Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Invalid safearray of variants?

$
0
0
STDMETHODIMP CMMEmulator::sendinputreport(BYTE inputreport[5], int length)
{
	// TODO: Add your implementation code here
		 _TCHAR szBuffer[100];
    _stprintf_s(szBuffer, _T("%i"), inputreport[1]);
	MessageBox(NULL,L"value of second byte input report",szBuffer,NULL);
	SAFEARRAY *test = new SAFEARRAY;
	  VARIANT HUGEP* pDescriptorData  = NULL;
	// Create a boundary struct to pass in when we create the SafeArray
    SAFEARRAYBOUND rgsabound[1];
    ZeroMemory(rgsabound, sizeof(rgsabound));
    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = 4;
    // Create as an Array of Variants becuase that is what the DSF 
    // Interface->put_DeviceSpecificDescriptor is expecting an array of Variants
    test = SafeArrayCreate(VT_VARIANT, 1, rgsabound );
      test->fFeatures = 2194;
    if( test == NULL )
    {
        // if the create failed, then goto to exit
        hr = E_UNEXPECTED;
        goto Exit;
    }
    SafeArrayAccessData(test, (void HUGEP**)&pDescriptorData);

    // Step through the SAFEARRAY and populate each variant with a Byte value
    //INT descSize2 = sizeof(inputreport);
    for( INT i = 0; i < 4; ++i )
    {
       pDescriptorData[i].vt = VT_UI1;
        pDescriptorData[i].bVal = inputreport[i];
    }
	 _TCHAR szBuffer2[100];
    _stprintf_s(szBuffer2, _T("%i"), test->fFeatures);
	MessageBox(NULL,L"safe array type",szBuffer2,NULL);
	piSoftHidDevice1[devindex]->QueueInputReport(test,10);
	piSoftHidDevice1[devindex]->StartProcessing();
	piSoftHidDevice1[devindex]->StopProcessing();
	SafeArrayUnaccessData(test);
	return S_OK;
	Exit:
SafeArrayUnaccessData(test);
   return hr;
}

as you can see above I was trying to assign the byte values to the variants inside a safearray and send this safe array to another sub/function called queueinputreport that has its safearray declared like this: queueinputreport( SAFEARRAY* psaInputReport,UINT timeoutduration). In the idl for the c++ project the safe array is defined as queueinputreport(SAFEARRAY(VARIANT), UINT timeoutduration). How can I pass a safearray correctly to queueinputreport? I have a messagebox inside queueinputreport that does tell me its values but it reports that the values are correctly passed so it confuses why it does not use that data and work. I believe this to be incorrectly formatted data being passed to the other safearray but have no clue where Iam going wrong? Can someone step in and help me out?

P.S. Iam not good with safearrays yet so if I have done something wrong feel free to point it out. I am trying to pass a safearray to softhidreceiver.dll included with Microsoft's device simulation framework that's where I get queueinputreport.


Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr




Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>