Differences in the Windows API between Windows XP and Vista / Server 2008

I am trying to create a single executable file for a simple Win32 application that should work on both Windows XP and Windows Vista / 2008.

Due to some changes in the way Vista works, some additional calls to the Win32 API need to be made for the program to function correctly, as it was in XP.

I am currently detecting whether the application is running on a version of Windows newer than XP, and additional win32 functions are called as needed. This works fine for Vista and Server 2008, but it doesn’t work for Windows XP.

In Windows XP, when I start the program, I get an error: the entry point of the ShutdownBlockReasonCreate procedure cannot be located in the dynamic link library USER32.DLL. This happens before any of my codes starts executing, and none of the code paths should work with XP when using XP.

I would really like to have only one executable file that works on both XP and Vista. If possible, I do not want to have conditional compilation and have two executables.

What is the best way to solve this problem?

+4
source share
5 answers

You will need to use LoadLibrary () and GetProcAddress () to get the entry point for this function. In XP, you get NULL back from GetProcAddress (), good enough to just skip the call. There's a good example in the SDK docs, the only tricky part is declaring a function pointer:

typedef BOOL (WINAPI *MYPROC)(HWND, LPCWSTR); 
+6
source

Since Download Delay does not work at the function level , you will have to call new functions on the pointer returned from GetProcAddress with the Windows version checked.

+4
source

In Windows XP, when I start the program, I get an error: the entry point of the ShutdownBlockReasonCreate procedure cannot be located in the dynamic link library USER32.DLL.

See this table for the Xp and Vista Windows APIs. According to the report for user32.dll , the ShutdownBlockReasonCreate ( HWND hWnd, LPCWSTR pwszReason ) symbol ShutdownBlockReasonCreate ( HWND hWnd, LPCWSTR pwszReason ) was added in Vista (and is missing in XP). I think this table may help you solve other portability problems.

enter image description here

+2
source

The Win32 SDK has a good example of this in the multimon.h header. Multi-monitor support was added in Windows 98/2000 and is not supported on 95 or NT 4.

 #define COMPILE_MULTIMON_STUBS #include "multimon.h" 

When COMPILE_MULTIMON_STUBS is determined by a secure function transfer, stubs will be created that will interact with the OS at the lowest level. This causes the call code to become messy with GetVersionEx calls.

+1
source

You can also use the GetVersionEx function to determine which version of Windows your program runs on. Then conditionally call the functions depending on the version of the OS. XP has dwMajorVersion = 5 and dwMinorVersion = 1; Vista has dwMajorVersion = 6 and dwMinorVersion = 0.

-1
source

Source: https://habr.com/ru/post/1301116/


All Articles