Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Variant, SafeArray.....etc

Reply
Thread Tools

Variant, SafeArray.....etc

 
 
Simply_Red
Guest
Posts: n/a
 
      07-31-2007
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[i],&TEMPORARY);

}
SafeArrayUnaccessData(*tab1);
}



the vb side:
Dim tab1(1) As Variant
Call Remplir_table(tab1)

 
Reply With Quote
 
 
 
 
Simply_Red
Guest
Posts: n/a
 
      07-31-2007

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

 
Reply With Quote
 
 
 
 
redfloyd@gmail.com
Guest
Posts: n/a
 
      08-01-2007
On Jul 31, 2:06 pm, Simply_Red <(E-Mail Removed)> wrote:
> [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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments