Skip to content

Commit 4fa42df

Browse files
dschogitster
authored andcommitted
winansi: simplify loading the GetCurrentConsoleFontEx() function
We introduced helper macros to simplify loading functions dynamically. Might just as well use them. This also side-steps a compiler warning when building with GCC v8.x: it would complain about casting between incompatible function pointers. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08e0450 commit 4fa42df

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

compat/winansi.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <wingdi.h>
88
#include <winreg.h>
99
#include "win32.h"
10+
#include "win32/lazyload.h"
1011

1112
static int fd_is_interactive[3] = { 0, 0, 0 };
1213
#define FD_CONSOLE 0x1
@@ -41,26 +42,21 @@ typedef struct _CONSOLE_FONT_INFOEX {
4142
#endif
4243
#endif
4344

44-
typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
45-
PCONSOLE_FONT_INFOEX);
46-
4745
static void warn_if_raster_font(void)
4846
{
4947
DWORD fontFamily = 0;
50-
PGETCURRENTCONSOLEFONTEX pGetCurrentConsoleFontEx;
48+
DECLARE_PROC_ADDR(kernel32.dll, BOOL, GetCurrentConsoleFontEx,
49+
HANDLE, BOOL, PCONSOLE_FONT_INFOEX);
5150

5251
/* don't bother if output was ascii only */
5352
if (!non_ascii_used)
5453
return;
5554

5655
/* GetCurrentConsoleFontEx is available since Vista */
57-
pGetCurrentConsoleFontEx = (PGETCURRENTCONSOLEFONTEX) GetProcAddress(
58-
GetModuleHandle("kernel32.dll"),
59-
"GetCurrentConsoleFontEx");
60-
if (pGetCurrentConsoleFontEx) {
56+
if (INIT_PROC_ADDR(GetCurrentConsoleFontEx)) {
6157
CONSOLE_FONT_INFOEX cfi;
6258
cfi.cbSize = sizeof(cfi);
63-
if (pGetCurrentConsoleFontEx(console, 0, &cfi))
59+
if (GetCurrentConsoleFontEx(console, 0, &cfi))
6460
fontFamily = cfi.FontFamily;
6561
} else {
6662
/* pre-Vista: check default console font in registry */

0 commit comments

Comments
 (0)