2019-05-03 00:29:04 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
#include "OneCoreDelay.hpp"
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOLEAN __stdcall OneCoreDelay::IsIsWindowPresent()
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
#ifdef __INSIDE_WINDOWS
|
|
|
|
return ::IsIsWindowPresent();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOLEAN __stdcall OneCoreDelay::IsGetSystemMetricsPresent()
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
#ifdef __INSIDE_WINDOWS
|
|
|
|
return ::IsGetSystemMetricsPresent();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOLEAN __stdcall OneCoreDelay::IsPostMessageWPresent()
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
#ifdef __INSIDE_WINDOWS
|
|
|
|
return ::IsPostMessageWPresent();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOLEAN __stdcall OneCoreDelay::IsSendMessageWPresent()
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
#ifdef __INSIDE_WINDOWS
|
|
|
|
return ::IsSendMessageWPresent();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
HMODULE GetUser32()
|
|
|
|
{
|
|
|
|
static HMODULE _hUser32 = nullptr;
|
|
|
|
if (_hUser32 == nullptr)
|
|
|
|
{
|
|
|
|
_hUser32 = LoadLibraryExW(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return _hUser32;
|
|
|
|
}
|
|
|
|
|
|
|
|
HMODULE GetKernel32()
|
|
|
|
{
|
|
|
|
static HMODULE _hKernel32 = nullptr;
|
|
|
|
if (_hKernel32 == nullptr)
|
|
|
|
{
|
|
|
|
_hKernel32 = LoadLibraryExW(L"kernel32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return _hKernel32;
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOL APIENTRY OneCoreDelay::AddConsoleAliasA(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ LPSTR Source,
|
|
|
|
_In_ LPSTR Target,
|
|
|
|
_In_ LPSTR ExeName)
|
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnAddConsoleAliasA)(LPSTR Source, LPSTR Target, LPSTR ExeName);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnAddConsoleAliasA pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnAddConsoleAliasA)GetProcAddress(h, "AddConsoleAliasA");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(Source, Target, ExeName);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOL APIENTRY OneCoreDelay::AddConsoleAliasW(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ LPWSTR Source,
|
|
|
|
_In_ LPWSTR Target,
|
|
|
|
_In_ LPWSTR ExeName)
|
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnAddConsoleAliasW)(LPWSTR Source, LPWSTR Target, LPWSTR ExeName);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnAddConsoleAliasW pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnAddConsoleAliasW)GetProcAddress(h, "AddConsoleAliasW");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(Source, Target, ExeName);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
DWORD APIENTRY OneCoreDelay::GetConsoleAliasA(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ LPSTR Source,
|
|
|
|
_Out_writes_(TargetBufferLength) LPSTR TargetBuffer,
|
|
|
|
_In_ DWORD TargetBufferLength,
|
|
|
|
_In_ LPSTR ExeName)
|
2019-06-11 22:27:09 +02:00
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnGetConsoleAliasA)(LPSTR Source, LPSTR TargetBuffer, DWORD TargetBufferLength, LPSTR ExeName);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetConsoleAliasA pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetConsoleAliasA)GetProcAddress(h, "GetConsoleAliasA");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(Source, TargetBuffer, TargetBufferLength, ExeName);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
2019-06-11 22:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD APIENTRY OneCoreDelay::GetConsoleAliasW(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ LPWSTR Source,
|
|
|
|
_Out_writes_(TargetBufferLength) LPWSTR TargetBuffer,
|
|
|
|
_In_ DWORD TargetBufferLength,
|
|
|
|
_In_ LPWSTR ExeName)
|
2019-06-11 22:27:09 +02:00
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnGetConsoleAliasW)(LPWSTR Source, LPWSTR TargetBuffer, DWORD TargetBufferLength, LPWSTR ExeName);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetConsoleAliasW pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetConsoleAliasW)GetProcAddress(h, "GetConsoleAliasW");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(Source, TargetBuffer, TargetBufferLength, ExeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI OneCoreDelay::GetCurrentConsoleFont(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ HANDLE hConsoleOutput,
|
|
|
|
_In_ BOOL bMaximumWindow,
|
2019-06-11 22:27:09 +02:00
|
|
|
_Out_ PCONSOLE_FONT_INFO lpConsoleCurrentFont)
|
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnGetCurrentConsoleFont)(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFO lpConsoleCurrentFont);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetCurrentConsoleFont pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetCurrentConsoleFont)GetProcAddress(h, "GetCurrentConsoleFont");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
2019-06-11 22:27:09 +02:00
|
|
|
}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOL WINAPI OneCoreDelay::GetCurrentConsoleFontEx(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ HANDLE hConsoleOutput,
|
|
|
|
_In_ BOOL bMaximumWindow,
|
|
|
|
_Out_ PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx)
|
2019-06-11 22:27:09 +02:00
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnGetCurrentConsoleFontEx)(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetCurrentConsoleFontEx pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetCurrentConsoleFontEx)GetProcAddress(h, "GetCurrentConsoleFontEx");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
2019-06-11 22:27:09 +02:00
|
|
|
}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
BOOL WINAPI OneCoreDelay::SetCurrentConsoleFontEx(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ HANDLE hConsoleOutput,
|
|
|
|
_In_ BOOL bMaximumWindow,
|
|
|
|
_In_ PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx)
|
2019-06-11 22:27:09 +02:00
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnSetCurrentConsoleFontEx)(HANDLE hConsoleOutput, BOOL bMaximumWindow, PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnSetCurrentConsoleFontEx pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnSetCurrentConsoleFontEx)GetProcAddress(h, "SetCurrentConsoleFontEx");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
2019-06-11 22:27:09 +02:00
|
|
|
}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
COORD WINAPI OneCoreDelay::GetConsoleFontSize(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ HANDLE hConsoleOutput,
|
2019-06-11 22:27:09 +02:00
|
|
|
_In_ DWORD nFont)
|
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef COORD(WINAPI * PfnGetConsoleFontSize)(HANDLE hConsoleOutput, DWORD nFont);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetConsoleFontSize pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetConsoleFontSize)GetProcAddress(h, "GetConsoleFontSize");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(hConsoleOutput, nFont);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
|
|
|
return { 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI OneCoreDelay::GetNumberOfConsoleMouseButtons(
|
|
|
|
_Out_ LPDWORD lpNumberOfMouseButtons)
|
|
|
|
{
|
|
|
|
HMODULE h = GetKernel32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef BOOL(WINAPI * PfnGetNumberOfConsoleMouseButtons)(LPDWORD lpNumberOfMouseButtons);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetNumberOfConsoleMouseButtons pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetNumberOfConsoleMouseButtons)GetProcAddress(h, "GetNumberOfConsoleMouseButtons");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(lpNumberOfMouseButtons);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return FALSE;
|
2019-06-11 22:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HMENU WINAPI OneCoreDelay::GetMenu(
|
2019-05-03 00:29:04 +02:00
|
|
|
_In_ HWND hWnd)
|
2019-06-11 22:27:09 +02:00
|
|
|
{
|
|
|
|
HMODULE h = GetUser32();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (h != nullptr)
|
|
|
|
{
|
2019-06-11 22:27:09 +02:00
|
|
|
typedef HMENU(WINAPI * PfnGetMenu)(HWND hWnd);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
static PfnGetMenu pfn = nullptr;
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn == nullptr)
|
|
|
|
{
|
|
|
|
pfn = (PfnGetMenu)GetProcAddress(h, "GetMenu");
|
|
|
|
}
|
2019-06-11 22:27:09 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
if (pfn != nullptr)
|
|
|
|
{
|
|
|
|
return pfn(hWnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|