?
Solved

Using TryEnterCriticalSection() is not a member of '`global namespace''

Posted on 2005-04-19
8
Medium Priority
?
1,185 Views
Last Modified: 2012-08-13
Using TryEnterCriticalSection() generates this error C2065 is not a member of '`global namespace''

However using  InitializeCriticalSection() or LeaveCriticalSection() does not generate any errors.

All functions are declared in Winbase.h  

Why does one genrate the error and not the others ?

How to fix it ?
0
Comment
Question by:hansw77041
  • 4
  • 2
  • 2
8 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13817271
Hi hansw77041,
> >TryEnterCriticalSection

Do you have include Windows.h ???

David Maisonave :-)
Cheers!
0
 
LVL 30

Expert Comment

by:Axter
ID: 13817289
Are you sure you have include Winbase.h  before using TryEnterCriticalSection?
0
 

Author Comment

by:hansw77041
ID: 13817400
Axter:

Yes #include <winbase.h> is delcared in stdafx.h .
Interesting when I type ::TryE... The IDE pops up a selection dialog and sure enough there it is. !
So at that point ::TryEnterCriticalSection() is known !

This is crazy why does InitializeCriticalSection() or LeaveCriticalSection()  work without problems...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hansw77041
ID: 13817408
From stdafx.h

#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                  // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <Windows.h>
#include <Winbase.h>

0
 

Author Comment

by:hansw77041
ID: 13817439
Turns out Windows.h should NOT be included...

#include <Windows.h>
// fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

Anyway problem remains the same !
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 13817497
Remove

#define VC_EXTRALEAN          // Exclude rarely-used stuff from Windows headers

from your StdAfx.h
0
 
LVL 86

Expert Comment

by:jkr
ID: 13817513
BTW, also make sure to either

#define _WIN32_WINNT  0x0400

or set _WIN32_WINNT=0x0400

in your project settings.
0
 

Author Comment

by:hansw77041
ID: 13818005
That fixed it... thanks jkr.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question