trouble with a safe array of variants
-
I have a safe array of variants I have been working on getting working in c++. I need to pass a safearray of variants with this flags in fFeatures set by default: FADF_FIXEDSIZE, FADF_STATIC, FADF_HAVEVARTYPE and FADF_VARIANT. Trouble is I have an ATL com dll project (mouse emulator) that wraps another ATL com dll called softhidreceiver. When I called softhidreceiver I need to pass a safe array of variants but Iam having trouble doing so. Here is an msdn forum post that never got solved but grew so large I just started a new post. http://social.msdn.microsoft.com/Forums/vstudio/en-US/a54fdef1-6479-41dc-8662-4c615d1dab9e/invalid-safearray-of-variants#be1b5734-9a80-439e-a3dd-32f48d24ab84[^] Anyone knowledge with safearray of variants? I have not choice in the matter unless someone has a better idea of passing values to queueinputreport? Heres my current code though so far:
STDMETHODIMP CMMEmulator::sendinputreport(unsigned char inputreport[5], int length)
{\_TCHAR szBuffer\[100\]; \_stprintf\_s(szBuffer, \_T("%i"), inputreport\[1\]); MessageBox(NULL,L"value of second byte input report",szBuffer,NULL); BYTE bSampe\[5\] = {0x00,inputreport\[1\],inputreport\[2\],0x00,0x00}; HRESULT hr = S\_OK; SAFEARRAY \*psaData = NULL; VARIANT HUGEP\* pVarArrayData = NULL; SAFEARRAYBOUND bound; bound.cElements = 5; bound.lLbound = 0;
psaData = SafeArrayCreateVector(VT_VARIANT,0,5);
hr = SafeArrayAccessData(psaData, (void HUGEP**)&pVarArrayData);
if (SUCCEEDED(hr))
{
for (long i = 0; i < 5; i++)
{
VariantInit(&pVarArrayData[i]);
pVarArrayData[i].vt = VT_UI1;
pVarArrayData[i].bVal = static_cast<byte>(bSampe[i]);
// SafeArrayPutElement(psaData,&i,&pVarArrayData);
}
hr = SafeArrayUnaccessData(psaData);
if (SUCCEEDED(hr))
{
piSoftHidDevice1[devindex]->QueueInputReport(psaData,10);
piSoftHidDevice1[devindex]->StartProcessing();
}
}
SafeArrayDestroy(psaData);//piSoftHidDevice1\[devindex\]->StopProcessing(); return S\_OK; //Exit:
}