简体   繁体   English

WIA 运行时检查失败 #0 C++(Windows 图像采集)

[英]WIA Run-Time Check Failure #0 C++ (Windows Image Acquisition)

i try to use WIA to send data to a camera.我尝试使用 WIA 将数据发送到相机。 I need to develop this in C++ so i used the official "tutorial" on https://docs.microsoft.com/en-us/windows/win32/wia/-wia-wia-tutorial I know another project that works with C# and i want to do the same on C++ (C# Project on: https://github.com/pixeltris/SonyAlphaUSB )我需要用 C++ 开发它,所以我使用了https://docs.microsoft.com/en-us/windows/win32/wia/-wia-wia-tutorial上的官方“教程”我知道另一个使用 C# 的项目我想在 C++ 上做同样的事情(C# 项目: https : //github.com/pixeltris/SonyAlphaUSB

When i want to use Escape Method https://docs.microsoft.com/en-us/windows/win32/api/wia_xp/nf-wia_xp-iwiaitemextras-escape i get the当我想使用Escape方法https://docs.microsoft.com/en-us/windows/win32/api/wia_xp/nf-wia_xp-iwiaitemextras-escape我得到

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
This is usually a result of calling a function declared with one calling
convention with a function pointer declared with a different calling convention.

Error and i hope you can help me to resolve this.错误,我希望你能帮助我解决这个问题。 My code looks like this:我的代码如下所示:

 //initialize wia
HRESULT h = CoInitialize(NULL);
IWiaDevMgr* pWiaDevMgr = NULL;
//create wia device manager
HRESULT hr = CreateWiaDeviceManager(&pWiaDevMgr);
//show connected devices and get deviceId
BSTR bstrDeviceID = SysAllocString(L"");
HRESULT hr2 = EnumerateWiaDevices(pWiaDevMgr, &bstrDeviceID);
//create device with device id
IWiaItem* ppWiaDevice;
HRESULT hr3 = CreateWiaDevice(pWiaDevMgr, bstrDeviceID, &ppWiaDevice);

//case IWiaItem to IWiaItemExtras
IWiaItemExtras* ppWiaExtra = (IWiaItemExtras*)ppWiaDevice;

//try to send data
DWORD dwEscapeCode = 256;
BYTE* lpInData = new unsigned char[37]{ 0x01, 0x92, 0x00 , 0x00 , 0x00, 0x00, 0x00 , 0x00 , 0x00 , 0x01 ,
    0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
    0x00, 0x00, 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
    0x00 ,   0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 }; 
DWORD cbInDataSize = sizeof(lpInData);

BYTE* pOutData = new unsigned char[4]{ 0x00 , 0x00,0x00, 0x00};
DWORD dwOutDataSize = sizeof(pOutData);

DWORD pdwActualDataSize = NULL;

BSTR bstre = SysAllocString(L"");
//just to test if ppWiaExtra is working
HRESULT hr6 = ppWiaExtra->GetExtendedErrorInfo(&bstre); //works
//try to send data with Escape Method
//see https://docs.microsoft.com/en-us/windows/win32/api/wia_xp/nf-wia_xp-iwiaitemextras-escape
HRESULT hr5 = ppWiaExtra->Escape(dwEscapeCode, lpInData, cbInDataSize, pOutData, dwOutDataSize, &pdwActualDataSize); //Run-Time Check Failure #0

The Methods i use are the same as in the example code on https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/multimedia/wia/wiassamp/wiassamp.cpp我使用的方法与https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/multimedia/wia/wiassamp/wiassamp.cpp上的示例代码中的方法相同

The Escape Method is:逃生方法是:

virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Escape( 
        /* [in] */ DWORD dwEscapeCode,
        /* [size_is][in] */ __RPC__in_ecount_full(cbInDataSize) BYTE *lpInData,
        /* [in] */ DWORD cbInDataSize,
        /* [length_is][size_is][out] */ __RPC__out_ecount_part(dwOutDataSize, pdwActualDataSize ? *pdwActualDataSize : dwOutDataSize) BYTE *pOutData,
        /* [in] */ DWORD dwOutDataSize,
        /* [out] */ __RPC__out DWORD *pdwActualDataSize) = 0;

So how can i find the actual problem why the error is shown and how can i resolve it?那么我怎样才能找到显示错误的实际问题,我该如何解决呢?

(I use WIA1 because WIA2 doesn't find the device) (我使用 WIA1 因为 WIA2 找不到设备)

STDMETHODCALLTYPE 

is defined in winnt.h as following:在 winnt.h 中定义如下:

#if defined(_WIN32) || defined(_MPPC_)

// Win32 doesn't support __export

#ifdef _68K_
#define STDMETHODCALLTYPE       __cdecl
#else
#define STDMETHODCALLTYPE       __stdcall
#endif
#define STDMETHODVCALLTYPE      __cdecl

#define STDAPICALLTYPE          __stdcall
#define STDAPIVCALLTYPE         __cdecl

#else

#define STDMETHODCALLTYPE       __export __stdcall
#define STDMETHODVCALLTYPE      __export __cdecl

#define STDAPICALLTYPE          __export __stdcall
#define STDAPIVCALLTYPE         __export __cdecl

#endif

EDIT 1:编辑 1:

GetExtendedErrorInfo

now returns Not Implemented Error (but that's currently not so important for me)现在返回未实现的错误(但这对我来说目前并不重要)

The bigger Problem is that更大的问题是

ppWiaExtra->Escape

returns E_FAIL and that one is unspecified, i think it's some pointer problem again or an issue with my usage of sizeof返回E_FAIL并且那个是未指定的,我认为这又是一些pointer问题,或者是我使用sizeof

IWiaItemExtras* ppWiaExtra = (IWiaItemExtras*)ppWiaDevice;

This line is not correct;这行不正确; you can't just cast pointers to get different COM interfaces.你不能仅仅通过转换指针来获得不同的 COM 接口。 That's what QueryInterface is for:这就是QueryInterface的用途:

IWiaItemExtras* ppWiaExtra;
HRESULT result = ppWiaDevice->QueryInterface(IID_PPV_ARGS(&ppWiaExtra));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM