none
"Attempting to read or write protected memory" exception in release mode RRS feed

  • Question

  • Hello Guys,

    Please help me on this issue.

    I am getiing exception as "Attempting to read or Write protected memory" while calling unamanaged method from C++/CLI code . I am using Net framework 4.0 and VS2010. and also i am using unmanaged static library (.lib) file

    For ur ref,

    method call like this,

    IntPtr nativeFilePath = Marshal.AllocHGlobal(filename);

    LoadDocument((const char*)nativeFilePath .ToPointer(),NULL);

    and Method is

    DLLEXPORT void* STDCALL LoadDocument((const char*) file_path, const char* password);

    Friday, May 21, 2010 11:35 AM

Answers

  • What's the data type of the filename variable?

    Marshal.AllocHGlobal takes a byte count as input, not a file path. Perhaps you wanted to use Marhal.StringToHGlobalAnsi instead?

     


    Mattias, C# MVP
    • Marked as answer by SamAgain Friday, May 28, 2010 4:20 AM
    Friday, May 21, 2010 12:42 PM
    Moderator

All replies

  • What's the data type of the filename variable?

    Marshal.AllocHGlobal takes a byte count as input, not a file path. Perhaps you wanted to use Marhal.StringToHGlobalAnsi instead?

     


    Mattias, C# MVP
    • Marked as answer by SamAgain Friday, May 28, 2010 4:20 AM
    Friday, May 21, 2010 12:42 PM
    Moderator
  • Hi,

       Thaks for your post. Could you provide some more details? Is there some type mismatch in the parameter you passed into the Marshal.AllocHGlobal method?


    Please mark the right answer at right time.
    Thanks,
    Sam
    Monday, May 24, 2010 8:18 AM
  • We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Please mark the right answer at right time.
    Thanks,
    Sam
    Friday, May 28, 2010 4:20 AM