com interop passing parameter (DWORD *)null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got an app that I've written using C# and some type libraries I've
generated from some of the directx .IDL files.

I have got a problem with calling some of the methods on the generated
interfaces. As an example, I've got a method I want to call that has a
parameter call reserved, that must be null or the method call fails with
unexpected parameter.

int method(int p1, int p2, DWORD *reserverd)

When I reference the TLB from my C#, it expects a call like:

int method(int p1, int p2, ref uint reserved)

How can I pass null to this method() for the reserved parameter? No,
declaring 'uint reserved=0;' and passing that in doesn't do the job.

Any thoughts?
 
How can I pass null to this method() for the reserved parameter?

You can't. If you want to do that, you have to change the parameter
type in the interop assembly to an IntPtr (native int in ILAsm syntax)
or uint*.



Mattias
 
I've got an app that I've written using C# and some type libraries
I've generated from some of the directx .IDL files.

I have got a problem with calling some of the methods on the generated
interfaces. As an example, I've got a method I want to call that has
a parameter call reserved, that must be null or the method call fails
with unexpected parameter.

int method(int p1, int p2, DWORD *reserverd)

When I reference the TLB from my C#, it expects a call like:

int method(int p1, int p2, ref uint reserved)

How can I pass null to this method() for the reserved parameter? No,
declaring 'uint reserved=0;' and passing that in doesn't do the job.

Any thoughts?

Use the MarshalAsAttribute:

public extern static int method(int p1, int p2,
[MarshalAs(UnmanagedType.U4)] IntPtr reserved);

IntPtr ptr = new IntPtr(0);
method(1,2,ptr);

or some other UnamangedType depending what you are expection on the last
param.

If there's to be an array passed you could also use
UnmanagedType.LPArray or SafeArray ... whatever you need.
 
Back
Top