我有一個簡單的應用程序,加載一個非託管的dll並從C#傳遞幾個字符串值。但在C++的dll應用程序中,我收到一個異常::嘗試訪問讀/寫保護內存。我的DLL導入看起來是這樣的:傳遞c#字符串到非託管的c + + DLL
[DllImport("X.dll", CallingConvention = CallingConvention.Cdecl) ]
public static extern int
DumpToDBLogFile([MarshalAs(UnmanagedType.I4)]int loggingLevel,
[MarshalAs(UnmanagedType.I4)]int jobId,
int threadId,
[MarshalAs(UnmanagedType.LPStr)]string procName,
[MarshalAs(UnmanagedType.LPStr)]string message);
和C++宣言就像
extern "C"
__declspec(dllexport) int DumpToDBLogFile(int loggingLevel, int jobId, int threadId, string procName, string message)
{
//access strings..
}
請幫助!
似乎C++中的代碼無法訪問c#中的堆。 – Kangkan 2010-03-04 15:52:47