Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling NT function on pre-NT system

So I don't do a lot of Win32 calls, but recently I have had to use the GetFileTime() and SetFileTime() functions. Now although Win98 and below are not officially supported in my program people do use it there anyway, and I try to keep it as usable as possible. I was just wondering what will happen as those functions do not exist in pre-NT systems, will they receive an error message of some sort for example because in that case I will add in an OS check? Thanks

like image 280
SteveL Avatar asked Dec 02 '08 16:12

SteveL


1 Answers

If you call the functions directly, then your program will not load on Win98.

What you can do is use LoadLibrary() / GetProcAddress() to get a pointer to GetFileTime() / SetFileTime(). On Win98 this will fail, giving you a null pointer which you can test for and ignore. On 2000 and later you will get a pointer which you can then use.

It's a pain, but it's the only solution I know of.

Here is an example of getting the UpdateLayeredWindow function if it exists:

typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);

UpdateLayeredWinFunc updateLayeredWindow = 0;
HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
like image 51
Roland Rabien Avatar answered Nov 10 '22 03:11

Roland Rabien