views:

38

answers:

2

I'm developing a windows app (it depends on DirectShow, so no Linux, etc).

It will run, for now, in XP and Windows 7 (no Vista support).

However, there's a piece of code that behaves very differently in XP or Windows 7, so I need to know in which system I am, to make a workaround. As I don't support Vista -and even if I did, I guess there wouldn't be much differences- I don't care if Vista and 7 are identified as the same OS, although I'd prefer they weren't.

Just in case, I'm developing in c++, and I don't want to maintain two different executables, and I'd prefer a language-agnostic way to do it.

So, my question: What's The Right Way(tm) to check at run-time which windows version is running?

+2  A: 

See this article on MSDN to get the OS version programatically.

Naveen
@Naveen: Thank you very much. Could you edit your answer to include the function names, so in case the link fails, anyone who finds this page can search for them?
Jaime Pardos
+2  A: 

The article referenced by Naveen has an important remark, that might be relevant for your scenario, too:

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself.

Checking for a particular feature can be done using the IsOS function.

GetVersionEx can be used to retrieve the OS version. However, be aware that the OS will identify differently depending on whether compatibility mode is in effect or not.

0xA3
@0xA3: Thank you. I'm not supporting any new feature, it's just that some DirectShow filters seem to behave differently in XP and 7 when applying some ugly low-level hacks (while some others behave differently even in normal conditions). For now, knowing the OS version seems enough.
Jaime Pardos