Re: Need help converting/marshalling char** from c++ dll to c# string array
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Mon, 22 Dec 2008 21:53:23 -0500
MS wrote:
I have a dll with function exports I need to import into a c# app. The signature of the c++ function is this:
extern char** WINAPI Flex_GetFeatureList(LM_HANDLE* hJob, int fSearchAll);
I am importing this in my C# app with this declaration:
[System.Runtime.InteropServices.DllImportAttribute(DllName, EntryPoint = "Flex_GetFeatureList")]
public static extern System.IntPtr Flex_GetFeatureList(IntPtr hJob, Int32 fSearchAll);
When I try to read this into a string array in c#, I don't get anything that looks right. It is just a string of garbled characters.
If we assume that the function returns 3 strings then try something
like:
IntPtr p = ...;
IntPtr p0 = Marshal.ReadIntPtr(p, 0);
IntPtr p1 = Marshal.ReadIntPtr(p, 4);
IntPtr p2 = Marshal.ReadIntPtr(p, 8);
string s0 = Marshal.PtrToStringAnsi(p0);
string s1 = Marshal.PtrToStringAnsi(p1);
string s2 = Marshal.PtrToStringAnsi(p2);
there are obviously a bazillion variants, but ...
Arne
.
- Follow-Ups:
- References:
- Prev by Date: Re: Can't send a udp packet to the local PC?
- Next by Date: Re: design oriented forums
- Previous by thread: Need help converting/marshalling char** from c++ dll to c# string array
- Next by thread: Re: Need help converting/marshalling char** from c++ dll to c# string array
- Index(es):
Relevant Pages
|