Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1.  //initialize wia
  2.     HRESULT h = CoInitialize(NULL);
  3.     IWiaDevMgr* pWiaDevMgr = NULL;
  4.     //create wia device manager
  5.     HRESULT hr = CreateWiaDeviceManager(&pWiaDevMgr);
  6.     //show connected devices and get deviceId
  7.     BSTR bstrDeviceID = SysAllocString(L"");
  8.     HRESULT hr2 = EnumerateWiaDevices(pWiaDevMgr, &bstrDeviceID);
  9.     //create device with device id
  10.     IWiaItem* ppWiaDevice;
  11.     HRESULT hr3 = CreateWiaDevice(pWiaDevMgr, bstrDeviceID, &ppWiaDevice);
  12.  
  13.     //case IWiaItem to IWiaItemExtras
  14.     IWiaItemExtras* ppWiaExtra = (IWiaItemExtras*)ppWiaDevice;
  15.  
  16.     //try to send data
  17.     DWORD dwEscapeCode = 256;
  18.     BYTE* lpInData = new unsigned char[37]{ 0x01, 0x92, 0x00 , 0x00 , 0x00, 0x00, 0x00 , 0x00 , 0x00 , 0x01 ,
  19.         0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
  20.         0x00, 0x00, 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
  21.         0x00 ,   0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 };
  22.     DWORD cbInDataSize = sizeof(lpInData);
  23.  
  24.     BYTE* pOutData = new unsigned char[4]{ 0x00 , 0x00,0x00,0x00 };
  25.     DWORD dwOutDataSize = sizeof(pOutData);
  26.  
  27.     DWORD pdwActualDataSize = NULL;
  28.  
  29.     BSTR bstre = SysAllocString(L"");
  30.     //just to test if ppWiaExtra is working
  31.     HRESULT hr6 = ppWiaExtra->GetExtendedErrorInfo(&bstre); //works
  32.     //try to send data with Escape Method
  33.     //see https://docs.microsoft.com/en-us/windows/win32/api/wia_xp/nf-wia_xp-iwiaitemextras-escape
  34.     HRESULT hr5 = ppWiaExtra->Escape(dwEscapeCode, lpInData, cbInDataSize, pOutData, dwOutDataSize, &pdwActualDataSize); //error below
  35.  
  36.     //Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
  37.     //This is usually a result of calling a function declared with one calling
  38.     //convention with a function pointer declared with a different calling convention.
  39.  
  40.     //Function in HeaderFile:
  41.  
  42.     /*
  43.     virtual HRESULT STDMETHODCALLTYPE Escape(
  44.      [in]  DWORD dwEscapeCode,
  45.      [size_is][in]  __RPC__in_ecount_full(cbInDataSize) BYTE * lpInData,
  46.      [in]  DWORD cbInDataSize,
  47.      [length_is][size_is][out]  __RPC__out_ecount_part(dwOutDataSize, pdwActualDataSize ? *pdwActualDataSize : dwOutDataSize) BYTE * pOutData,
  48.      [in]  DWORD dwOutDataSize,
  49.      [out]  __RPC__out DWORD * pdwActualDataSize) = 0;
  50.     */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement