Need just a little Visual Basic 6 help

dullard

Elite Member
May 21, 2001
25,776
4,305
126
I need to use a function in a 3rd party library nameed OOIDRV32.DLL. I have had no problems using that library in the past for most functions. But, there are a few functions that I have never been able to use since I couldn't figure out how. If anyone could help with this one example, I could easilly convert it to other functions.

A module that is supposed to be included in the project has this declaration:

Declare Function USB2000_IdentifyUSB2000 Lib "OOIDRV32.DLL" Alias "#402" (ByVal DevNum As Integer, SerNum As Byte) As Long

I am getting the proper DevNum returned from that function. I am getting the proper long result from the function (1 if it works and 0 if it doesn't). However, I am only getting the first part of SerNum. I need SerNum to be a string that looks like this "USB2E7477". All I get is SerNum = 85, and 85 is the ASCII code for "U".

The manual for that library says this:
Bool USB2000_ItentifyUSB2000(int devnum, char* serialnumber)
Parameter: Use
devnum: An index from 0 to 127
serialnumber: The returned serial number from the USB2000

Return value: This function returns TRUE if the device is a USB2000, FALSE otherwise.

! To use this function in Visual Basic or Visual Basic for Applications, convert the serial number from an array of ASCII values.

Clearly, a byte is just one ASCII character. Is it possible to get an array of ASCII values or is the library just fuc&ed?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Yes.

Dim b(50) As Byte
Dim iDevNum As Integer

USB2000_IdentifyUSB2000(iDevNum, b(0))

The b array should contain the full value. You need to make sure that b is large enough to handle the full size of the serial number.
 

dullard

Elite Member
May 21, 2001
25,776
4,305
126
Thanks a lot. It works now.

I tried this:
Dim b(50) As Byte
Dim iDevNum As Integer

USB2000_IdentifyUSB2000(iDevNum, b())
And I tried this
Dim b(50) As Byte
Dim iDevNum As Integer

USB2000_IdentifyUSB2000(iDevNum, b(1))
Both failed miserably. I never thought of using a zero. Well it is obvious I'm not a trained programmer.

Would the reverse be true then too? If I have a string, and I convert it to a byte array b(), do I just send b(0) to the functions?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
In terms of passing a string, if it's a LPSTR parameter on the C/C++ side, you can pass a VB string object directly (Text).

Otherwise, I think you should be able to pass the b(0) as a char* param, but I haven't tested it.

EDIT: There might be other methods as well. Here's a nice detailed article on the subject.