//获取排行 
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#中如何声明及调用这个方法,请高手们给出具体的写法,谢谢!

解决方案 »

  1.   

    我们公司开发用的是C++、C#都是C++调用C#
      

  2.   

    two level指针tagPlayerInfo** ppPlayerInfo估计够戗
      

  3.   

    可以参考Passing Structures
    http://msdn.microsoft.com/en-us/library/awbckfbz.aspx
      

  4.   

    把C++程序编译成 exe文件
    改进一下C++程序可以读取参数
    参数放在文本文件中
    就是C#程序先想文件写入参数
    然后 调用用一个进程去跑 exe 文件
    然后函数的运行结果
    照样写在文本文件中
    C#去读取
    这个 主要考虑的就是时间的问题貌似很笨
      

  5.   


    声明:
    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);
      

  6.   

    UMWEBCLIENT 不明白这个做什么?请教!
      

  7.   

    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信息) 
    万分感谢!!!
      

  8.   


    难道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]...访问
    应该可以!你试试看!
      

  9.   

    public static int GetPlayerList(int maxrows, ref int rows,out tagPlayerInfo[] ppPlayerInfo);少了个externpublic static extern int GetPlayerList(int maxrows, ref int rows,out tagPlayerInfo[] ppPlayerInfo);
      

  10.   

    试了,声明没问题,具体取数据的代码不知怎么写
    调用的时候out 出来的数组为null
      

  11.   

    int UMWEBCLIENT GetPlayerList(const int maxrows, int* rows, tagPlayerInfo** ppPlayerInfo); 这个方法就么有说明文档之类的东西么?
      

  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);这样声明可以,测试通过
      

  13.   

    哦,倒是忘记了这个万能的System.IntPtr了,呵呵