Trying to read data from a motorola barcode scanner. Works 99% of the time, then throws a ExecutionEngineException…

Hi guys,

Im using a library called SNAPI.dll written in c++ to read data from a barcode scanner. I'm using PInvoke/DLLImport to use to functions. It works perfectly 99% of the time, and without warning it throws a ExecutionEngineException with very little info available. Its says:

: The runtime has encountered a fatal error. The address of the error was at 0x733c9c82, on thread 0x3ef4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

Here's my main PInvoke signatures with their corresponding C++ signitures in the .h file. Can someone verify they are correct?

 //SNAPIDLL_API int __stdcall SNAPI_Init(HWND hwnd, HANDLE * DeviceHandles, int * NumDevices); [DllImport("SNAPI.dll")] private static extern int SNAPI_Init(IntPtr hwend, IntPtr[] DeviceHandles, ref int NumDevices); //SNAPIDLL_API int __stdcall SNAPI_Connect(HANDLE DeviceHandle); [DllImport("SNAPI.dll")] private static extern int SNAPI_Connect(IntPtr DeviceHandle); //SNAPIDLL_API int __stdcall SNAPI_Disconnect(HANDLE DeviceHandle); [DllImport("SNAPI.dll")] private static extern int SNAPI_Disconnect(IntPtr DeviceHandle); //SNAPIDLL_API int __stdcall SNAPI_SetDecodeBuffer(HANDLE DeviceHandle, unsigned char *pData, long max_length); [DllImport("SNAPI.dll")] private static extern int SNAPI_SetDecodeBuffer(IntPtr DeviceHandle, [In, Out]byte[] pData, int max_length); 

Any help i could get on this would be much appreciated. Thanks!

by CCRed95 via /r/csharp

Leave a Reply