In terms of the OP question, IntPtr does not help him. Assume the exported
function is something like:
BOOL DoSomething(SOMESTRUCT * struct1);
And the managed struct and/or class is:
// Declares a managed structure for the unmanaged structure.
[ StructLayout( LayoutKind.Sequential )]
public struct MyStruct
{
public int one = 1;
public long two =2;
}
// Declares a managed class for the unmanaged structure.
[ StructLayout( LayoutKind.Sequential )]
public class MyClass
{
public int one = 1;
public long two = 2;
}
Then his exports might be something like (among others):
// Because MyStruct is a value type, you cannot pass null as a
// parameter. Instead, declare an overloaded method.
[ DllImport( "Kernel32.dll" )]
public static extern bool DoSomething(
ref MyStruct myStruct );
[ DllImport( "Kernel32.dll" )]
public static extern bool DoSomething(
int flag ); // Declares an int instead of a structure reference so you
can pass a zero.
// Because MyClass is a class, you can also pass null as parameter.
// No overloading is needed.
[ DllImport( "Kernel32.dll", EntryPoint="DoSomething" )]
public static extern bool DoSomething2(
MyClass myClass );
Then he can call "DoSomething" like:
MyStruct ms;
MyClass mc = new MyClass();
bool b = DoSomething(ref ms); //Call using ref to struct.
bool b = DoSomething(0); //Call passing zero. You could pass
(int)IntPtr.Zero here, but why?
bool b = DoSomething2(mc); //Call using ref to class.
bool b = DoSomething2(null); //Call passing null.
In none of those cases does IntPtr help.
--
William Stacey
"Juan Gabriel Del Cid" <jd*****@atrevido.nospam.net> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
Hope that clears it up for you,