【发布时间】:2015-08-31 12:23:21
【问题描述】:
我已经用C#完成了我的部分编码,下面给出一个小方法
public static unitdefn GetUnit(XmlDocument doc)
{
XmlNodeList nodeList1 = (XmlNodeList)doc.DocumentElement.SelectNodes("//UnitDefinitions/Unit");
int countdefn = nodeList1.Count;
unitdefn[] arrunt = new unitdefn[countdefn];
if (countdefn != 0)
{
int i = 0;
foreach (XmlNode node in nodeList1)
{
XmlAttribute att = node.Attributes["name"];
if (att != null)
{
string idu = node.Attributes["name"].Value;
//System.Console.WriteLine(id1);
arrunt[i].name = idu;
}
i++;
}
}
return arrunt[0];
}
并且我希望在我的 C++ 项目中使用此方法,并且我已经完成了如下所示
int xmlRead()
{
int x=1,s=1;
char xmldllpath[1000]="//dllpath";
HMODULE h = LoadLibrary(xmldllpath);
if (!h) {
printf("error: Could not load %s\n", xmldllpath);
return 0; // failure
}
getAdr(&s, h, "GetUnit");
}
dll 加载成功,但未获取该方法 任何具体的方法来做到这一点
【问题讨论】:
-
将 C# 方法“导出”到 C++ 存在一个非常大的问题 - C# 代码全部在 .Net 虚拟机中运行 - 后台总是在执行 JIT、终结/垃圾收集等。在支持从 C++ 代码直接调用的同时如何提供该环境?答案要复杂得多。
标签: c# c++ unmanaged dllexport