views:

155

answers:

3

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

+7  A: 

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");
FigBug
A: 
Michael Stum
A: 

You could call FindFirstFile instead of GetFileTime. I wouldn't know an alternative for SetFileTime, though.

MSalters
From the research I have done it seems that there isn't one, thanks though!
SteveL