我在非托管C/C++代码(dll)中有一个函数,它返回一个包含char数组的结构.我创建了C#struct来接收调用该函数的返回值.并且调用此函数的uppon得到'System.Runtime.InteropServices.MarshalDirectiveException'
这是C声明:
typedef struct T_SAMPLE_STRUCT {
int num;
char text[20];
} SAMPLE_STRUCT;
SAMPLE_STRUCT sampleFunction( SAMPLE_STRUCT ss );
Run Code Online (Sandbox Code Playgroud)
这是C#声明:
struct SAMPLE_STRUCT
{
public int num;
public string text;
}
class Dllwrapper
{
[DllImport("samplecdll.dll")]
public static extern SAMPLE_STRUCT sampleFunction(SAMPLE_STRUCT ss);
}
Run Code Online (Sandbox Code Playgroud)
我使用1字节ASCII.
有没有人有关于如何做到这一点的提示或解决方案?
我想在发生无法处理的访问冲突时创建进程转储文件.
目前,我已经注册了我的,未处理的异常回调:
SetUnhandledExceptionFilter(CustomUnhandledExceptionFilter);
Run Code Online (Sandbox Code Playgroud)
CustomUnhandledExceptionFilter创建转储文件并打印调用堆栈.
但是这种方法有一个缺陷 - 它是在AV已经发生时完成的,AV异常被抛出并且没有被它发生的线程处理.当异常即将离开线程范围并在此时创建转储时调用未处理的异常回调由于堆栈指针丢失,因此没有函数的局部变量发生异常.
有没有办法克服这个问题?我想看看在AV发生的那一刻得到AV的堆栈线程.