Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing windows API differences between Windows XP and Vista/Server 2008

I am trying to create a single executable of a simple Win32 application that has to be able to run on both Windows XP and Windows Vista/2008.

Due to some changes in the way Vista works some extra Win32 API calls have to be made to make the program function correctly as it did on XP.

Currently I detect if the application is running on a Windows version newer than XP and call the extra win32 functions as needed. This works fine when running on Vista and Server 2008 but fails when running on Windows XP.

On Windows XP when the program starts I get the error message: The procedure entry point ShutdownBlockReasonCreate could not be located in they dynamic link library USER32.DLL. This happens before any of my code starts executing and none of the code paths when running on XP should call that function.

I would really like to just have one executable that works on both XP and Vista. If possible I dont want to have to have conditional compilation and have two executables.

What is the best way to solve this issue?

like image 263
Tim Avatar asked Dec 17 '22 03:12

Tim


1 Answers

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

  typedef BOOL (WINAPI *MYPROC)(HWND, LPCWSTR); 
like image 146
Hans Passant Avatar answered Feb 16 '23 12:02

Hans Passant