Tech Off Post

Single Post Permalink

View Thread: P/Invoke with char* gives AccessViolationException
  • User profile image

    Hmm... Only problem I can see offhand (and I tested it to be sure just in case) was that you didn't use:

    extern "C"

    In your C function definitions which left the function calls decorated. By adding that everything seemed to work fine using:

    [DllImport(@"c:\test.exe", EntryPoint = "myText")]

    If I left the extern "C" off and used the decorated name (via dumpbin) that also worked.

    [DllImport(@"C:\test.exe", EntryPoint = "?myText@@YAXPAD@Z")]

    So it looks like your problem was more in the decorated names in C++ than anything.

    You can read more about it here: