Question:
C++ Error c2371, dont understand?
2014-06-15 20:08:14 UTC
I was recently compiling a project that had included this block:

#ifndef WIN32
typedef void * HMODULE
#endif

It gave me that error and referred me to this line on the sdk's installation:

typedef HINSTANCE HMODULE;

I dont even understand how that causes a redefinition error. I have no experience absolutely in c++ and would appreciate if someone could help me fix it
Three answers:
Ratchetr
2014-06-15 20:36:24 UTC
The definition of HMODULE has changed over the years. It is no longer a void *, but I *think* it used to be in the past.



The more puzzling thing is how you got the typedef for HMODULE from the sdk, but when you included the other header, WIN32 was not defined. If WIN32 *WAS* defined, then the other header would not try to redefine it. (#ifndef means... #if not defined).



Are you including windows.h? Typically you want to include that first, before any other headers. That should bring in a definition of WIN32, which will cause the other header not to typedef HMODULE.
Jim
2014-06-15 21:12:48 UTC
I usually use

#if !defined(_WIN32)

...

#endif

in order to prevent any possibility of problems with spaces or whatever, AND I get the advantage of being able to do stuff like

#if defined(_MSC_VER) && !defined(_WIN32)

#elif defined(__BORLANDC__) && !defined(__WIN32__)

#else //probably defined, or compiler is unknown type or compiler uses some unknown definition of WIN32?

#endif

for something like that. by the way, this definition differs with the embarcadero compiler and maybe also with mingw-w64 although mingw-w64 pprobably follows MSVC++.



check compiler's predefined macros.

http://msdn.microsoft.com/en-us/library/b0084kay.aspx

http://www.openwatcom.org/ftp/manuals/1.5/clr.pdf

http://docwiki.embarcadero.com/RADStudio/XE6/en/Predefined_Macros

you have your WIN32 wrong by an underscore.
2014-06-15 20:12:29 UTC
In C++ Error C2371 is the redefinition error.



In your application make sure you are not using HMODULE as a variable or object name. Also please do not make any changes to the windows SDK library.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...