Error[8]: Undefined offset: 7, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我看了看,尝试了一切我能想到或已经找到的建议.我仍然没有运气获得我需要的数据. 我正在使用第三方DLL,我认为它是用C语言编写的.我需要在C#中访问此DLL中的函数.在大多数情况下,我有这个工作,除了一个功能.我遇到问题的函数有以下标题: uint queryNumOfServers(USHORT *NumOfServers, char ServerNames[8][16]); 我在C#应用程序中 我看了看,尝试了一切我能想到或已经找到的建议.我仍然没有运气获得我需要的数据.

我正在使用第三方DLL,我认为它是用C语言编写的.我需要在C#中访问此DLL中的函数.在大多数情况下,我有这个工作,除了一个功能.我遇到问题的函数有以下标题:

uint queryNumOfServers(USHORT *NumOfServers,char Servernames[8][16]);

我在C#应用程序中声明了以下内容

[Dllimport("clIEnt.dll",CharSet=CharSet.Ansi]public static extern uint queryNumOfServers(ref short numberofServer,StringBuilder servernames);

我这称之为:

StringBuilder servernames = new StringBuilder(128);short numServers = -1;queryNumberOfServers(ref numServers,servernames);

问题是,虽然numberOfServers返回等于4,但我只在servernames中获得一个名称.我在一个小C程序中测试了上面的C函数.我得到了numberOfServer = 4,但我还得到了4个名字.

我试过以下但没有成功:

[Dllimport("clIEnt.dll",CharSet=charSet.Ansi,CallingConvention = CallingConvention.StdCall)]public static extern uint queryNumOfServers(ref short numberOfServer,[MarshalAs(UnmanagedType.LPStr)] string servernames);

称之为

string servernames = new string('
[Dllimport("clIEnt.dll",CharSet = CharSet.Ansi)]public static extern uint queryNumOfServers(ref short numberOfServers,[MarshalAs(UnmanagedType.LPArray)] byte[,] servernames);
',128);queryNumOfServers(ref numServers,servernames);

使用此选项对servernames没有任何更改.

开发环境是Visual Studio 2008.

解决方法 经过多次搜索和拔毛,这是对我有用的解决方案.

在我的C#应用​​程序中声明了函数头:

byte[,] servernames = new byte[8,16];short numServers = -1;queryNumberOfServers(ref numServers,servernames);

然后调用如下:

[+++]

这将返回一个双索引字节数组.从这里我使用Buffer.Blockcopy()和EnCoding.UTF8.GetString()将我的字节数组转换为字符串数组.

总结

以上是内存溢出为你收集整理的将C char [] []数组元素编组为C#全部内容,希望文章能够帮你解决将C char [] []数组元素编组为C#所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
将C char [] []数组元素编组为C#_C_内存溢出

将C char [] []数组元素编组为C#

将C char [] []数组元素编组为C#,第1张

概述我看了看,尝试了一切我能想到或已经找到的建议.我仍然没有运气获得我需要的数据. 我正在使用第三方DLL,我认为它是用C语言编写的.我需要在C#中访问此DLL中的函数.在大多数情况下,我有这个工作,除了一个功能.我遇到问题的函数有以下标题: uint queryNumOfServers(USHORT *NumOfServers, char ServerNames[8][16]); 我在C#应用程序中 我看了看,尝试了一切我能想到或已经找到的建议.我仍然没有运气获得我需要的数据.

我正在使用第三方DLL,我认为它是用C语言编写的.我需要在C#中访问此DLL中的函数.在大多数情况下,我有这个工作,除了一个功能.我遇到问题的函数有以下标题:

uint queryNumOfServers(USHORT *NumOfServers,char Servernames[8][16]);

我在C#应用程序中声明了以下内容

[Dllimport("clIEnt.dll",CharSet=CharSet.Ansi]public static extern uint queryNumOfServers(ref short numberofServer,StringBuilder servernames);

我这称之为:

StringBuilder servernames = new StringBuilder(128);short numServers = -1;queryNumberOfServers(ref numServers,servernames);

问题是,虽然numberOfServers返回等于4,但我只在servernames中获得一个名称.我在一个小C程序中测试了上面的C函数.我得到了numberOfServer = 4,但我还得到了4个名字.

我试过以下但没有成功:

[Dllimport("clIEnt.dll",CharSet=charSet.Ansi,CallingConvention = CallingConvention.StdCall)]public static extern uint queryNumOfServers(ref short numberOfServer,[MarshalAs(UnmanagedType.LPStr)] string servernames);

称之为

string servernames = new string('
[Dllimport("clIEnt.dll",CharSet = CharSet.Ansi)]public static extern uint queryNumOfServers(ref short numberOfServers,[MarshalAs(UnmanagedType.LPArray)] byte[,] servernames);
',128);queryNumOfServers(ref numServers,servernames);

使用此选项对servernames没有任何更改.

开发环境是Visual Studio 2008.

解决方法 经过多次搜索和拔毛,这是对我有用的解决方案.

在我的C#应用​​程序中声明了函数头:

byte[,] servernames = new byte[8,16];short numServers = -1;queryNumberOfServers(ref numServers,servernames);

然后调用如下:

这将返回一个双索引字节数组.从这里我使用Buffer.Blockcopy()和EnCoding.UTF8.GetString()将我的字节数组转换为字符串数组.

总结

以上是内存溢出为你收集整理的将C char [] []数组元素编组为C#全部内容,希望文章能够帮你解决将C char [] []数组元素编组为C#所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1244417.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存