Variant, SafeArray.....etc

S

Simply_Red

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)
 
S

Simply_Red

i did a mistake, the problem have nothing to do with Variant or
SafeArray, i just used an old code for testing how to create a table
of tables of different sizes, and i didn't see that in excel i had a
function, not a sub, so excel was waiting for a return value that C++
doesn't send, and the fact that it crashes at VariantCopy, confused
me, so i didn't think about other possible problems.

PS:i'm sorry for the confusion
 
R

redfloyd

[OT redacted]
PS:i'm sorry for the confusion

1. Congratulations on finding your mistake.
2. In the future, when you post, please consider this: Your question
was VC specific
(even more, it was VC6 specific). This is off-topic for this
newsgroup. You might
want to consider reading the FAQ (http://www.parashift.com/c++-faq-
lite) and in particular
section 5 (http://www.parashift.com/c++-faq-lite/how-to-post.html)
to see what is topical.

In general, ask yourself, "Would my question be essentially the same
in a different programming language?".
If you answer yes, then you probably should post in a newsgroup
dedicated to general programming.

Also ask yourself, "Does this question make sense for a different
platform (i.e. Linux/Mac instead of Windows)?".
If you answer yes, then it would probably be on topic here. If the
answer is no, then you are probably better off
posting to a newsgroup dedicated to your platform.

In both cases, a reasonable set of suggested newsgroups can be found
in FAQ 5.9.

Please feel free to bring your C++ specific questions here, we'll be
glad to help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top