C#调用c++方法问题,高手请进

Jack2013tong 2009-02-11 10:54:06
//获取排行
int UMWEBCLIENT GetPlayerList(const int maxrows, int* rows, tagPlayerInfo** ppPlayerInfo);
这是c++写的一个方法,um_web_client.dll是供调用的dll
ppPlayerInfo 是结构体
// public struct tagPlayerInfo
// {
// public int id;
// public char[] PlayerName;
// public int Country;
// public int OfficerRace;
// public int Level;
// public int MilitaryRank;
// public int Money;
// public int ResourceCount;
// public int CityCount;
// public int GeneralCount;
// public int Credit;
// };
[DllImport("um_web_client.dll")]
请问在c#中如何声明及调用这个方法,请高手们给出具体的写法,谢谢!
...全文
203 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙宜坡 2009-02-12
  • 打赏
  • 举报
回复
int UMWEBCLIENT GetPlayerList(const int maxrows, int* rows, tagPlayerInfo** ppPlayerInfo);

这个方法就么有说明文档之类的东西么?
Jack2013tong 2009-02-12
  • 打赏
  • 举报
回复
试了,声明没问题,具体取数据的代码不知怎么写
调用的时候out 出来的数组为null
龙宜坡 2009-02-12
  • 打赏
  • 举报
回复
试了没有?
Jack2013tong 2009-02-12
  • 打赏
  • 举报
回复
还没有得到答案,哪位高手帮下忙?
龙宜坡 2009-02-12
  • 打赏
  • 举报
回复
哦,倒是忘记了这个万能的System.IntPtr了,呵呵
Jack2013tong 2009-02-12
  • 打赏
  • 举报
回复
[DllImport("um_web_client.dll")]
public static extern int GetPlayerListCs(int maxrows, out int rows, out IntPtr playerlist);

[DllImport("um_web_client.dll")]
public static extern int GetPlayerListCs(int maxrows, out int rows, tagPlayerInfoOutEx** playerlist);

这样声明可以,测试通过
sphinger 2009-02-12
  • 打赏
  • 举报
回复
路过……
宝_爸 2009-02-11
  • 打赏
  • 举报
回复
可以参考

Passing Structures
http://msdn.microsoft.com/en-us/library/awbckfbz.aspx
宝_爸 2009-02-11
  • 打赏
  • 举报
回复
two level指针tagPlayerInfo** ppPlayerInfo

估计够戗
liaoyunt07 2009-02-11
  • 打赏
  • 举报
回复
我们公司开发用的是C++、C#

都是C++调用C#
龙宜坡 2009-02-11
  • 打赏
  • 举报
回复
public static int GetPlayerList(int maxrows, ref int rows,out tagPlayerInfo[] ppPlayerInfo);


少了个extern

public static extern int GetPlayerList(int maxrows, ref int rows,out tagPlayerInfo[] ppPlayerInfo);
龙宜坡 2009-02-11
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 huwei2003 的回复:]
怎样取出所有的ppPlayerInfo信息呢?(有多条ppPlayerInfo信息)
[/Quote]

难道public static int GetPlayerList(int maxrows, ref int rows, ref tagPlayerInfo ppPlayerInfo);
传的是一个结构体数组?

看样子应该是的,从名字看来GetPlayerList !

哪么方法
public static int GetPlayerList(int maxrows, ref int rows, ref tagPlayerInfo ppPlayerInfo);

的声明应该改一改了

数组本身就引用类型

所以改后我觉得应该是
public struct tagPlayerInfo
{
public int id;
public string PlayerName;
public int Country;
public int OfficerRace;
public int Level;
public int MilitaryRank;
public int Money;
public int ResourceCount;
public int CityCount;
public int GeneralCount;
public int Credit;
};
[DllImport("um_web_client.dll")]
public static int GetPlayerList(int maxrows, ref int rows,out tagPlayerInfo[] ppPlayerInfo);



用的话和一般的C#方法没区别,这个ppPlayerInfo是个输出参数,执行完后直接用ppPlayerInfo[0]...访问
应该可以!

你试试看!
Jack2013tong 2009-02-11
  • 打赏
  • 举报
回复
to:goga21cn
非常谢谢!
请问
public struct tagPlayerInfo
{
public int id;
public string PlayerName;
public int Country;
public int OfficerRace;
public int Level;
public int MilitaryRank;
public int Money;
public int ResourceCount;
public int CityCount;
public int GeneralCount;
public int Credit;
};
[DllImport("um_web_client.dll")]
public static int GetPlayerList(int maxrows, ref int rows, ref tagPlayerInfo ppPlayerInfo);
方法体中怎样取出所有的ppPlayerInfo信息呢?(有多条ppPlayerInfo信息)
万分感谢!!!
龙宜坡 2009-02-11
  • 打赏
  • 举报
回复
UMWEBCLIENT 不明白这个做什么?请教!
龙宜坡 2009-02-11
  • 打赏
  • 举报
回复

声明:
public struct tagPlayerInfo
{
public int id;
public string PlayerName;
public int Country;
public int OfficerRace;
public int Level;
public int MilitaryRank;
public int Money;
public int ResourceCount;
public int CityCount;
public int GeneralCount;
public int Credit;
};
[DllImport("um_web_client.dll")]
public static int GetPlayerList(int maxrows, ref int rows, ref tagPlayerInfo ppPlayerInfo);


wanghao3616 2009-02-11
  • 打赏
  • 举报
回复
up
ws_hgo 2009-02-11
  • 打赏
  • 举报
回复
孟老大,维也纳...
都已经退隐
  • 打赏
  • 举报
回复
注册com
huxuanhui 2009-02-11
  • 打赏
  • 举报
回复
把C++程序编译成 exe文件
改进一下C++程序可以读取参数
参数放在文本文件中
就是C#程序先想文件写入参数
然后 调用用一个进程去跑 exe 文件
然后函数的运行结果
照样写在文本文件中
C#去读取
这个 主要考虑的就是时间的问题

貌似很笨
Lxpd 2009-02-11
  • 打赏
  • 举报
回复
up

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧