问题
I have a DLL file that is written in C++. I am try to use in C++ DLL in my c# code. C++ method is called correctly but it gives error after process completed.
Exception Details:
completed.System.ExecutionEngineException was unhandled Message=Exception of type 'System.ExecutionEngineException' was thrown.
回答1:
I got the same problem with this code:
[DllImport("camapi.dll", CharSet = CharSet.Unicode)]
private static extern CSTATUS_T CWRAPPER_GetFriendlyName(IntPtr pCameraBus, string sCamID, out StringBuilder sFriendlyName,
uint uBufferSizeInWords);
public static string CWRAPPER_GetFriendlyName(IntPtr pCameraBus, string sCamID)
{
var sFriendlyName = new StringBuilder(256);
var status = CWRAPPER_GetFriendlyName(pCameraBus, sCamID, out sFriendlyName, (uint)s.Capacity + 1);
return (status == CSTATUS_T.CSTATUS_SUCCESS) ? sFriendlyName.ToString() : "";
}
The problem was the "out" keyword. The example on MSDN doesn't have the 'out'.
Hope that helps someone... Simon
来源:https://stackoverflow.com/questions/15925884/an-unhandled-exception-of-type-system-executionengineexception-occurred-in-xxx