Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to transfer into a C ++ structure via a DLL , the content of a VB structure (UTD).

My VB code is as follows :

Private Declare Function Cpp_TEST1 Lib "C:\Users\\TEST1.dll" (ByRef iStruct As myStruct) As Double

Type myStruct
    n As Long
    data() As Long
    rData As Boolean
End Type

iStruct.n = 10
iStruct.rData= True
ReDim To 12) = 1 = 2 = 3 = 4 = 5 = 6 = 7 = 8 = 9 = 10 = 11 = 12

Test1 = Cpp_TEST1(iStruct)

In C++ side i do :

struct myStruct{    
    long n;
    long  *data;

XLSTATLINK_API double __stdcall Cpp_TEST1(myStruct *iStruct)
    return 1;

When i spy iStruct, I get good values ​​for data n et rData.
For the data array, the data obtained are random :

[0] 8388609 long
[1] 4 long
[2] 0 long
[3] 234122136 long
[4] 12 long
[5] 1 long
[6] 634790639 long
[7] -2013222912 long
[8] 352064696 long
[9] 352064792 long
[10] 1771379816 long
[11] 537 long

My problem is that I can't recover the data array contained in the VBA structure from the C++ DLL !!

Thanks you in advance ;-)
KarstenK 13-May-15 12:51pm    
It is obvious that the rData part doesnt work. Use some fixed values instead of the Redim() ones.
[no name] 13-May-15 13:32pm    
Notice you used VARIANT_BOOL for the boolean member.

Your long *data declaration should probably be a VARIANT.

Also, the parameter to Cpp_TEST1 is likely also a VARIANT.
Maciej Los 13-May-15 15:08pm    
Do you use Option Base 1?

In VB the arrays are defined as safe arrays, you have to access it as such in C.
struct myStruct{    
    long n;
    SAFEARRAY *data;
Share this answer
Depending on Option Base[^] statement, lower bound of arrays start from 0 (zero) or 1(one). If you do not use this statement, array must starts from 0. I'd suggest to read this article Arrays in VB[^] which might help you to understand how to declare and initilize arrays.

ReDim Preserve
For i = 0 to 11 = i+1
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900