線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1755
推到 Plurk!
推到 Facebook!

函式包成DLL以供DELPHI呼叫

尚未結案
david753
一般會員


發表:19
回覆:22
積分:8
註冊:2004-07-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-21 20:53:48 IP:59.104.xxx.xxx 未訂閱
我想將以下函式包成DLL以供DELPHI呼叫 該如何做? 可行嗎?    /*===========================================================================*/ /* Function: Digital Modulation Lists                                        */ /* Purpose:  This function manipulates the digital modulation data lists.    */ /*           The list contains data bits. The lists can be creaded only if   */ /*           the instrument is equipped with Data Generator option SMIQ-B11. */ /*===========================================================================*/ ViStatus _VI_FUNC rssmiq_digModLists (ViSession instrumentHandle, ViInt32 action,                     ViString name, ViBoolean type, ViString data,                     ViInt32 numOfBytes, ViBoolean controlList) {     ViStatus    rssmiq_status = VI_SUCCESS;     ViChar      *buffer = VI_NULL;     ViUInt32    *tmpData = VI_NULL;     ViUInt32    tmpVal1, tmpVal2;     ViUInt32    i;     FILE        *fh = VI_NULL;     ViChar      listName[256];     ViChar      bb_string[4];     ViUInt32    size;     ViString    p2data,                 p2name;     ViChar      str[10];     ViUInt16    interface_type = VI_INTF_GPIB;     rssmiq_instrRange   instrPtr;     ViUInt16    oldEndChar = VI_ASRL_END_NONE;     ViBoolean   oldTermChar = VI_FALSE;        CHECKERR (viGetAttribute (instrumentHandle, VI_ATTR_USER_DATA, &instrPtr));        strcpy (bb_string, instrPtr->instrType ? "BB:" : "");        /*- Check input parameter ranges ----------------------------------------*/     if (rssmiq_invalidViInt32Range (action, 0, 3))         return VI_ERROR_PARAMETER2;     if (rssmiq_invalidViBooleanRange (type))         return VI_ERROR_PARAMETER4;     if (rssmiq_invalidViInt32Range (numOfBytes, 0, 250000))         return VI_ERROR_PARAMETER6;     if (rssmiq_invalidViBooleanRange (controlList))         return VI_ERROR_PARAMETER7;        strcpy (listName, name);        switch (action) {         case 0:             /* Select list*/             if (type) {                 /* Selecting a control list*/                 if (instrPtr->instrType)                 {                     CHECKERR (viPrintf (instrumentHandle, "\n:SOUR:BB:DM:CLIST:SEL \"%s\"\n",                                      name));                 }                 else                 {                     CHECKERR (viPrintf (instrumentHandle, "\n:SOUR:DM:CLIST:SEL \"%s\";:SOUR:DM:CLIST:CONT %s\n",                                      name, offOnArr[controlList]));                 }             } else {                 CHECKERR (viPrintf (instrumentHandle, "\n:SOUR:%sDM:DLIST:SEL \"%s\"\n", bb_string, name));             }         break;         case 2:             /* Create list from file*/                /* Reading the file ===============================================*/             if ((fh = fopen (name, "rb")) == VI_NULL) {               rssmiq_status = VI_ERROR_INSTR_FILE_OPEN;               goto Error;             }          if (fseek (fh, 0, SEEK_END) != 0) {         rssmiq_status = VI_ERROR_INSTR_FILE_OPEN;         goto Error;       }          if ((int)(size = ftell (fh)) < 0) {         rssmiq_status = VI_ERROR_INSTR_FILE_OPEN;         goto Error;       }          if (fseek (fh, 0, SEEK_SET) != 0) {         rssmiq_status = VI_ERROR_INSTR_FILE_OPEN;         goto Error;       }                /* Read the file content into a temporary buffer*/             /* Allocate temporary buffer*/             if ((tmpData = malloc (size+1)) == 0) {         rssmiq_status = VI_ERROR_ALLOC;         goto Error;             }          if (fread (tmpData, sizeof (ViUInt32), size/sizeof (ViUInt32), fh) != size) {         rssmiq_status = VI_ERROR_INSTR_FILE_OPEN;         goto Error;       }          fclose (fh);       fh = VI_NULL;                numOfBytes = size;                /* List name to be created in the instrument is same as the filename*/             /* Extension is cut off, max length is 7 chars*/       p2name = strrchr (name, '\\');       strcpy (listName, p2name ? 1+p2name : name);       if (strchr (listName, '.')) (*strchr (listName, '.')) = 0;       if (strlen (listName) > 7) listName[7] = 0;         case 1:             /* Create list from buffer*/             /* Because the size of the command string in this case can be very long*/             /* and depends on the data array size, the buffer to hold the command*/             /* string is allocated dynamically. Its length is 85 chars for the commands*/             /* plus number of array elements*/             if ((buffer = malloc (81+numOfBytes)) == 0) return VI_ERROR_ALLOC;                sprintf (str, "%ld", numOfBytes);                if (type) {                 /* Creating a control list*/                 p2data = buffer + sprintf (buffer, "\n:SOUR:%sDM:CLIST:SEL \"%s\";"                     ":FORM:DATA PACK;BORD NORM;:SOUR:%sDM:CLIST:DATA #%ld%ld",                     bb_string, listName, bb_string, strlen (str), numOfBytes);             } else {                 /* Creating a data list*/                 p2data = buffer + sprintf (buffer, "\n:SOUR:%sDM:DLIST:SEL \"%s\";"                     ":FORM:DATA PACK;BORD NORM;:SOUR:%sDM:DLIST:DATA #%ld%ld",                     bb_string, listName, bb_string, strlen (str), numOfBytes);             }                /* Allocate temporary buffer. It will be used to*/             /* hold bit data. This prevents this input data buffer*/             /* from being changed when doing bit shifts before sending it*/             /* to the instrument.*/             if (tmpData == VI_NULL) {               if ((tmpData = malloc (numOfBytes)) == 0)                   return VI_ERROR_ALLOC;               memcpy (tmpData, data, numOfBytes);           }                if (type) {                 /* Control List: Need to reverse the symbol - data order*/                 for (i=0; i>= 6; tmpVal1 &= 0x03FFFFFF; tmpVal1--; tmpVal2 &= 0x0000003F; tmpVal2 <<= 26; tmpVal1 |= tmpVal2; tmpData[i] = rssmiq_swapViUInt32 (tmpVal1); } } memcpy (p2data, tmpData, numOfBytes); p2data = numOfBytes; CHECKERR(viGetAttribute (instrumentHandle, VI_ATTR_INTF_TYPE, &interface_type)); if (interface_type == VI_INTF_ASRL) { CHECKERR(viSetAttribute (instrumentHandle, VI_ATTR_ASRL_END_IN, oldEndChar)); CHECKERR(viSetAttribute (instrumentHandle, VI_ATTR_TERMCHAR_EN, oldTermChar)); } else CHECKERR(viPrintf(instrumentHandle,"\n:SYST:COMM:GPIB:LTER EOI\n")); if ((rssmiq_status = viWrite (instrumentHandle, buffer, p2data - buffer, 0)) < 0) { goto Error; } if (interface_type == VI_INTF_ASRL) { CHECKERR(viSetAttribute (instrumentHandle, VI_ATTR_ASRL_END_IN, oldEndChar)); CHECKERR(viSetAttribute (instrumentHandle, VI_ATTR_TERMCHAR_EN, oldTermChar)); } else CHECKERR(viPrintf(instrumentHandle,"\n:SYST:COMM:GPIB:LTER STAN\n")); free (tmpData); tmpData = VI_NULL; free (buffer); buffer = VI_NULL; break; case 3: /* Delete list*/ if (type) { /* Selecting a control list*/ CHECKERR (viPrintf (instrumentHandle, "\n:SOUR:%sDM:CLIST:DEL \"%s\"\n", bb_string, name)); } else { CHECKERR (viPrintf (instrumentHandle, "\n:SOUR:%sDM:DLIST:DEL \"%s\"\n", bb_string, name)); } break; } Error: if (fh) fclose (fh); if (tmpData) free (tmpData); if (buffer) free (buffer); return rssmiq_status; }
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-21 21:45:27 IP:203.204.xxx.xxx 未訂閱
您好: 下面有建立dll的教學 http://delphi.ktop.com.tw/topic.php?topic_id=18760 http://delphi.ktop.com.tw/topic.php?topic_id=48346 呼叫他 procedure TForm1.Button1Click(Sender: TObject); var LibH:THandle; {宣告一個讓dll使用的Handle} begin LibH:=LoadLibrary('makedll.dll'); {載入dll檔案} if Libh=0 then ShowMessage('error'); {如果載入失敗時會傳回0} test; {使用Dll中的函數} FreeLibrary(LibH); {釋放dll的Handle} end;
david753
一般會員


發表:19
回覆:22
積分:8
註冊:2004-07-20

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-29 06:27:56 IP:59.104.xxx.xxx 未訂閱
是否要在vcc內建立dll檔?
系統時間:2024-05-05 4:02:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!