473,486 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

com interop passing parameter (DWORD *)null

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?
Nov 15 '05 #1
3 3131
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
unsafe
{
uint * NullPtr = null;
SomeMethod(ref * NullPtr);
}
Nov 15 '05 #3
"No Spam Man" <no****@nospam.com> wrote in
news:eK**************@TK2MSFTNGP12.phx.gbl:
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.

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2131
by: spammy | last post by:
Hi all, Im attempting to use a COM class in C# via .NET interop. The class has two modes - synhrounous and asynchronous. The mode is determined by the use (or not) of an optional out parameter:...
3
2068
by: Thomas Christmann | last post by:
Hi! Sorry for the weird topic, I don't know how to describe it better... I have a little problem here I can't wrap my mind around. If I do: ------------------------------------- #define DWORD...
1
6762
by: ivang | last post by:
Hello, All! Please help me to marshal following win32 structure: typedef struct _STARTUPINFOW { DWORD cb; LPWSTR lpReserved;
3
3184
by: Keith M | last post by:
Could some kind soul illustrate how I can call the EnumPrintProcessors Win32 API from c# code? BOOL EnumPrintProcessors( LPTSTR pName, // print server name LPTSTR pEnvironment, ...
4
8418
by: dogalacar | last post by:
Hi All, I am trying to pass array of structures from a C dll to C# as msdn sample does(outarrayofstructs sample) but PtrToStructure function gives error : --> "structure must not be a value...
6
2393
by: Nataraj1978 | last post by:
I have a requirement to use a dll written in Visual C++ 6.0 in my C# application. In order to establish the link between my application and the dll, I have written a ATL COM Component in Visual...
7
10936
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
1
4541
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
8
9422
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.