问题描述
大家好,
我正在使用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 char [] []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!