Skip to content

Commit

Permalink
Stop using dynamic loading for some APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed May 31, 2020
1 parent 069badb commit c457685
Showing 1 changed file with 11 additions and 55 deletions.
66 changes: 11 additions & 55 deletions src/os_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,27 +246,6 @@ static BOOL win8_or_later = FALSE;
# define UChar uChar.UnicodeChar
# endif

#if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
// Dynamic loading for portability
typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX
{
ULONG cbSize;
COORD dwSize;
COORD dwCursorPosition;
WORD wAttributes;
SMALL_RECT srWindow;
COORD dwMaximumWindowSize;
WORD wPopupAttributes;
BOOL bFullscreenSupported;
COLORREF ColorTable[16];
} DYN_CONSOLE_SCREEN_BUFFER_INFOEX, *PDYN_CONSOLE_SCREEN_BUFFER_INFOEX;
typedef BOOL (WINAPI *PfnGetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX);
static PfnGetConsoleScreenBufferInfoEx pGetConsoleScreenBufferInfoEx;
typedef BOOL (WINAPI *PfnSetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX);
static PfnSetConsoleScreenBufferInfoEx pSetConsoleScreenBufferInfoEx;
static BOOL has_csbiex = FALSE;
#endif

/*
* Get version number including build number
*/
Expand Down Expand Up @@ -7682,30 +7661,13 @@ vtp_flag_init(void)
static void
vtp_init(void)
{
HMODULE hKerneldll;
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
CONSOLE_SCREEN_BUFFER_INFOEX csbi;
# ifdef FEAT_TERMGUICOLORS
COLORREF fg, bg;
# endif

// Use functions supported from Vista
hKerneldll = GetModuleHandle("kernel32.dll");
if (hKerneldll != NULL)
{
pGetConsoleScreenBufferInfoEx =
(PfnGetConsoleScreenBufferInfoEx)GetProcAddress(
hKerneldll, "GetConsoleScreenBufferInfoEx");
pSetConsoleScreenBufferInfoEx =
(PfnSetConsoleScreenBufferInfoEx)GetProcAddress(
hKerneldll, "SetConsoleScreenBufferInfoEx");
if (pGetConsoleScreenBufferInfoEx != NULL
&& pSetConsoleScreenBufferInfoEx != NULL)
has_csbiex = TRUE;
}

csbi.cbSize = sizeof(csbi);
if (has_csbiex)
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg];
save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg];
store_console_bg_rgb = save_console_bg_rgb;
Expand Down Expand Up @@ -7930,7 +7892,7 @@ ctermtoxterm(
set_console_color_rgb(void)
{
# ifdef FEAT_TERMGUICOLORS
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
CONSOLE_SCREEN_BUFFER_INFOEX csbi;
guicolor_T fg, bg;
int ctermfg, ctermbg;

Expand All @@ -7950,8 +7912,7 @@ set_console_color_rgb(void)
bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);

csbi.cbSize = sizeof(csbi);
if (has_csbiex)
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);

csbi.cbSize = sizeof(csbi);
csbi.srWindow.Right += 1;
Expand All @@ -7960,8 +7921,7 @@ set_console_color_rgb(void)
store_console_fg_rgb = csbi.ColorTable[g_color_index_fg];
csbi.ColorTable[g_color_index_bg] = (COLORREF)bg;
csbi.ColorTable[g_color_index_fg] = (COLORREF)fg;
if (has_csbiex)
pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
# endif
}

Expand Down Expand Up @@ -8017,22 +7977,20 @@ get_default_console_color(
reset_console_color_rgb(void)
{
# ifdef FEAT_TERMGUICOLORS
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
CONSOLE_SCREEN_BUFFER_INFOEX csbi;

if (USE_WT)
return;

csbi.cbSize = sizeof(csbi);
if (has_csbiex)
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);

csbi.cbSize = sizeof(csbi);
csbi.srWindow.Right += 1;
csbi.srWindow.Bottom += 1;
csbi.ColorTable[g_color_index_bg] = (COLORREF)store_console_bg_rgb;
csbi.ColorTable[g_color_index_fg] = (COLORREF)store_console_fg_rgb;
if (has_csbiex)
pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
# endif
}

Expand All @@ -8043,19 +8001,17 @@ reset_console_color_rgb(void)
restore_console_color_rgb(void)
{
# ifdef FEAT_TERMGUICOLORS
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
CONSOLE_SCREEN_BUFFER_INFOEX csbi;

csbi.cbSize = sizeof(csbi);
if (has_csbiex)
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
GetConsoleScreenBufferInfoEx(g_hConOut, &csbi);

csbi.cbSize = sizeof(csbi);
csbi.srWindow.Right += 1;
csbi.srWindow.Bottom += 1;
csbi.ColorTable[g_color_index_bg] = (COLORREF)save_console_bg_rgb;
csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb;
if (has_csbiex)
pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
SetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
# endif
}

Expand Down

0 comments on commit c457685

Please sign in to comment.