Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am trying to pass a VARIANT type to a COM method. I am basically using this to read an array of integer from the COM method. Unfortunately, I am stuck like hell :(

Before sending the variable, COM is initialized to an array of INT :
C++
VARIANT *variantVariable = new VARIANT;
 ::VariantInit(variantVariable);
 variantVariable->vt     = VT_ARRAY | VT_INT;
 SAFEARRAYBOUND bounds[1];
 bounds[0].cElements = 100; // array size
 bounds[0].lLbound = 0;
 SAFEARRAY *pSafeArray = SafeArrayCreate(VT_INT,1,bounds);
 // pointer to access the data
 int *pData;
 SafeArrayAccessData(pSafeArray,reinterpret_cast<void **>(&pData));
for(Uint offset = 0; 100 > offset; ++offset)
{
   pData[offset] = -1;
}

SafeArrayUnaccessData(pSafeArray);
variantVariable->parray = pSafeArray;

I am calling the COM :
VB
interfaceVariable->COMFUNCTION(
    variantVariable

);

On tracing the COM function, I see that variantVariable is empty. How-ever, just before calling it, it would be an array of int. I am not sure what is going wrong. Please help.
Posted
Updated 17-Nov-10 19:36pm
v2

1 solution

Most of the time, you should use _variant_t instead of VARIANT. It's much cleaner. You also might use SafeArrayGetElement. That should work...
 
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