tags:

views:

105

answers:

1

Hi, 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 two 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.

A: 

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);

Timores
Hi, Thanks for your answer. I tried by using String bulder but it was also not helpfull and throwing same error.
You should publish the C definition of the method; this way, people here could have a look and suggest a different mapping.
Timores
Actually I dont have the definition of method, I have only .dll file.This dll was previousely used in oracle .fmb application. The following is the used definition in oracle .fmb file.
fh_itms_get_mon_mask := ORA_FFI.REGISTER_FUNCTION(lh_USER,'get_month_mask',ORA_FFI.C_STD);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_CHAR_PTR);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_CHAR_PTR);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT);ORA_FFI.REGISTER_PARAMETER(fh_itms_get_mon_mask,ORA_FFI.C_INT);ORA_FFI.REGISTER_RETURN(fh_itms_get_mon_mask,ORA_FFI.C_INT);
The string parameters seem to be input only, so do not use ref in the method definition (and call), but keep using String as data type.
Timores