Author Topic: Emulation/Simulation of multiple mouse devices?  (Read 9909 times)

jeffcarl1

  • Member
  • ***
  • Posts: 2
Emulation/Simulation of multiple mouse devices?
« on: May 08, 2014, 11:15:52 am »
I have some c++ code I am having trouble with that uses Device simulation framework from Microsoft's WDK 7.1. I am trying to create multiple mouse devices but I am having problems with the report being sent at all if the fFeatures of the array is not 0x892. I have tried to send an input report but I think I have declared my safe array wrong because it fails to work:

Code: [Select]
  STDMETHODIMP CMMEmulator::sendinputreport(BYTE inputreport[5])
        {
//SAFEARRAY *inputreport

 // Create as an Array of Variants because that is what the DSF
// Interface->put_DeviceSpecificDescriptor is expecting an array of Variants

   FADF_STATIC+FADF_FIXEDSIZE+FADF_VARIANT+FADF_HAVEVARTYPE;
   if(  test->fFeatures == 0x892)
   {
    MessageBox(NULL,L"has correct safearray type",L"correct data format",NULL);

    }
    // test->fFeatures = 2194;

Here I assign a byte to each part of the safe array:
// Step through the SAFEARRAY and populate each variant with a Byte value
    LONG length = 4;
    //SafeArrayLock(psaValues);
     CComVariant v;
    for(int i = 0; i < 5; i++)
     {
        //j[i] = i;
     MessageBox(NULL,L"inputreport assigned to variable",NULL,NULL);
          v.Clear();
       v.vt = VT_UI1;
       v.uiVal = inputreport[i];
       v.Detach(&pDescriptorData[i]);
        c.Add (v, TRUE);
     }

This section of code is for sending an input report to a device I select using devindex (integer).
MessageBox(NULL,L"data is successfully assigned to safearray",L"correct data format",NULL);
//piSoftHidDevice1[devindex]->
piSoftHidDevice1[devindex]->QueueInputReport(c,8);

piSoftHidDevice1[devindex]->StartProcessing();
piSoftHidDevice1[devindex]->StopProcessing();

return S_OK;
//Exit:
   //SafeArrayUnaccessData(test);
  //return 0;
  }

Here is the c++ code for queue input report I am passing data to:
Code: [Select]
STDMETHODIMP CHIDDevice::QueueInputReport( SAFEARRAY* psaInputReport, UINT     timeoutDuration )
/*++
Routine Description:
Queues additional input reports

Arguments:
 IdleTimeout - used to set the value of the log level

Return value:
  S_OK
--*/
{
VARIANT *  pArrayData  = NULL;
UINT               cbData      = 5;
LONG                lLBound     = 0;
LONG                lUBound     = 0;
HRESULT             hr          = S_OK;
HID_INPUT_REPORT    inputReport;
BOOLEAN             result      = TRUE;

// Initialize Structure
inputReport.timeout = timeoutDuration;
inputReport.cbInputReport = 0;
inputReport.pbInputReport = NULL;
    MessageBox(NULL,L"report initialized",L"initial report",NULL);
// Get SAFEARRAY size
IfFailHrGo(SafeArrayGetLBound(psaInputReport, 1, &lLBound));
IfFailHrGo(SafeArrayGetUBound(psaInputReport, 1, &lUBound));
IfFalseHrGo(lUBound > lLBound, E_UNEXPECTED);
cbData = lUBound - lLBound + 1;
//psaInputReport->fFeatures = 0x892;
//psaInputReport->fFeatures = 0x892;
inputReport.pbInputReport = (BYTE*)CoTaskMemAlloc( cbData * sizeof(BYTE) );
 _TCHAR szBuffer3[100];
_stprintf_s(szBuffer3, _T("%i"), &psaInputReport->fFeatures);
MessageBox(NULL,L"array content features",szBuffer3,NULL);
// If the memory Allocation fails, then fail and exit
if( inputReport.pbInputReport == NULL )
{
    hr = E_UNEXPECTED;
    goto Exit;
}
//void HUGEP** cast orginally
IfFailHrGo( SafeArrayAccessData( psaInputReport,
                                 reinterpret_cast<void HUGEP**>(&pArrayData) ) );

// Step through the SAFEARRAY and populating only BYTE input report
// and bail out if the type is not correct
for( LONG i = 0; i <= lUBound; ++i )
{
    if (pArrayData[i].vt == VT_UI1)
    {

        inputReport.pbInputReport[i] = pArrayData[i].bVal;

    }
    else
    {
        hr = E_FAIL;
        goto Exit;
    }
}
  SafeArrayUnaccessData(psaInputReport);
inputReport.cbInputReport = cbData;
    //MessageBox(NULL,L"report being sent next",L"sent report",NULL);
// Add the report to the input queue (does a shallow copy so no need to free the   array data)
result = m_InputReportQueue.insert( inputReport );
 if (result == FALSE)
{
    MessageBox(NULL,L"failed to queue the input",NULL,NULL);
    hr = E_FAIL;
}
return hr;
Exit:
SafeArrayUnaccessData(psaInputReport);
if( FAILED(hr) )
{
    CoTaskMemFree(inputReport.pbInputReport);
}
return hr;
}

c++

If anyone has any hints as to what I am doing wrong can you please share them?
« Last Edit: May 08, 2014, 11:25:38 am by jeffcarl1 »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Emulation/Simulation of multiple mouse devices?
« Reply #1 on: May 08, 2014, 10:51:04 pm »
I don't have experience with the simulation framework so can probably be of limited help, but from:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms221482%28v=vs.85%29.aspx

0x892 means

FADF_VARIANT
FADF_HAVEVARTYP
FADF_FIXEDSIZE
FADF_STATIC

Why are you changing it?