CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 1999
    Posts
    123

    Conditional compilation by Windows version

    I want to conditionally compile sections of code if the Windows version is not Windows 95.

    Am I correct in assuming that I can't use ::GetVersionEx?

    Am I correct that #if (WINVER > 0x400) will work but it will also exclude for NT 4?

    How do you suggest I do this?

  2. #2
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    Am I correct in assuming that I can't use ::GetVersionEx?
    Yes, you're correct. Function/method calls are not evaluated at compile time.

    I'm not sure about the various #defines for WINVER. There may be a header someplace with that info.

    You realize that a conditional compile will only be effective for the building of the application i.e. if you build it on a win 95 or XP machine -- if you build on XP (etc..) it will still be the same application when you move it to 95...
    Last edited by bytz; September 29th, 2003 at 08:26 AM.
    bytz
    --This signature left intentionally blank--

  3. #3
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Conditional compilation by Windows version

    Originally posted by Bob H
    I want to conditionally compile sections of code if the Windows version is not Windows 95.
    Just think again about what you're asking here... Got a little confused about compile time vs. run time?

  4. #4
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    These are the winver values that I could find
    ** WINVER < 0x400 = Windows NT 3.5, Windows NT 3.51
    ** WINVER = 0x400 = Windows 95, Windows NT SUR (default)
    ** WINVER > 0x400 = Windows NT SUR enhancements
    WINVER = 0x030a (NT 3.5?)
    WINVER = 0x0500 (XP/2000?)

    Good luck
    bytz
    --This signature left intentionally blank--

  5. #5
    Join Date
    Apr 1999
    Posts
    123
    I am getting runtime errors when the application runs on Window 95 machines like "... exe file is linked to missing export USER32.DLL: Track Mouse event".

    I believe I can solve this by excluding certain code at compile time. I added an Office XP menu system which uses trackmouseevent. By excluding includes to this code and other code references to the office xp menu system, it should revert to the regular windows menu system and the error messages should go away.

    ------------------

    I read the posts above again and thought a bit. You are right. This won't work because this method is tied to the machine I am compiling on.
    Last edited by Bob H; September 29th, 2003 at 08:43 AM.

  6. #6
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    No... yes, well, actually you're right and wrong. Yes, what is included in the application and how it works is determined by the compile machine. No, if you want to make it work on different machines, you don't want to use conditional compliation.

    For features that don't work well on "back" versions of Windows, like 95 with no service packs/upgrades, you'll need to add code that checks the version of windows and executes the appropiate code, like:
    // PSEUDO CODE!!!
    if (version >= 98)
    do one thing
    else
    do other thing

    Note: this is conditional execution not conditional compliation.
    bytz
    --This signature left intentionally blank--

  7. #7
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    There should be several threads and sample code to detect and interput the version information for windows. A sample code for drawing gradients illustrates a simple use for this.
    bytz
    --This signature left intentionally blank--

  8. #8
    Join Date
    Apr 1999
    Posts
    123
    I know how to do that. Thanks.

    I got this Office XP menu code off CodeProject. I have posted on the forum associated with the code if this approach of excluding calls to the code at runtime will solve the problem. There are 8 different calls to the code so I will probably wait for an answer before plunging in.

  9. #9
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by bytz
    These are the winver values that I could find
    ** WINVER < 0x400 = Windows NT 3.5, Windows NT 3.51
    ** WINVER = 0x400 = Windows 95, Windows NT SUR (default)
    ** WINVER > 0x400 = Windows NT SUR enhancements
    WINVER = 0x030a (NT 3.5?)
    WINVER = 0x0500 (XP/2000?)

    Good luck
    MSDN should have a table if you just look for WINVER

  10. #10
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    In such situations where there is a runtime decision, I sometimes do this.

    1. GetVersion or GetVersionEx...

    2. if Platform 1,

    API1

    else

    API2.

    Here, I do not use LoadLibrary, GetProc etc... but I use the APIs themselves, supported or unsupported. But these DLLs, I force to delay load..

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