Click here to Skip to main content
15,120,478 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
*pEventCode is my safearray... dEventCd is the 'double' value...I want to insert the dEventCd values to my *pEventCode safearray one by one when (bPriv) is true... Please help. I get E_INVALIDARG error.


C++
lResult=SafeArrayUnlock(*pEventCode);
HRESULT hr = SafeArrayDestroyData(*pEventCode);

for(INT_PTR count(0); count < nEventCnt; ++count)
{
    mapEventCds.GetNextAssoc(pos, dEventCd, bPriv);

    if (bPriv)
    {
        hr = SafeArrayPutElement(*pEventCode, &iEventCdIdx, &dEventCd);
        iEventCdIdx++;
    }
}
Posted
Updated 7-Nov-13 8:04am
v2

Something like this merged with your code? You have to work with the limits of the safearray
C++
//Check dimensions of the array:
LONG lLBound, lUBound;
long element; //for array indexing
HRESULT hr;
	
// Get the lower bound of the array
hr = SafeArrayGetLBound(*pEventCode, 1, &lLBound);
if (FAILED(hr))
{
   //Handle Error
}

// Get the upper bound of the array
hr = SafeArrayGetUBound(*pEventCode, 1, &lUBound);
if (FAILED(hr))
{
   //Handle Error
}


// put your array elements into the SAFEARRAY
for( element = lLBound; element <= lUBound; element++ )
{
    hr = SafeArrayPutElement(*pEventCode, &element, &dEventCode);
    if(FAILED(hr))
    {
         // Handle Error
    }	
}
   
Comments
Guru16 7-Nov-13 13:58pm
   
Yes.. But I'm unable to add the event code using SafeArrayPutElement.. It needs a variant.. My type is double. Is there anyway I could add a double?
Looking at http://msdn.microsoft.com/en-us/library/windows/desktop/ms221170(v=vs.85).aspx[^] there doesn't seem to be a double type for safearray - which I gather is your problem. Though there is a user defined type but I haven't looked at how to use it.
   
Comments
CPallini 7-Nov-13 16:00pm
   
There is. It is the VT_R8.

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