我的第一个问题:)
我正在使用C++(一个游戏的地图编辑器)编写的应用程序,它具有用C#编写的前端UI.因为我是C#的新手,所以我想尽可能地在C++方面做.
从C#开始,我想调用一个C++函数,该函数将返回一个带有简单变量类型(int和string)的结构列表,这样我就可以在UI中填充一个带有它们的listBox.这可能吗?我应该如何在C#中编写dll导入函数?
我试着在这里搜索答案,但我只找到了如何将列表从C#传递给C++的帖子.
C++代码:
struct PropData
{
PropData( const std::string aName, const int aId )
{
myName = aName;
myID = aId;
}
std::string myName;
int myID;
};
extern "C" _declspec(dllexport) std::vector<PropData> _stdcall GetPropData()
{
std::vector<PropData> myProps;
myProps.push_back( PropData("Bush", 0) );
myProps.push_back( PropData("Tree", 1) );
myProps.push_back( PropData("Rock", 2) );
myProps.push_back( PropData("Shroom", 3) );
return myProps;
}
Run Code Online (Sandbox Code Playgroud)
C#导入功能:
[DllImport("MapEditor.dll")]
static extern ??? GetPropData();
Run Code Online (Sandbox Code Playgroud)
编辑:
在Ed S.的帖子之后,我将c ++代码更改为struct PropData {PropData(const std :: string aName,const int aId){myName = aName; myID = aId; …