Jump to content
  • Advertisement
Sign in to follow this  
NewBreed

including windows.h but cross-platform?

This topic is 4279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm attempting to make my game easier to port when it comes to different platforms other than Windows. Although, to use OGL I need to include <windows.h>. Is there a way I can include <windows.h> through my compiler rather than the source code, so that the source code won't need to be modified to be recompiled on another platform. All the platform specific code (setting up the window etc...) is in a seperate project. I'm using VC2k5. Thank you! (: NB

Share this post


Link to post
Share on other sites
Advertisement
What happened to my question!?!?! Ok... try again:

I'm wanting to make my game easier to port to different platforms other than Windows. To use OGL I need to include <windows.h>, although this then removes the cross platform idea of the game code. Is there a way I can include the header from the compiler without changing the code, so that way I can recompile the game code to a static library for whatever OS? My compiler is VS2K5, the platform specific code (setting up the window etc..) is in a seperate project.

Thank you! (:
NB

Share this post


Link to post
Share on other sites
I don't know about including it through the compiler, but there is a way to include it through source code and not worry about changing the code when you're on a different compiler.

For msvc, you can include like this:


#ifdef _MSC_VER
# include <windows.h>
#endif


_MSC_VER is only defined with visual studio, so the include will only be processed if that is defined.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It might be better to use


#ifdef WIN32 // instead of _MSC_VER
# include
#endif


Since you'll likely want windows.h included on Windows, regardless of which compiler is used.

Share this post


Link to post
Share on other sites
Hrm... some reason viewing the question only shows my reply, I'm viewing this through the "reply to topic" screen. :S

One thing, maybe I could do this:


#define WIN32_VS2K5

#ifdef WIN32_VS2K5
#include <windows.h>
#endif

#ifdef WIN64_VS2K5
#include <windows.h>
#endif

#ifdef LINUX32_SOMELINUXCOMPILER
#include SOMELINUXHEADER
#endif

#ifdef LINUX64_SOMELINUXCOMPILER
#include SOMELINUXHEADER
#endif

Share this post


Link to post
Share on other sites
Or do away with preprocessor defines all together. Include one file, unconditionally. Setup your compiler to include the version of that file appropriate for the current environment.

CM

Share this post


Link to post
Share on other sites
The above posted define will work for VS, but this is a better method

Quote:
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32))
#include <windows.h>
#endif

Share this post


Link to post
Share on other sites
Else you can take a look at the glut.h header file. It totally removes the windows.h dependency.

glut.h only defines the few Windows specifics required, and saves noticeable compilation time even when you work in the Windows context. This used to be a great advantage some years ago, but nowadays CPUs and compilers are so fast, it's not really an argument anymore ...

Still if you do such a choice, which seems rather drastic, you must see it on a broader scale, as a discipline. Be accustommed to separate dependencies (concepts, compilation and linking) and split the project in well formed modules, well interfaced. I'd say it really pays on medium term.

I have created many decent multi OS projects based on GL, and this scheme works quite well. It's very impressive and enjoyable to recompile a complex project developped many weeks on Windows and have it working fine on MAC OS in 5 minutes !

Anything OS dependent put separately in a library, with a modular approach (minimalist system server) and you have clean totally OS independent stuff for your core game engine project.

Share this post


Link to post
Share on other sites
Hmm... Ok, thanks everybody for your replies. A lot of things there to look over here...

I'm quite interested in glut.h as well; never really thought anything of that other than an outdated wrapper. I'll take a good butchers.

Thanks again all,
NB (:

Share this post


Link to post
Share on other sites
Quote:
Original post by CmpDev
The above posted define will work for VS, but this is a better method

Quote:
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32))
#include <windows.h>
#endif


That depends... For example if you're using gcc even on a windows platform, you don't need to include windows.h to use opengl.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!