GregoryGr
asked on
Call C++ DLL from VB6 using user-defined data type
From VB, I'm calling a DLL created with C++. When I pass in a string ByVal, the DLL funstions fine. When I pass, ByRef, a user-defined data type including strings and longs, the DLL fails.
I've setup an identical structure in Vb to match what is defined in the DLL (including the use of fixed length strings).
I believe using fixed length VB strings will give me a null terminated string in the C-based DLL.
The problem is complicated because I cant find a way to get into debug mode to test the DLL by stepping into it from the VB call. As a result, I first created and debugged the code with a C-based EXE, then, moved the functions into the DLL.
I've setup an identical structure in Vb to match what is defined in the DLL (including the use of fixed length strings).
I believe using fixed length VB strings will give me a null terminated string in the C-based DLL.
The problem is complicated because I cant find a way to get into debug mode to test the DLL by stepping into it from the VB call. As a result, I first created and debugged the code with a C-based EXE, then, moved the functions into the DLL.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
listen...
ASKER
The UDT contains fixed length strings and integers into the DLL, not variable length strings. With the debugging info you gave me, I found the issue to be VB doesn't NULL terminate strings by default. I ran into problems trying the BSTR data type so I was planning just to NULL terminate the incoming VB strings.
Do you think that is a bad idea and I must use BSTR data types?
Do you think that is a bad idea and I must use BSTR data types?
ASKER
Using the fixed length strings instead of BSTR within the UDT seems to work for me once I NULL terminated the strings.
Your instructions to test the DLL from C++ helped a great deal!
Thanks!
Your instructions to test the DLL from C++ helped a great deal!
Thanks!
Glad I could help