mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
Run code cleanup
This commit is contained in:
@@ -38,67 +38,67 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
{
|
||||
// do not run when double-clicking
|
||||
if (wcsstr(GetCommandLine(), RUN_ARG) == nullptr)
|
||||
{
|
||||
MessageBox(nullptr, L"This executable is not designed to launch directly.", L"QuickLook.WoW64HookHelper", 0);
|
||||
return 0;
|
||||
}
|
||||
// do not run when double-clicking
|
||||
if (wcsstr(GetCommandLine(), RUN_ARG) == nullptr)
|
||||
{
|
||||
MessageBox(nullptr, L"This executable is not designed to launch directly.", L"QuickLook.WoW64HookHelper", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pDll = LoadLibrary(L"QuickLook.Native32.dll");
|
||||
pGCS = reinterpret_cast<PGCS>(GetProcAddress(pDll, "GetCurrentSelection"));
|
||||
pDll = LoadLibrary(L"QuickLook.Native32.dll");
|
||||
pGCS = reinterpret_cast<PGCS>(GetProcAddress(pDll, "GetCurrentSelection"));
|
||||
|
||||
WM_HOOK_NOTIFY = RegisterWindowMessage(L"WM_QUICKLOOK_HOOK_NOTIFY_MSG");
|
||||
WM_HOOK_NOTIFY = RegisterWindowMessage(L"WM_QUICKLOOK_HOOK_NOTIFY_MSG");
|
||||
|
||||
WNDCLASS wc = {};
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.lpszClassName = MSG_WINDOW_CLASS;
|
||||
if (!RegisterClass(&wc))
|
||||
return 0;
|
||||
WNDCLASS wc = {};
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.lpszClassName = MSG_WINDOW_CLASS;
|
||||
if (!RegisterClass(&wc))
|
||||
return 0;
|
||||
|
||||
hMsgWindow = CreateWindow(MSG_WINDOW_CLASS, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
|
||||
if (hMsgWindow == nullptr)
|
||||
return 0;
|
||||
hMsgWindow = CreateWindow(MSG_WINDOW_CLASS, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
|
||||
if (hMsgWindow == nullptr)
|
||||
return 0;
|
||||
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0) > 0)
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return msg.wParam;
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0) > 0)
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (msg == WM_HOOK_NOTIFY)
|
||||
{
|
||||
GetCurrentSelection();
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
if (msg == WM_HOOK_NOTIFY)
|
||||
{
|
||||
GetCurrentSelection();
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
void GetCurrentSelection()
|
||||
{
|
||||
// This function runs inside the target process. Some of them may already support Long Path.
|
||||
// Therefore, we must assume all of them support Long Path to avoid buffer overflow.
|
||||
WCHAR dllBuffer[MAX_PATH_EX] = {'\0'};
|
||||
pGCS(dllBuffer);
|
||||
// This function runs inside the target process. Some of them may already support Long Path.
|
||||
// Therefore, we must assume all of them support Long Path to avoid buffer overflow.
|
||||
WCHAR dllBuffer[MAX_PATH_EX] = {'\0'};
|
||||
pGCS(dllBuffer);
|
||||
|
||||
auto hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, SHARED_MEM_NAME);
|
||||
if (hMapFile == nullptr)
|
||||
return;
|
||||
auto hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, SHARED_MEM_NAME);
|
||||
if (hMapFile == nullptr)
|
||||
return;
|
||||
|
||||
auto buffer = static_cast<PWCHAR>(MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0));
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
CloseHandle(hMapFile);
|
||||
return;
|
||||
}
|
||||
auto buffer = static_cast<PWCHAR>(MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0));
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
CloseHandle(hMapFile);
|
||||
return;
|
||||
}
|
||||
|
||||
wcscpy_s(buffer, wcslen(dllBuffer) + 1, dllBuffer);
|
||||
wcscpy_s(buffer, wcslen(dllBuffer) + 1, dllBuffer);
|
||||
|
||||
UnmapViewOfFile(buffer);
|
||||
CloseHandle(hMapFile);
|
||||
UnmapViewOfFile(buffer);
|
||||
CloseHandle(hMapFile);
|
||||
}
|
||||
|
Reference in New Issue
Block a user