Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I send a structure in VB to a DLL

I have a function in a DLL written in LW/CVI that expects a structure an input parameter. How do I access this function using VB 6.0? I've tried using UDT in vb but something's missing.

Has anyone done this before?
0 Kudos
Message 1 of 4
(7,550 Views)
It has been done before and it can be easy or difficult depending on the complexity of the struct. Assuming that the struct is relatively simple (ie. just values...no embedded arrays or strings) you can define an equivalend Type in VB and then set up the declaration to call it ByVal.

There's lots of SDK examples that do this. If you're having trouble with it you might want to load up the "API Viewer" add-in and VB and browse the SDK functions. You should be able to find some that use this method.

If you're struct is more complex, you may have to go at a lower level to access it in VB. For example, if you pass an array as a member of a struct, what you'll end up with in VB is merely the pointer to the array. Then you'll have to use some mem copying func
tions (RtlMoveMemory is the typical one) to copy from the pointer into a VB allocated variable. Not impossible, but not as easy as just declaring the variable like in the simple example above.

Hope that helps!
0 Kudos
Message 2 of 4
(7,546 Views)

Hello Jason,

I have no experience in VB and I need some more help if possible.

I have in VB a structure with three members :

Type MYSTRUCT

nInt as Integer

sFilename as String * 256

sProjectDir as String * 256

End Type

What do I have to do in VB and in my C DLL in order to receive in the DLL the string from the struct ?
 
Now I'm using in C a void* parameter to my function and a cast to the struct but I have problems with the strings (they arrive correct in the DLL but copying them to other strings using strcpy failed)
 
Thanks in advance
0 Kudos
Message 3 of 4
(7,409 Views)
The function parameter - void* - must be declared as "ByRef x As Any" or "ByRef x As MYSTRUCT"in VB if you want to pass the reference to struct.  Did you declare the function properly? 
0 Kudos
Message 4 of 4
(7,366 Views)