473,609 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ 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 3143
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******** ******@TK2MSFTN GP12.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 MarshalAsAttrib ute:

public extern static int method(int p1, int p2,
[MarshalAs(Unman agedType.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.L PArray 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
2139
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: COMClass test = new COMClass(); object results = null;
3
2080
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 unsigned long #include <stdio.h> #include <malloc.h>
1
6779
by: ivang | last post by:
Hello, All! Please help me to marshal following win32 structure: typedef struct _STARTUPINFOW { DWORD cb; LPWSTR lpReserved;
3
3194
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, // environment name DWORD Level, // information level LPBYTE pPrintProcessorInfo, // processor data buffer DWORD cbBuf, // size of data buffer LPDWORD pcbNeeded, // bytes received or required
4
8428
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 class" What i am doing wrong ? here is the code
6
2404
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 C++.NET . This COM component is referenced in my C# application. The COM component statically links with the 6.0 dll. I am facing problems in passing data from C# to the dll through the COM component. Description: 1. The dll exposes a function...
7
10949
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 this screen below. Please help, thanks in advance... Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify...
1
4554
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 number of other C# dlls referencing Interfaces.dll and using logger.dll interop for logging.
8
9427
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 Summation(LPVOID Param) {
0
8139
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.