C# 将托管字符串[]封送到非托管字符** 这是我的C++结构(使用多字节字符集)
和.Net结构C# 将托管字符串[]封送到非托管字符** 这是我的C++结构(使用多字节字符集),c#,c++,string,marshalling,C#,C++,String,Marshalling,和.Net结构 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct HOOKCONFIG { public int threadId; public IntPtr destination; // MarshalAs? public string[] gameApps; // MarshalAs? public string[] profilePa
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct HOOKCONFIG {
public int threadId;
public IntPtr destination;
// MarshalAs?
public string[] gameApps;
// MarshalAs?
public string[] profilePaths;
}
我遇到了一些问题,如何封送字符串数组?
当我在C++中访问Stutt变量“PrimeLePATS”时,我得到了这样的错误:
App.exe中发生类型为“System.AccessViolationException”的未处理异常
其他信息:尝试读取或写入受保护内存。这通常是一个问题
表示其他内存已损坏
简单方法:将原型更改为IntPtr[]:
public IntPtr[] gameApps;
public IntPtr[] profilePaths;
现在,当您呼叫时,需要大致输入以下psudo代码:
GCHandle handle = GCHandle.Alloc(string);
gameApps = new IntPtr[] { GCHandle.ToIntPtr(handle) };
// Unmanaged call
handle.Free();
简单方法:将原型更改为IntPtr[]:
public IntPtr[] gameApps;
public IntPtr[] profilePaths;
现在,当您呼叫时,需要大致输入以下psudo代码:
GCHandle handle = GCHandle.Alloc(string);
gameApps = new IntPtr[] { GCHandle.ToIntPtr(handle) };
// Unmanaged call
handle.Free();
你能试着注释掉HWND/IntPtr吗?你能试着注释掉HWND/IntPtr吗?