mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Fix Windows warning about GetVersionEx deprecation.
Rather than squelching the warning, I'm actually paying attention to the deprecation, in that I'm allowing for the possibility that the function might stop existing or stop returning success.
This commit is contained in:
parent
f1fae1bfaa
commit
869a0f5f71
@ -374,23 +374,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* config box. */
|
||||
defuse_showwindow();
|
||||
|
||||
if (!init_winver())
|
||||
{
|
||||
char *str = dupprintf("%s Fatal Error", appname);
|
||||
MessageBox(NULL, "Windows refuses to report a version",
|
||||
str, MB_OK | MB_ICONEXCLAMATION);
|
||||
sfree(str);
|
||||
return 1;
|
||||
}
|
||||
init_winver();
|
||||
|
||||
/*
|
||||
* If we're running a version of Windows that doesn't support
|
||||
* WM_MOUSEWHEEL, find out what message number we should be
|
||||
* using instead.
|
||||
*/
|
||||
if (osVersion.dwMajorVersion < 4 ||
|
||||
(osVersion.dwMajorVersion == 4 &&
|
||||
osVersion.dwPlatformId != VER_PLATFORM_WIN32_NT))
|
||||
if (osMajorVersion < 4 ||
|
||||
(osMajorVersion == 4 && osPlatformId != VER_PLATFORM_WIN32_NT))
|
||||
wm_mousewheel = RegisterWindowMessage("MSWHEEL_ROLLMSG");
|
||||
|
||||
init_help();
|
||||
@ -3111,8 +3103,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||
int n;
|
||||
char *buff;
|
||||
|
||||
if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ||
|
||||
osVersion.dwPlatformId == VER_PLATFORM_WIN32s) break; /* no Unicode */
|
||||
if (osPlatformId == VER_PLATFORM_WIN32_WINDOWS ||
|
||||
osPlatformId == VER_PLATFORM_WIN32s)
|
||||
break; /* no Unicode */
|
||||
|
||||
if ((lParam & GCS_RESULTSTR) == 0) /* Composition unfinished. */
|
||||
break; /* fall back to DefWindowProc */
|
||||
@ -3317,10 +3310,10 @@ static void sys_cursor_update(void)
|
||||
SetCaretPos(caret_x, caret_y);
|
||||
|
||||
/* IMM calls on Win98 and beyond only */
|
||||
if(osVersion.dwPlatformId == VER_PLATFORM_WIN32s) return; /* 3.11 */
|
||||
if (osPlatformId == VER_PLATFORM_WIN32s) return; /* 3.11 */
|
||||
|
||||
if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
|
||||
osVersion.dwMinorVersion == 0) return; /* 95 */
|
||||
if (osPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
|
||||
osMinorVersion == 0) return; /* 95 */
|
||||
|
||||
/* we should have the IMM functions */
|
||||
hIMC = ImmGetContext(hwnd);
|
||||
@ -4672,7 +4665,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
||||
/* XXX how do we know what the max size of the keys array should
|
||||
* be is? There's indication on MS' website of an Inquire/InquireEx
|
||||
* functioning returning a KBINFO structure which tells us. */
|
||||
if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT && p_ToUnicodeEx) {
|
||||
if (osPlatformId == VER_PLATFORM_WIN32_NT && p_ToUnicodeEx) {
|
||||
r = p_ToUnicodeEx(wParam, scan, keystate, keys_unicode,
|
||||
lenof(keys_unicode), 0, kbd_layout);
|
||||
} else {
|
||||
@ -5671,7 +5664,7 @@ void do_beep(void *frontend, int mode)
|
||||
* We must beep in different ways depending on whether this
|
||||
* is a 95-series or NT-series OS.
|
||||
*/
|
||||
if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
if (osPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
Beep(800, 100);
|
||||
else
|
||||
MessageBeep(-1);
|
||||
|
@ -688,8 +688,7 @@ void clear_jumplist(void)
|
||||
/* Adds a saved session to the Windows 7 jumplist. */
|
||||
void add_session_to_jumplist(const char * const sessionname)
|
||||
{
|
||||
if ((osVersion.dwMajorVersion < 6) ||
|
||||
(osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion < 1))
|
||||
if ((osMajorVersion < 6) || (osMajorVersion == 6 && osMinorVersion < 1))
|
||||
return; /* do nothing on pre-Win7 systems */
|
||||
|
||||
if (add_to_jumplist_registry(sessionname) == JUMPLISTREG_OK) {
|
||||
@ -703,8 +702,7 @@ void add_session_to_jumplist(const char * const sessionname)
|
||||
/* Removes a saved session from the Windows jumplist. */
|
||||
void remove_session_from_jumplist(const char * const sessionname)
|
||||
{
|
||||
if ((osVersion.dwMajorVersion < 6) ||
|
||||
(osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion < 1))
|
||||
if ((osMajorVersion < 6) || (osMajorVersion == 6 && osMinorVersion < 1))
|
||||
return; /* do nothing on pre-Win7 systems */
|
||||
|
||||
if (remove_from_jumplist_registry(sessionname) == JUMPLISTREG_OK) {
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include "putty.h"
|
||||
#ifndef SECURITY_WIN32
|
||||
#define SECURITY_WIN32
|
||||
#endif
|
||||
#include <security.h>
|
||||
|
||||
OSVERSIONINFO osVersion;
|
||||
DWORD osMajorVersion, osMinorVersion, osPlatformId;
|
||||
|
||||
char *platform_get_x_display(void) {
|
||||
/* We may as well check for DISPLAY in case it's useful. */
|
||||
@ -186,11 +187,41 @@ void dll_hijacking_protection(void)
|
||||
}
|
||||
}
|
||||
|
||||
BOOL init_winver(void)
|
||||
void init_winver(void)
|
||||
{
|
||||
OSVERSIONINFO osVersion;
|
||||
static HMODULE kernel32_module;
|
||||
DECL_WINDOWS_FUNCTION(static, BOOL, GetVersionExA, (LPOSVERSIONINFO));
|
||||
|
||||
if (!kernel32_module) {
|
||||
kernel32_module = load_system32_dll("kernel32.dll");
|
||||
/* Deliberately don't type-check this function, because that
|
||||
* would involve using its declaration in a header file which
|
||||
* triggers a deprecation warning. I know it's deprecated (see
|
||||
* below) and don't need telling. */
|
||||
GET_WINDOWS_FUNCTION_NO_TYPECHECK(kernel32_module, GetVersionExA);
|
||||
}
|
||||
|
||||
ZeroMemory(&osVersion, sizeof(osVersion));
|
||||
osVersion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
||||
return GetVersionEx ( (OSVERSIONINFO *) &osVersion);
|
||||
if (p_GetVersionExA && p_GetVersionExA(&osVersion)) {
|
||||
osMajorVersion = osVersion.dwMajorVersion;
|
||||
osMinorVersion = osVersion.dwMinorVersion;
|
||||
osPlatformId = osVersion.dwPlatformId;
|
||||
} else {
|
||||
/*
|
||||
* GetVersionEx is deprecated, so allow for it perhaps going
|
||||
* away in future API versions. If it's not there, simply
|
||||
* assume that's because Windows is too _new_, so fill in the
|
||||
* variables we care about to a value that will always compare
|
||||
* higher than any given test threshold.
|
||||
*
|
||||
* Normally we should be checking against the presence of a
|
||||
* specific function if possible in any case.
|
||||
*/
|
||||
osMajorVersion = osMinorVersion = UINT_MAX; /* a very high number */
|
||||
osPlatformId = VER_PLATFORM_WIN32_NT; /* not Win32s or Win95-like */
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE load_system32_dll(const char *libname)
|
||||
|
@ -1129,14 +1129,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* Determine whether we're an NT system (should have security
|
||||
* APIs) or a non-NT system (don't do security).
|
||||
*/
|
||||
if (!init_winver())
|
||||
{
|
||||
modalfatalbox("Windows refuses to report a version");
|
||||
}
|
||||
if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
has_security = TRUE;
|
||||
} else
|
||||
has_security = FALSE;
|
||||
init_winver();
|
||||
has_security = (osPlatformId == VER_PLATFORM_WIN32_NT);
|
||||
|
||||
if (has_security) {
|
||||
#ifndef NO_SECURITY
|
||||
|
@ -105,7 +105,7 @@ printer_enum *printer_start_enum(int *nprinters_ptr)
|
||||
* PRINTER_INFO_5 is recommended.
|
||||
* Bletch.
|
||||
*/
|
||||
if (osVersion.dwPlatformId != VER_PLATFORM_WIN32_NT) {
|
||||
if (osPlatformId != VER_PLATFORM_WIN32_NT) {
|
||||
ret->enum_level = 5;
|
||||
} else {
|
||||
ret->enum_level = 4;
|
||||
|
@ -521,9 +521,9 @@ void show_help(HWND hwnd);
|
||||
/*
|
||||
* Exports from winmisc.c.
|
||||
*/
|
||||
extern OSVERSIONINFO osVersion;
|
||||
GLOBAL DWORD osMajorVersion, osMinorVersion, osPlatformId;
|
||||
void init_winver(void);
|
||||
void dll_hijacking_protection(void);
|
||||
BOOL init_winver(void);
|
||||
HMODULE load_system32_dll(const char *libname);
|
||||
const char *win_strerror(int error);
|
||||
void restrict_process_acl(void);
|
||||
|
Loading…
Reference in New Issue
Block a user