编组 const std::string 参数

发布于 2025-01-11 02:00:51 字数 857 浏览 5 评论 0原文

当我尝试将

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文