Err: Attempted to read or write protected memory - only in VS2005, works fine in VS2003

Hi all

I am wrapping an unmanaged c++ win32 dll functions (  export naming decration is c++ ) into a managed c++ dll using IJW. While calling the managed wrapper from C#,  it crashes at line where I call the unmanaged function and saying the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

If i compile the same managed c++ wrapper code in VS2003 (framework 1.1) and execute,  it works fine without any error.

Is there anything else I need to taken care ( like /clr switch or anything else )specific to 2005/ framework 2.0

thanks...milton.


Answer this question

Err: Attempted to read or write protected memory - only in VS2005, works fine in VS2003

  • Anonymous0011

    Does this mean that the 3rd part library was built with VC2003

    Thanks,
      Ayman Shoukry
      VC++ Team

  • thenewdays

    No its not a vs2003 library, This third party dll is a vc++6 compiled unmanaged dll.

    thanks...milton.

  • Philip Stuyck

    It should just work. Have you tried debugging to see what is really happening

    Also, please provide a small sample reproducing the issue so that folks on the forum could better help you.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • thermowolf

    Hi Ayman,

    I can't debug into the unmanaged part and see what exactly is happening as I dont have the source code.

    Its a thirdparty library and I am provided with the .h file, .lib file and the .dll only. Also another hint is, this unmanaged dll is a JNI based wrapper dll to call functions in a java library.

    The same code works fine in VS 2003. Thats where I am getting confused.

    Following is the code snippet I used:

       XYZRules::XYZRules()
       {
        xyzApi = new XYZAPI(); //unmanaged class
       }


       int XYZRules::SetLicenseKey(String^ LicenseKey)
       {
        const char * szLicenseKey = (const char *)(Marshal::StringToHGlobalAnsi(LicenseKey)).ToPointer();    
        int nRtn = xyzApi->setLicenseKey(szLicenseKey);
        Marshal.FreeHGlobal(szLicenseKey);
        return nRtn; 
       }

    Here the line "int nRtn = xyzApi->setLicenseKey(szLicenseKey);" crashes and says the error. any thoughts..

    thanks...milton.


  • Kevin Won

    Thanks, I will try it. I will contact the third party for a VS2005 compiled library. Donno how fast they will revert.

    The same C Runtime problem has to be there in VS2003 also right But in VS2003 it just works !!!..

    Please let me know if more thoughts come up...

    thanks....milton.

  • DerBruzzzler

    I believe this is not a supported scenario since the library might be using a different model of the CRT (C run time). The best way is to rebuild the 3rd library if possible.

    If you don't have the sources then it is going to be hard to speculate what is happening without being able to debug into the issue.

    Thanks,
      Ayman Shoukry
      VC++ Team



  • Err: Attempted to read or write protected memory - only in VS2005, works fine in VS2003