标准C转C#对应,C++与C#互操作

DWORD-》UInt32

WORD-》ushort


函数原型 C++中

        //函数功能:测试
	//参数:    char* testIn1[IN]                  -- 测试传入参数1
	//          char* testIn2[IN]               -- 测试传入参数2
	//          char* testOut[OUT]          -- 测试传出参数
	//返回值:  int                                -- 函数执行成功,则返回0;否则返回错误码
	int vxTestFun1(char* testIn1, char* testIn2, char* testOut);

C#中交互对应

        [DllImport("Test.dll", EntryPoint = "vxTestFun1", CallingConvention = CallingConvention.Cdecl)]
        public static extern int vxTestFun1(string testIn1, string testIn2, IntPtr testOut);

C#中调用

            int MaxPath = 260;
            byte[] chararray = new byte[MaxPath];
            IntPtr x = Marshal.AllocHGlobal(MaxPath * sizeof(byte));//申请与chararray相同大小的内存
            Marshal.Copy(chararray, 0, x, MaxPath);//内存拷贝
            VxInvoker.vxTestFun1("testin1","testin2", x);
            Marshal.Copy(x, chararray, 0, MaxPath);
            Marshal.FreeHGlobal(x);//释放内存
            string path = Encoding.Default.GetString(chararray).Trim("\0".ToCharArray()) ;//去除掉字符串中多余的终结符"\0"



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值