MCPcopy Create free account
hub / github.com/OpenKneeboard/OpenKneeboard / GetFullPathForCurrentExecutable

Function GetFullPathForCurrentExecutable

src/lib/tracing.cpp:20–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18namespace OpenKneeboard {
19
20wchar_t* GetFullPathForCurrentExecutable() {
21 static std::once_flag sOnce;
22 // `QueryFullProcessImageNameW()` requires us to provide a size; it doesn't
23 // support the usual 'pass a nullptr and get the size back, then call again'
24 // thing.
25 static wchar_t sBuffer[MAX_PATH] {};
26
27 std::call_once(sOnce, [&buffer = sBuffer]() {
28 memset(buffer, 0, std::size(buffer) * sizeof(buffer[0]));
29 // `QueryFullProcessImageNameW()` requires a real handle,
30 // not the pseudo-handle returned by `GetCurrentProcess()`.
31 winrt::handle process {OpenProcess(
32 PROCESS_QUERY_LIMITED_INFORMATION, false, GetCurrentProcessId())};
33 if (!process) {
34 dprint(
35 "OpenProcess(..., GetCurrentProcessID()) failed: {} @ {}",
36 GetLastError(),
37 std::source_location::current());
38 return;
39 }
40 auto characterCount = static_cast<DWORD>(std::size(buffer));
41 const auto result
42 = QueryFullProcessImageNameW(process.get(), 0, buffer, &characterCount);
43 if (result == 0) {
44 dprint(
45 "QueryFullProcessImageNameW() returned {}, failed with {:#018x} @ {}",
46 result,
47 GetLastError(),
48 std::source_location::current());
49 }
50 });
51 return sBuffer;
52}
53
54}// namespace OpenKneeboard

Callers 2

InjectedDLLMainFunction · 0.85
LogSystemInformationFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected