首页 新闻 会员 周边

.net 调用c的dll,其中形参是 char[][4096]

0
[待解决问题]

c的dll声明函数如下
void test(char data[][4096])
{
printf(data[0]);
if (strcmp(data[0],"hello") == 0)
{
strcpy(data[0], " hi");
}

if (strcmp(data[1], "hello") == 0)
{
	strcpy(data[1], " en");
}

}

c# 来调用
[DllImport("test.dll", EntryPoint = "test", CallingConvention = CallingConvention.Cdecl)]
public static extern char test(char[,] ms);

        char[,] ms = new char[2, 4096];
        ms[0, 0] = 'h';
        ms[0, 1] = 'e';
        ms[0, 2] = 'l';
        ms[0, 3] = 'l';
        ms[0, 4] = 'o';

        ms[1, 0] = 'h';
        ms[1, 1] = 'e';
        ms[1, 2] = 'l';
        ms[1, 3] = 'l';
        ms[1, 4] = 'o';

        test(ms);

值是传递过去了,但是那边strcpy拷贝的数据并没有回来,不知道为啥,感觉像是值传递了,怎么解决,应该怎么调用

HiXiaoYu的主页 HiXiaoYu | 初学一级 | 园豆:4
提问于:2023-03-31 17:17
< >
分享
所有回答(1)
0

https://www.bbsmax.com/A/A7zgq0jY54/ 会不会是C跟C#Char的区别造成的

但乱红尘熊 | 园豆:773 (小虾三级) | 2023-04-04 13:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册