C# mashal const std::list<object> from c++ dll

c# mashal const std::list<object> from c++ dll

本文关键字:gt from c++ dll object mashal const list lt std      更新时间:2023-10-16

我必须在c#中使用c++ DLL并且我必须在我的c#程序中导入在c++ DLL中定义的这个函数:

void rtdGetSkillsetListResult(bool success, const std::list <skillset_info> skillsetList)

如何在c#中"翻译"

const std::list <skillset_info>

其中skillset_info在c++ DLL中定义了如下结构:

struct skillset_info
{
   std::string code;
   bool standby; 
};

非常感谢!

托管c#代码不能使用像std::list这样的非托管c++对象。因此,您不能直接从c#中使用非托管DLL。

最简单的解决方案是创建一个c++/CLI层,它可以从非托管到托管。

另一个选择是调整未管理的代码,使其可以用p/invoke调用,但我认为这将比c++/CLI需要更多的努力。