我有一个简单的应用程序加载的非托管的DLL,并传递了一些字符串值,将它从C#。但在C ++ DLL的应用程序,我收到一个异常:试图访问一个读/写保护的内存。我的DLL导入是这样的:
[的DllImport(X.dll,CallingConvention = CallingConvention.Cdecl)
公共静态外部INT
DumpToDBLogFile([的MarshalAs(UnmanagedType.I4)INT loggingLevel,
[的MarshalAs(UnmanagedType.I4)INT JOBID,
INT threadId的,
[的MarshalAs(UnmanagedType.LPStr)字符串PROCNAME,
[的MarshalAs(UnmanagedType.LPStr)字符串消息);
和C ++的宣言就像
的externC
__declspec(dllexport)的INT DumpToDBLogFile(INT loggingLevel,诠释JOBID,诠释threadId的,串PROCNAME,字符串消息)
{
//访问字符串..
}
请帮助!
解决方案 字符串!= LPSTR
尝试:
的externC
__declspec(dllexport)的INT DumpToDBLogFile(INT loggingLevel,诠释JOBID,诠释threadId的,字符* PROCNAME,字符*消息){//访问字符串..
}
I have a simple application that loads an unmanaged dll and passes a few string values to it from C#. But in the C++ dll application, I receive an exception :: Tried to access a read/write protected memory. My DLL Import looks like this:
[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);
and the C++ Declaration is like
extern "C"
__declspec(dllexport) int DumpToDBLogFile( int loggingLevel, int jobId, int threadId, string procName, string message )
{
//access strings..
}
Help please!!!
解决方案string != LPStr
try:
extern "C"
__declspec(dllexport) int DumpToDBLogFile( int loggingLevel, int jobId, int threadId, char* procName, char* message ) { //access strings..
}
上一篇:流明:无法打开流:权限在.../vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107中被拒绝无法打开、被拒、权限、monol
下一篇:找不到类日志找不到、日志