FatalExecutionEngineError was detected
I am facing a problem while using an unmanaged dll in my .net application and getting the exception "The runtime has encountered a fatal error. The address of the error was at 0x79e71bd7, on thread 0xbb4. 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."
my code is below....
[DllImport("ITMSDLL.dll")]
internal static extern int get_month_mask(ref String theMask,ref String theByt, int theSt_Dow, int theSt_Week, int theEn_Dow, int theEn_Week);
and callng this method by following method in C#
public int GetMonthMask(ref String theMask,ref String theByt, int theSt_Dow, int
theSt_Week, int theEn_Dow, int theEn_Week)
{
return CITMSDLLMethods.get_month_mask(ref theMask, ref theByt, theSt_Dow,
theSt_Week, theEn_Dow, theEn_Week);
}
above tw开发者_开发技巧o methods are from wrapper dll made in .net.
and the above method is called by following code
aRc = Utility.objCITMSDLL.GetMonthMask(ref aRetMask,ref aMByte, aSt_Dow, aSt_Wk, aEn_Dow, aEn_Wk);
when calling this method it throws exception "FatalExecutionEngineError was detected" and the exception message specified in the top.
When an unmanaged method returns a string in a char buffer, it is usually mapped to a StringBuilder in .NET, not a String.
Here is an example for GetWindowText, straight from pinvoke
int GetWindowText(HWND hWnd, LPTSTR lpString, int nMaxCount);
becomes:
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
精彩评论