Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

public header (raylib.h) with <windows.h> #857

Closed
osom8979 opened this issue Jun 2, 2019 · 2 comments
Closed

public header (raylib.h) with <windows.h> #857

osom8979 opened this issue Jun 2, 2019 · 2 comments

Comments

@osom8979
Copy link

osom8979 commented Jun 2, 2019

I have been working on mixing raylib with imgui in my project.

It was a problem with duplicated symbols on the Windows platform, but this was solved by fixing the code. (ex. Rectangle, DrawText, etc ...)

As a result, we have succeeded but we need to constantly respond to the upgrade.

Do you have plan to modify the public header (raylib.h) to coexist with the <windows.h> file?

@raysan5
Copy link
Owner

raysan5 commented Jun 2, 2019

Hi @osom8979, where is windows.h included? That collision shouldn't happen. Most probably windows.h colliding functions are not being used anywhere, actually, colliding symbols probably come from libraries neither required by the program...

I've been dealing with those windows.h collisions for some years and there is always some wayto avoid them. For example, here it is a possible solution to just include what it's really needed from windows.h:

/* 
  @raysan5: To avoid conflicting windows.h symbols with raylib, some flags are defined
  WARNING: Those flags avoid inclusion of some Win32 headers that could be required 
  by user at some point and won't be included...
*/

/* If defined, the following flags inhibit definition of the indicated items.*/
#define NOGDICAPMASKS     // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOVIRTUALKEYCODES // VK_*
#define NOWINMESSAGES     // WM_*, EM_*, LB_*, CB_*
#define NOWINSTYLES       // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
#define NOSYSMETRICS      // SM_*
#define NOMENUS           // MF_*
#define NOICONS           // IDI_*
#define NOKEYSTATES       // MK_*
#define NOSYSCOMMANDS     // SC_*
#define NORASTEROPS       // Binary and Tertiary raster ops
#define NOSHOWWINDOW      // SW_*
#define OEMRESOURCE       // OEM Resource values
#define NOATOM            // Atom Manager routines
#define NOCLIPBOARD       // Clipboard routines
#define NOCOLOR           // Screen colors
#define NOCTLMGR          // Control and Dialog routines
#define NODRAWTEXT        // DrawText() and DT_*
#define NOGDI             // All GDI defines and routines
#define NOKERNEL          // All KERNEL defines and routines
#define NOUSER            // All USER defines and routines
/*#define NONLS             // All NLS defines and routines*/
#define NOMB              // MB_* and MessageBox()
#define NOMEMMGR          // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMETAFILE        // typedef METAFILEPICT
#define NOMINMAX          // Macros min(a,b) and max(a,b)
#define NOMSG             // typedef MSG and associated routines
#define NOOPENFILE        // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
#define NOSCROLL          // SB_* and scrolling routines
#define NOSERVICE         // All Service Controller routines, SERVICE_ equates, etc.
#define NOSOUND           // Sound driver routines
#define NOTEXTMETRIC      // typedef TEXTMETRIC and associated routines
#define NOWH              // SetWindowsHook and WH_*
#define NOWINOFFSETS      // GWL_*, GCL_*, associated routines
#define NOCOMM            // COMM driver routines
#define NOKANJI           // Kanji support stuff.
#define NOHELP            // Help engine interface.
#define NOPROFILER        // Profiler interface.
#define NODEFERWINDOWPOS  // DeferWindowPos routines
#define NOMCX             // Modem Configuration Extensions

/* Type required before windows.h inclusion  */
typedef struct tagMSG *LPMSG;

#include <windows.h>

/* Type required by some unused function...  */
typedef struct tagBITMAPINFOHEADER {
  DWORD biSize;
  LONG  biWidth;
  LONG  biHeight;
  WORD  biPlanes;
  WORD  biBitCount;
  DWORD biCompression;
  DWORD biSizeImage;
  LONG  biXPelsPerMeter;
  LONG  biYPelsPerMeter;
  DWORD biClrUsed;
  DWORD biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

#include <objbase.h>
#include <mmreg.h>
#include <mmsystem.h>

/* @raysan5: Some required types defined for MSVC/TinyC compiler */
#if defined(_MSC_VER) || defined(__TINYC__)
    #include "propidl.h"
#endif

There are also some libraries out there that divide windows.h into separate pieces.

No plans to modify raylib functions for the moment.

@osom8979
Copy link
Author

osom8979 commented Jun 2, 2019

thank you for reply.

@osom8979 osom8979 closed this as completed Jun 2, 2019
a3f added a commit to athreef/Alien-raylib that referenced this issue Jul 30, 2019
Including both the raylib header and windows.h (via perl.h) is problematic
because they define the same symbols. We might be able get around this by
defining NOUSER and friends to have the WinAPI not use these symbols:
raysan5/raylib#857 (comment)

But for now, just open code the prototype we need for our test and
have the header be used in a separate test that's skipped on Windows.

Fixes #4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants