DLL written in c + + header file, function are defined as follows
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 ") */
Try the following several ways to write program in vb (equipment serial number for "QAAMZ") 1, direct transmission string Disclaimer: Private declare function usb_relay_device_open_with_serial_number Lib "xx path" (byval SerNum as string, byval lenth as long) as long The Dim return as long Return=usb_relay_device_open_with_serial_number (" QAAMZ ", 5) 2, passing a pointer Statement, byval SerNum as long Including sernum for serial number first character array pointer address
But both "DLL calling convention error",
Consult ~
Ps: this problem lead to ask: https://bbs.csdn.net/topics/392563831 Has solved the question using DLL for equipment serial number,
CodePudding user response:
Change statement into a pointer parameter C, VB inside with byref incoming, type of any Private declare function usb_relay_device_open_with_serial_number Lib "xx path" (byref SerNum as any, byval lenth as long) as long
Next, the char C is actually an array of bytes, the VB string into an array of bytes
Dim (a) as byte A=strconv (" abcd "1234, vbfromunicode)
Finally, pass the first element of the array, DLL there is obtained by the array in the starting address of the memory, namely the array pointer, Dim return as long Return=usb_relay_device_open_with_serial_number (a (0), ubound (a) + 1)