C#与C/C++ dll之间数据传递的一些问题与解决

目前因为工作原因需要使用WPF制作用户界面,同时对于处理算法方面需要使用C/C++来写算法并封装成Dll,以便C#端可以调用使用,对于常用类型,比如int,void,char等类别的传递因为之前使用过所以还算驾轻就熟,后面应用到了复杂点的结构体。

例如结构体如下:

C部分的

typedef struct ErrorArea {//the closed rectangle area which contains the black pixels that are connected together.
	int x;//positioin x of the rect left, it is in [0, Solution). 
	int top;//positioin y of the rect top it is in [0, MaxLinesPerPage).
	int w;//width of the rect, in is in [0, Solution). 
	int bottom;//the last line (bottom of the rect)

	int weight;//how many pixels are black in the area.
	int minWidth;//minmum widht of a segment in the area
	int maxWidth;//minmum widht of a segment in the area

	int type;

	//bool splited;//if is spliter into mulite vertical lines 
	//bool hasRing;//if has a ring 
	//bool finished;//is the error area is in detection.

	bool merged;//if is spliter into mulite vertical lines 

	struct ErrorArea* prev;
	struct ErrorArea* succ;
}Error;

对应C#部分定义

 //define Struct
        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct ErrorArea
        {
            public int x;//positioin x of the rect left, it is in [0, Solution). 
            public int top;//positioin y of the rect top it is in [0, MaxLinesPerPage).
            public int w;//width of the rect, in is in [0, Solution). 
            public int bottom;//the last line (bottom of the rect)

            public int weight;//how many pixels are black in the area.
            public int minWidth;//minmum widht of a segment in the area
            public int maxWidth;//minmum widht of a segment in the area

            public int type;

            public bool merged;//if is spliter into mulite vertical lines 
            ErrorArea* prev;
            ErrorArea* succ;
        }
但是在传递的时候出现了问题,之前C端 返回值传递的是Struct * ,但是在调用的时候总是出现问题,后来换了种实现方式,我将Struct* 作为参数指针传递过去进行修改,运行通过了。(18/2/8)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值