tags:

views:

97

answers:

3

Hi,

I am using Visual C++, and I am trying to include a file that uses BYTE (as well as DOUBLE, LPCONTEXT...) , which by default is not a defined type.

If I include windows.h, it works fine, but windows.h also defines GetClassName wich I don't need. I am looking for an alternative to windows.h include, that would work with VC++ and would define most of the types like BYTE, DOUBLE ...

Thanks

+2  A: 

BYTE and LPCONTEXT are types used and defined by the Windows API. If you develop a windows application, include windows.h so you can use the Windows API methods and the required types.

Any symbol defined in windows.h that you don't need does not effect your application in any way, they are simply ignored at compile time.

PS: You could, of course, copy the exact definitions of these structs from the windows headers into your own header files, but you don't gain anything. Quite the contrary. The header files define the types shared by all Windows API calls. If these types ever change, your application might crash horribly because the types defined in your private header files and those used by Windows no longer match. That's why everybody who needs those types simply includes windows.h.

Sebastian
+1  A: 

You need to include windows.h to get those types. If you want to reduce the number of defines that windows.h brings in, you can #define WIN32_LEAN_AND_MEAN before including windows.h, which will exclude a lot of stuff (but not everything). See http://support.microsoft.com/kb/166474.

JSBangs
+2  A: 

I think windows.h at most declares GetClassName(), not that it defines it. A function declaration like that (and there will be many, many more brought in by windows.h) doesn't cost anything.

If you're worried that it collides with a function name you want to use, consider putting your own in a namespace.

unwind
+1 for clarifying the declare/define difference
Tomas
Unfortunately the GetClassName function comes from a vendor API, and I had an issue at run time. I used afxwin.h that did the trick.
jules