T
Ted Sung
Hi,
I finally got this C function to be called correctly from C#.
char * version_chk( const char *)
I needed to do the following:
[DllImport( "test.dll",
CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr version_chk(
[MarshalAs(UnmanagedType.LPStr)]
string version );
string sTestVersion = "3.0f_p2";
IntPtr test = version_chk( sTestVersion );
// how do we figure out the length?
string sReturnVersion = Marshal.PtrToStringAnsi(test,7);
Console.WriteLine( "version is " + sReturnVersion ) ;
The key was the CallingConvention!
Now that I have the IntPtr, test, available, I'm trying to understand
how I can know the length instead of having to hardcode it.
Any ideas?
Thanks,
Ted
I finally got this C function to be called correctly from C#.
char * version_chk( const char *)
I needed to do the following:
[DllImport( "test.dll",
CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr version_chk(
[MarshalAs(UnmanagedType.LPStr)]
string version );
string sTestVersion = "3.0f_p2";
IntPtr test = version_chk( sTestVersion );
// how do we figure out the length?
string sReturnVersion = Marshal.PtrToStringAnsi(test,7);
Console.WriteLine( "version is " + sReturnVersion ) ;
The key was the CallingConvention!
Now that I have the IntPtr, test, available, I'm trying to understand
how I can know the length instead of having to hardcode it.
Any ideas?
Thanks,
Ted