CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Determine Windows OS from #define

    I have a device handler that was not working with Windows XP. It was fixed by a few #pragma statements ( #pragma inline_depth(0) ) around some areas of code. This fixed it for Windows XP, however....we just noticed that it broke it for Windows 2000.

    Is there a simple #define I can check to wrap the pragmas that will determine if OS is Windows 2000 or XP.

    Basically, I want something like,

    Code:
    #ifdef WINXP
    #pragma inline_depth(0)
    #endif
    I'm googling, but not seeing something like that. I'm guessing there should be.

    Will WINVER be sufficient? What are correct values?
    According to this page,
    0x500 should be value for Win2000,
    and
    0x501 for XP.

    But those are minimum values.....so would I get screwed with some "in between values" perhaps?



    Any help?

  2. #2
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Determine Windows OS from #define

    I just tried wrapping with:

    Code:
    #ifdef (WINVER > 0x500)
    #pragma inline_depth(0)
    #endif
    I should know Monday morning if that worked or not.

  3. #3
    Join Date
    May 2008
    Posts
    300

    Re: Determine Windows OS from #define

    Macros are used before compiling while the os version can be known only when the program is running...

    Are you expecting that a program would know what os it will run on before it is not even compiled?

    WINVER is what windows.h expects YOU to define. If there really are compatibiliy problem, seperate program into two versions.
    Last edited by DreamShore; October 2nd, 2009 at 01:46 PM.
    Nope

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Determine Windows OS from #define

    What DreamShore said.

    Essentially, you'd have to have different versions of your EXE for the different platforms you want to support. So, at install time, you can determine which exe to install.

    Try taking the EXE you created by adding that #ifdef, and run it on a Win2K machine. It should still be broken.

    Viggy

  5. #5
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Determine Windows OS from #define

    Thanks for the tips/reminders.

    I really want to avoid having two separate version of the EXE if possible.

    I am now trying a solution like this (hopefully will get time to get on the testers in the next few hours). Do you think this will work?


    Code:
       OSVERSIONINFOEX osvi;
       BOOL bOsVersionInfoEx;
    
       // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
       // If that fails, try using the OSVERSIONINFO structure.  
       ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
       
       // For SCR#185
       if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
       {
    	   // If GetVersionEx fails, nothing we can do. AFDX may fail
    	   osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    	   GetVersionEx ( (OSVERSIONINFO *) &osvi);
       }
    
    
    
    	// check for WinXP, only call for winXP
    	if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
    	{
    		this->ProcessActionXP();
    	}
    	else
    	{
    		this->ProcessAction2000();
    	}
    The ProcessAction2000 and ProcessActionXP are in separate files.

  6. #6
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Determine Windows OS from #define

    What about Vista? Windows 7?

    Viggy

  7. #7
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Re: Determine Windows OS from #define

    Not a concern....this is an old legacy program that's being phased out. No chance it will be on Vista or 7. It will only be on the platforms its currently on.

    Quote Originally Posted by MrViggy View Post
    What about Vista? Windows 7?

    Viggy


    BTW....the above method appears to have worked!

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