Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I forward declare HANDLE? (Win32)

Tags:

c++

c

winapi

How do I forward declare HANDLE? I don't want to include all of windows.h in this particular header.

like image 226
Billy ONeal Avatar asked Nov 08 '10 04:11

Billy ONeal


2 Answers

The header that actually typedefs HANDLE is winnt.h. Unfortunately this is 15K lines - here, so fixing your issue by including the slimline windef.h is a bit misleading.

Here is the relevant part on my system (obviously the details could change from revision to revision, but won't change at the implementation level since this would break existing binaries):

//
// Handle to an Object
//

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct name##__ *name
#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
typedef HANDLE *PHANDLE;

PS gotta love that #if 0 in this shipping Microsoft header file.

like image 195
Steve Townsend Avatar answered Nov 04 '22 17:11

Steve Townsend


Well, looks like I answered this one myself. I just #includeed <windef.h> instead of <windows.h> for now. I would still like to be able to forward declare just HANDLE if anyone has a way of doing so.

like image 29
Billy ONeal Avatar answered Nov 04 '22 15:11

Billy ONeal