函式包成DLL以供DELPHI呼叫 |
尚未結案
|
david753
一般會員 發表:19 回覆:22 積分:8 註冊:2004-07-20 發送簡訊給我 |
我想將以下函式包成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
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
您好:
下面有建立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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |