Re: How to marshall "pointer to pointer"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ilya Tumanov [MS] (ilyatum_at_online.microsoft.com)
Date: 02/06/05


Date: Sun, 6 Feb 2005 10:46:51 -0800

Please try this:

public static extern Int32 PlaceInstance( UInt32 Handle, UInt16 ParticleID,
UInt16 Layer, Byte[] InstanceName, float X, float Y, Byte[] Path, IntPtr
DstPath );

Call it as follows:

PlaceInstance(handle, 123, 222, Encoding.ASCII.GetBytes("name"), 10, 50,
null, IntPtr.Zero);

Note you can's pass strings. Strings are unicode and your DLL seems to
expect ASCII.

If you're expecting DstPath back, you would have to pass an instance of
IntPtr.
After call is done, cast it to Int32*, get value at this pointer, cast it to
IntPtr and pass it it Marshal.PtrToStringBSTR() to get this string.

Best regards,

Ilya
This posting is provided "AS IS" with no warranties, and confers no rights.

"Xinjie ZHANG" <xjzhang78@hotmail.com> wrote in message
news:edSk8EFDFHA.3416@TK2MSFTNGP09.phx.gbl...
I use a third-party C library in my .NET CF application. The method
signature for one of the C functions is:
int PlaceInstance( U32 Handle, U16 ParticleID, U16 Layer, char*
InstanceName, SFLOAT X, SFLOAT Y, char* Path, char** DstPath );
In C++ applications, it can be called like this:

PlaceInstance(handle, 123, 222, "name", 10, 50, NULL, NULL)

I have tried many ways to make it work, but unfortunately, I can not :(

public static extern int PlaceInstance( uint Handle, ushort ParticleID,
ushort Layer, string InstanceName, float X, float Y, string Path, out
StringBuilder DstPath );
call ==>
StringBuilder builder = new StringBuilder(1024);
PlaceInstance(handle, 123, 222, "name", 10, 50, null, out builder)

public static unsafe extern int PlaceInstance( uint Handle, ushort
ParticleID, ushort Layer, string InstanceName, float X, float Y, char* Path,
char** DstPath );
call ==> PlaceInstance(handle, 123, 222, "name", 10, 50, (char*)0,
(char**)0)

public static unsafe extern int PlaceInstance( uint Handle, ushort
ParticleID, ushort Layer, string InstanceName, float X, float Y, byte* Path,
byte** DstPath );
call ==> PlaceInstance(handle, 123, 222, "name", 10, 50, (byte*)0,
(byte**)0)

public static extern int PlaceInstance( uint Handle, ushort ParticleID,
ushort Layer, string InstanceName, float X, float Y, IntPtr Path, out IntPtr
DstPath );
call ==>
IntPtr ptr = IntPtr.Zero;
PlaceInstance(handle, 123, 222, "name", 10, 50, IntPtr.Zero, out ptr )

They always fail in PlaceInstance call with "Object reference not set to an
instance of an object" error. It makes me crazy :( Could anyone helps me
out? Thanks !



Relevant Pages

  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: inconsistent behavior of >FLOAT
    ... empty string, strings with leading and trailing blanks. ... I think it is too late for>FLOAT to rescind the strong suggestion in its spec that this "should" be the case. ... As long as the spec is tightened to require that a string of blanks must be treated as a valid zero, a programmer would know to filter such a case, if needed, before it is passed to>FLOAT. ... I think ignoring leading and trailing blanks may be reasonable for>FLOAT, as long as it does not violate the current spec. ...
    (comp.lang.forth)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... And now a question about something else: why do you use floating ... use then to copy a float into a char *1. ... binary representation doesn't resemble a string like "123.46343" ...
    (comp.lang.c)
  • Re: help with Table Macro
    ... Available Float, which will always be in column ... string contained in that cell. ... test phrase "available float". ... next matching word and repeat the process until no more matching words ...
    (microsoft.public.word.application.errors)
  • Re: How to know instance name?
    ... Public Property Prop1As String ... ' The Set property procedure is called when the value ... public Class Class1 ... property readonly InstanceName ...
    (microsoft.public.dotnet.general)