日期:2014-05-17  浏览次数:20825 次

C#调用C++DLL的问题
我在C++dll中定义了这样两个结构体。并提供一个接口

struct score
{
double chinese;
double english;
double math;
double together[3];
};
struct info
{
score scc;
score scc1;
double hehe[100];
};
DATAINTERFACEDLL_API __int32 setNum(info* aaa)
{
aaa->scc1.chinese=100;
aaa->scc.chinese=99;
return 0;
}

然后在C#中调用该DLL。我是用的C#窗体

public struct score
    {
        public double chinese;
        public double english;
        public double math;
        public double[] together; 
    };
    public struct info
    {
        public score scc;
        public score scc1;
        public double[] hehe;
    };
////////
[DllImport("……\\DataInterfaceDll.dll", EntryPoint = "setNum")]
        public static extern int setNum(ref info aaa);

////
        public Form1()
        {
            InitializeComponent();
            info inf=new info();
            SMotionInfoToShow smits = new SMotionInfoToShow();
            setNum(ref inf);
            setInfo(ref smits);
            textBox1.Text = inf.scc1.chinese.ToString();
            textBox3.Text = inf.scc.chinese.ToString();

textbox3中的可以显示99,但是textbox1中未显示100.我试了试,如果结构体中包含结构体,那么只能给第一个包含的结构体中赋值,这是为什么呢?
c# dll c++ struct

------解决方案--------------------
复杂结构你最好用 Mash 那个属性一个个描述清楚。
------解决方案--------------------
结构体一般都很麻烦,
------解决方案--------------------
看下这个就会了  http://dongtingyueh.blog.163.com/blog/static/461945320124239215442/
------解决方案--------------------
结构体确实麻烦,看看有没有人有高招,学习学习