C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2009, 10:05 AM   #1
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
passing nullable type to a P/invoked function

Does anyone know of a way I can pass a nullable type to a p/invoked function? specifically I need parameter 1 of:
Code:
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, int? enumerator, IntPtr hwndParent, uint Flags);
to be passable so I can avoid have to overload the function.
__________________
A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside
WDT is offline   Reply With Quote
Old 06-26-2009, 10:15 AM   #2
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 468
SetupDiGetClassDevs

From looking at that I'd use the signature below and pass IntPtr.Zero for NULL.

Code:
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern IntPtr SetupDiGetClassDevs(           // 1st form using a ClassGUID
   ref Guid ClassGuid,
   IntPtr Enumerator,
   IntPtr hwndParent,
   int Flags
);
valaris is offline   Reply With Quote
Old 06-27-2009, 05:57 AM   #3
WDT
Tha 1 Sick RAT
 
Join Date: Dec 2003
Posts: 267
Quote:
Originally Posted by valaris View Post
SetupDiGetClassDevs

From looking at that I'd use the signature below and pass IntPtr.Zero for NULL.

Code:
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern IntPtr SetupDiGetClassDevs(           // 1st form using a ClassGUID
   ref Guid ClassGuid,
   IntPtr Enumerator,
   IntPtr hwndParent,
   int Flags
);
I meant parameter 1 of the function. not the enumerator the ref Guid ClassGuid variable. Also I should say I changed the enumerator to string type variable. The original posting of the function was a typo.
__________________
A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside
WDT is offline   Reply With Quote
Old 06-27-2009, 08:48 AM   #4
Registered User
 
Join Date: Mar 2009
Location: england
Posts: 95
A Guid can't be null, but you can also use this second signature:

Code:
[DllImport("setupapi.dll", CharSet = CharSet.Auto)] 
static extern IntPtr SetupDiGetClassDevs(
   IntPtr ClassGuid,
   string Enumerator,
   IntPtr hwndParent,
   int Flags
);
Code:
SetupDiGetClassDevs(IntPtr.Zero, ...........
theoobe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VC Toolkit 2003 Noobwaker Windows Programming 8 03-13-2006 07:33 AM
Game Pointer Trouble? Drahcir C Programming 8 02-04-2006 02:53 AM
<Gulp> kryptkat Windows Programming 7 01-14-2006 01:03 PM
Question on l-values. Hulag C++ Programming 6 10-13-2005 04:33 PM
passing counters between function BungleSpice C Programming 18 02-21-2004 06:16 PM


All times are GMT -6. The time now is 06:44 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22