c++ mutex header and windows header conflicts

Sep 14, 2014 at 2:51pm
Hi,

When I try to include the header of mutex (#include <mutex>) after the windows one(#include <Windows.h>), all windows variables get destroyed, and the compilers gives out errors that STD:: functions are not defined.

How can I solve this?

Thank you,

Gomitung
Sep 14, 2014 at 5:15pm
This doesn't make any sense OP. Let's start with you telling us what version of which IDE you are using.

EDIT: Your code would help to if you don't mind. That way we will be able to see what you are trying to call.
Last edited on Sep 14, 2014 at 5:18pm
Sep 19, 2014 at 5:36pm
The code is:
1
2
3
4
#include <mutex>
#include <Windows.h>
std::mutex mtx;
HWND hwnd;


HWND is not defined.
Sep 19, 2014 at 7:23pm
Like I said, we should start with the name and version of the IDE and compiler that you are using. This will tell us if this particular C++x11 feature is supported or not. If it is not, then that would at least explain the issue that you are seenig. In that case the WinAPI still has it's own version of a Mutex that you may be able to use instead.
Last edited on Sep 19, 2014 at 7:24pm
Sep 19, 2014 at 7:36pm
Microsoft Visual Studio 2013
Sep 19, 2014 at 8:04pm
I have VS2013 Express and cannot confirm your problem in a new blank project.
Sep 19, 2014 at 8:10pm
I'm glad I'm not the only one.

@ OP: HWND is defined in 'Windef.h' which should be brought in from a relative directory when you include 'Windows.h'. Do you have a current Windows SDK in your search path or are you trying to include this using only literal paths that you cut out when you posted this here?
Sep 19, 2014 at 8:11pm
Yes, if I remove the include of the mutex and the std::mutex variable, the HWND works.
Sep 19, 2014 at 8:16pm
Try reinstalling your compiler and make sure any other compilers (e.g. MinGW) are not in your system path when you try again (I usually just rename the MinGW folder with a dash at the end).
Sep 19, 2014 at 8:23pm
Thanks! That solved it!
Topic archived. No new replies allowed.