1

I have to use a c++ DLL in c# and I have to import in my c# program this function defined in the c++ DLL:

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

How can I "translate" in c#

const std::list <skillset_info>

where skillset_info has defined in c++ dll with the following structure:

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

Thanks a lot!


Managed C# code cannot consume unmanaged C++ objects like std::list. So you cannot use the unmanaged DLL directly from C#.

The simplest solution will be to make a C++/CLI layer that adapts from unmamaged to managed.

Another option would be to adapt the unmamaged code so that it was callable with p/invoke but I think that would involve more effort than C++/CLI.

4

1 回答 1

3

托管 C# 代码不能使用非托管 C++ 对象,例如std::list. 因此,您不能直接从 C# 使用非托管 DLL。

最简单的解决方案是制作一个从未损坏到托管的 C++/CLI 层。

另一种选择是调整未损坏的代码,以便可以使用 p/invoke 调用它,但我认为这比 C++/CLI 需要更多的努力。

于 2013-04-04T11:01:48.033 回答