Reputation: 51
I'm creating a static library that I intend for other people to use. This static library utilizes the Windows header, and in many of the functions it uses Windows definitions, such as DWORD, PDWORD, LPVOID, etc. I want these to be somewhat strict as to really define the functions in my library, reducing misuse. However, if I include the Windows header inside the header files of my static library, then someone who includes my library will automatically have the Windows header also included, and I don't believe this is the correct way of going about this process as many of the libraries I typically include in my other projects also require that I include the correct header files. So how should I go about "requiring" that people who use my library also include the windows header, or at least have my library check to see if the windows header is already included? This applies to other headers too, just in general (i.e. if I had to include iostream, then I would want to check if the iostream header was already included).
Essentially, should my static library take precedence over all of the user's includes, or adapt depending on what the user had already included? If the user includes my library, is it better to have them simply include my library's header and nothing else, or is there some way to make it so the user includes what they need in addition to my library?
For some extra clarity:
#include "MyLibrary.h"
BOOL WINAPI DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpvReserved) {
// Stuff
}
Or
#include <Windows.h>
#include "MyLibrary.h"
BOOL WINAPI DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpvReserved) {
// Stuff
}
Upvotes: 0
Views: 303
Reputation: 1467
It does not matter how many times you include Windows.h
, it already encloses its content within a #ifndef
- #endif
construct. If it was included once, some macro is already defined and the code in the header will not be included again.
On the other hand, if your library is static, it does not rely anymore on any external code, all symbols coming from Windows.h
are effectively private to the library and not seen by anything else.
EDIT : to clarify your last edit.
The public API should be in the .h of your library. If Windows.h
is not part of the API you offer, you better put it in your .cc, so, second option. If, on the contrary, some definitions from Windows.h
are used in the definition of your public API, include it in your .h.
Upvotes: 2