Jump to content

Recommended Posts

Posted

I'm using VC6.

i have a DLL written in VC6 and used by VB6( and VBA Excel),

i use SafeArray as parameter, the array is created(declared), in VB

and C++ fill it.

now i need VC++ to get an array of array of different sizes, and VB

can't know the size of these arrays, so the arrays will be 'created'

in VC.

here the code that i use(and it crashes):

void __declspec(dllexport) CALLBACK Remplir_table(LPSAFEARRAY FAR

*tab1)

{

VARIANT HUGEP * CONTENU;

SAFEARRAYBOUND sabound[1]; // 1-D array

SAFEARRAY FAR* psa = NULL; // SAFEARRAY structure pointer

VARIANT TEMPORARY;

VariantInit(&TEMPORARY);

SafeArrayAccessData(*tab1, (void HUGEP**)&CONTENU);

sabound[0].lLbound = 0;

sabound[0].cElements = 2;

for (int i = 0; i<2; i++)

{

psa = SafeArrayCreate( VT_R4, 1, sabound );

float HUGEP* ResData;

SafeArrayAccessData(psa, (void HUGEP**)&ResData);

ResData[0] = 1.5; //just for test

ResData[1] = 0.75;//just for test

V_VT(&TEMPORARY ) = VT_ARRAY | VT_R4;

V_ARRAY(&TEMPORARY) = psa;

SafeArrayUnaccessData(psa);

VariantCopy(&CONTENU,&TEMPORARY);

}

SafeArrayUnaccessData(*tab1);

}

the vb side:

Dim tab1(1) As Variant

Call Remplir_table(tab1)


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...