CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Posts
    13

    #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>
    Last edited by Marc G; December 26th, 2012 at 04:55 AM. Reason: Added code tags

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: #include <WinBase.h> errors: how to avoid?

    Quote Originally Posted by joeu2004 View Post
    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

  3. #3
    Join Date
    Dec 2012
    Posts
    13

    Re: #include <WinBase.h> errors: how to avoid?

    Quote Originally Posted by Paul McKenzie View Post
    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.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: #include <WinBase.h> errors: how to avoid?

    From the "man page"

    Syntax
    C++


    VOID WINAPI Sleep(
    _In_ DWORD dwMilliseconds
    );
    It's not sleep, it's Sleep. C/C++ is case sensitive.
    Best regards,
    Igor

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: #include <WinBase.h> errors: how to avoid?

    Quote Originally Posted by joeu2004 View Post
    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.
    You have to read it all.
    WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured