如何在C#中转换C char [] [] [英] How to convert a C char[][] in C#

查看:77
本文介绍了如何在C#中转换C char [] []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用C#编写Winform项目,我必须使用C编写的dll与OpenVMS机器进行通信。



有些方法使用C char **或unsigned char **参数



当我尝试在字符串数组中翻译那些参数时,字节数组或StringBuilder并调用thoses方法我的软件抛出一个AccesViolation。



当我用IntPtr替换thoses参数并使用Marshal.Copy时我遇到了同样的问题();



我的软件是用不安全的选项构建的。



这里有一个来源摘录:



Hi every body,
I'm working on Winform project in C# and I have to use a C written dll to communicate with an OpenVMS machine.

Some methods are using a C char** or an unsigned char** parameters

When i try to "translate" those parameters in string array, byte array or a StringBuilder and call thoses methods my software threw an AccesViolation.

I have the same problem when I replace thoses parameters with an IntPtr and use Marshal.Copy();

My software is build with the unsafe option.

Here an extract from the sources :

[DllImport("IPSecureClt.dll", EntryPoint = "IPSec_ListProjet")]
public static extern int IPSec_ListProject(
[In][Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPTStr)]
ref string[] cListProjects,int iNbElement, ref int iNbProjects);
);





这里的C声明:





Here the C declaration :

long IPSec_ListProjet(char cList[][256+1], const unsigned long lNbElement, unsigned long *lNbProjets);





如何将Cchar **转换为C#字符串数组?



感谢您帮助



How could I convert the "C" char** to a "C#" string array ?

Thanks for helping

推荐答案

查看我的文章和代码呼叫所有电台。它处理在运行时之间转换C ++和C#字符串以及函数调用的东西。
Take a look on my article and code Calling All Stations. It handles the stuff converting C++ and C# strings and function calling between the runtimes.


这篇关于如何在C#中转换C char [] []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆