Skip to content

Commit

Permalink
Fix the detection of targets that use the GUI subsystem (71#6)
Browse files Browse the repository at this point in the history
* Fix the detection of targets that use the GUI subsystem

* Allocate path on the stack
  • Loading branch information
pfmoore committed Aug 7, 2022
1 parent 99f7f73 commit ea09917
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion shim.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <corecrt_wstdio.h>
#pragma comment(lib, "SHELL32.LIB")
#pragma comment(lib, "SHLWAPI.LIB")
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>

#include <string>
Expand Down Expand Up @@ -213,8 +215,19 @@ int wmain(int argc, wchar_t* argv[])
}

// Find out if the target program is a console app

wchar_t unquotedPath[MAX_PATH] = {};
wmemcpy(unquotedPath, path->c_str(), path->length());
PathUnquoteSpacesW(unquotedPath);
SHFILEINFOW sfi = {};
const auto isWindowsApp = HIWORD(SHGetFileInfoW(path->c_str(), -1, &sfi, sizeof(sfi), SHGFI_EXETYPE)) != 0;
const auto ret = SHGetFileInfoW(unquotedPath, -1, &sfi, sizeof(sfi), SHGFI_EXETYPE);

if (ret == 0)
{
fprintf(stderr, "Could not determine if target is a GUI app. Assuming console.\n");
}

const auto isWindowsApp = HIWORD(ret) != 0;

if (isWindowsApp)
{
Expand Down

0 comments on commit ea09917

Please sign in to comment.