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

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 ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi hansw77041,
> >TryEnterCriticalSection

Do you have include Windows.h ???

David Maisonave :-)
Are you sure you have include Winbase.h  before using TryEnterCriticalSection?
hansw77041Author Commented:

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...
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

hansw77041Author Commented:
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
#include <afxcmn.h>                  // MFC support for Windows Common Controls

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

hansw77041Author Commented:
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 !

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

from your StdAfx.h

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW, also make sure to either

#define _WIN32_WINNT  0x0400

or set _WIN32_WINNT=0x0400

in your project settings.
hansw77041Author Commented:
That fixed it... thanks jkr.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.