编组 const std::string 参数
当我尝试将
extern __declspec(dllexport) void SomeNativeFunction(const std::string param1, const std::string param2);
SomeNative.Dll
中定义和声明的函数导入到 .NET 控制台应用程序中时,
class Program
{
[DllImport("SomeNative", CallingConvention = CallingConvention.Cdecl)]
extern static void SomeNativeFuntion(string param1, string param2);
static void Main(string[] args)
{
StartEventHandling("param1", "param2");
}
}
我收到错误
System.AccessViolationException' 发生在 ManagedS7DosEventManagerClient.dll 中 尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
这可能表明我需要正确地整理参数。
字符串默认封送处理概述 不幸的是,没有提及任何有关标准库字符串的封送处理的内容。
When I try to import the function
extern __declspec(dllexport) void SomeNativeFunction(const std::string param1, const std::string param2);
defined and declared in SomeNative.Dll
into a .NET console application using
class Program
{
[DllImport("SomeNative", CallingConvention = CallingConvention.Cdecl)]
extern static void SomeNativeFuntion(string param1, string param2);
static void Main(string[] args)
{
StartEventHandling("param1", "param2");
}
}
I get the error
System.AccessViolationException' occurred in ManagedS7DosEventManagerClient.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Which is probably an indication, that I need to marshal the parameters correctly.
This overview of default marshalings for strings unfortunately doesn't say anything about marshaling of standard library strings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论