Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

C#
[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);
);


Here the C declaration :

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


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

Thanks for helping
Posted
Comments
Richard MacCutchan 23-Jan-15 10:17am    
cList is a 2-dimensional byte array, not an array of strings.
clemhindie 26-Jan-15 2:58am    
Hi Richard,
I try to use a 2-dimensional byte instead of of a string array. The framework throw a MarchalDirectiveException.
Richard MacCutchan 26-Jan-15 4:06am    
See https://msdn.microsoft.com/en-us/library/z6cfh6e6%28v=vs.110%29.aspx for details of how to use such a feature.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900