#include <WinBase.h> errors: how to avoid?
I get a slew of syntax errors starting in line 243 of <WinBase.h>.
The compiler underscores such typedefs as ULONG_PTR, DWORD, PVOID and HANDLE among others.
Presumably, <winbase.h> has a prerequisite header file that it is not #include'g itself :-(.
What am I missing?
PS: I tried changing the order of #include <WinBase.h>, to no avail.
The code is....
Code:
#include "stdafx.h"
#include <stdlib.h>
#include <time.h> // for time()
#include <WinBase.h> // for sleep()
int _tmain(int argc, char* argv[])
{
time_t st, et;
st = time();
sleep(2000);
et = time();
printf("%ld\n%ld\n%ld\n", st, et, et-st);
done:
printf("press Enter to terminate");
getchar();
return 0;
}
"stdafx.h" is (as provided by Visual C++)....
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
"targetver.h" is (as provided by Visual C++)....
#pragma once
#include <SDKDDKVer.h>
Re: #include <WinBase.h> errors: how to avoid?
Quote:
Originally Posted by
joeu2004
I get a slew of syntax errors starting in line 243 of <WinBase.h>.
The compiler underscores such typedefs as ULONG_PTR, DWORD, PVOID and HANDLE among others.
You should include <windows.h>, and from there add any missing headers that are API-based. Trying to cherry-pick which "sub-header" to include, as you've done, isn't the way to go about this.
Regards,
Paul McKenzie
Re: #include <WinBase.h> errors: how to avoid?
Quote:
Originally Posted by
Paul McKenzie
You should include <windows.h>, and from there add any missing headers that are API-based. Trying to cherry-pick which "sub-header" to include, as you've done, isn't the way to go about this.
Thanks. Including <windows.h> does eliminate the error.
As for cherry-picking, I was simply following the information in the sleep "man page" at http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx.
It states that the header file is WinBase.h on WinXP.
But in fact, including <windows.h> and even subsequently including <WinBase.h> does not provide the function prototype for sleep().
I'll post a separate question.
Re: #include <WinBase.h> errors: how to avoid?
From the "man page"
Quote:
Syntax
C++
VOID WINAPI Sleep(
_In_ DWORD dwMilliseconds
);
It's not sleep, it's Sleep. C/C++ is case sensitive.
Re: #include <WinBase.h> errors: how to avoid?
Quote:
Originally Posted by
joeu2004
You have to read it all.
Quote:
WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);