int EXPORT_API usb_relay_device_open_with_serial_number(const char *serial_number,unsigned len); /*open device that serial number is serial number*/
/*return:This funcation return a valid handle to the device on success or NULL on failure*/
/**eg:usb_relay_device_open_with_serial_number("abcde",5")*/
在vb中嘗試以下幾種方式撰寫程式(設備序列號為“QAAMZ”)
1、直接傳遞字串
宣告:
private declare function usb_relay_device_open_with_serial_number Lib“xx路徑”(byval SerNum as string,byval lenth as long)as long
呼叫
dim return as long
return=usb_relay_device_open_with_serial_number(“QAAMZ”,5)
2、傳遞指標
宣告中 byval SerNum as long
其中sernum為序列號陣列首字符的指標地址
改一下宣告,C里面傳入指標的引數,VB里面用byref傳入,型別為any
private declare function usb_relay_device_open_with_serial_number Lib“xx路徑”(byref SerNum as any,byval lenth as long)as long
接下來,C的char 其實就是位元組陣列。把VB的string轉換成位元組陣列
dim a() as byte
a = strconv("1234abcd" ,vbfromunicode)
最后,把陣列的第一個元素傳遞進去,其實DLL那邊獲得的就是這個陣列在記憶體里的起始地址。也就是這個陣列的指標。
dim return as long
return=usb_relay_device_open_with_serial_number(a(0) ,ubound(a)+1)
vc的dll中需要把呼叫模式設為_stdcall才能讓vb呼叫
比如函式:
void add (int a ,int b)
就無法在VB中呼叫
要改為:
void add _stdcall (int a ,int b)
轉自:
https://bbs.csdn.net/topics/350190581
第2樓;
uj5u.com熱心網友回復:
我沒看過dll里面的代碼。不過之前有兩個函式已經運行成了,是不是應該是stdcall的?
uj5u.com熱心網友回復:
參考成的函式宣告是什么樣子的?
uj5u.com熱心網友回復:
vc的dll中需要把呼叫模式設為_stdcall才能讓vb呼叫
比如函式:
void add (int a ,int b)
就無法在VB中呼叫
要改為:
void add _stdcall (int a ,int b)
轉自:
https://bbs.csdn.net/topics/350190581
第2樓;
我沒看過dll里面的代碼。不過之前有兩個函式已經運行成了,是不是應該是stdcall的?
參考成的函式宣告是什么樣子的?
參考成了兩個函式。
1,初始化函式
在dll頭檔案中宣告為:
int EXPORT_API usb_relay_init(void)
/*init the usb relay library
return 0 on success and-1 on failure*/
在vb中宣告為
private declare function usb_relay_init lib."路徑"()as long
2,第二個函式是掃描設備資訊的,在另一個帖子里大神您回復過我,按照您的方法解決了。