|
-
January 23rd, 2018, 06:17 AM
#1
[RESOLVED] How to use version number macros/definitions
I need to hide a function if product version 4.3.0 or lower is being used. A macro has been defined that I can use for this case as:
Code:
#define PRODUCT_VERSION ((PRODUCT_MAJOR_VERSION << 16) + (PRODUCT_MINOR_VERSION << 8) + PRODUCT_BUILDNUMBER)
I've printed the PRODUCT_VERSION for version 4.3.1 to console and seen that it translates to 262913 so I've used that number in a #if as shown below which is a working solution to my problem but it's also a bad and ugly solution. Is there a better way to work with this macro?
Code:
#if PRODUCT_VERSION>=262913
void troublesomefunction()
{
//code
}
#endif
-
January 23rd, 2018, 06:53 AM
#2
Re: How to use version number macros/definitions
This is similar to how dealing with different windows versions work. See https://docs.microsoft.com/en-us/cpp...nd-win32-winnt
The small difference is that windows versions work on hex numbers - not decimal. So 262913 becomes 0x040301 and the text becomes
Code:
#if PRODUCT_VERSION>=0x040301
void troublesomefunction()
{
//code
}
#endif
You could also do it like this
Code:
#define PROD430 0x040300
#define PROD431 0x040301
#if PRODUCT_VERSION >= PROD431
void troublesomefunction()
{
//code
}
#endif
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 23rd, 2018, 07:17 AM
#3
Re: How to use version number macros/definitions
I didn't realise it worked on hex, no wonder my decimal version number looked odd.
Thanks 2kaud
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|