-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
87 lines (69 loc) · 1.63 KB
/
util.cpp
File metadata and controls
87 lines (69 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// util.cpp
//
// Various utility routines
#include "stdafx.h"
extern BOOL g_fDebug;
VOID DebugOut(
__in const WCHAR *pwszFormat,
...
)
{
va_list args;
if( g_fDebug )
{
va_start( args, pwszFormat );
vfwprintf( stderr, pwszFormat, args );
va_end( args );
}
}
HRESULT GetLastFailureAsHRESULT()
{
HRESULT hr = S_OK;
DWORD dwResult = ERROR_SUCCESS;
dwResult = ::GetLastError();
hr = HRESULT_FROM_WIN32( dwResult );
if ( SUCCEEDED( hr ) )
{
hr = E_FAIL;
}
return hr;
}
BOOL
GetProcessImageName(
__in HWND hwnd,
__out_ecount(cchImage) WCHAR *pwszImage,
__in DWORD cchImage
)
{
BOOL fResult = FALSE;
HANDLE hProcess = NULL;
DWORD dwProcessId = 0;
DWORD dwThreadId = 0;
DWORD cchTemp = 0;
dwThreadId = GetWindowThreadProcessId( hwnd, &dwProcessId );
hProcess = OpenProcess( PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId );
if( hProcess == NULL )
{
DebugOut( L"Failed OpenProcess for hwnd %p with %d\n", hwnd, GetLastError() );
goto Exit;
}
cchTemp = cchImage;
if( !QueryFullProcessImageNameW( hProcess, 0, pwszImage, &cchTemp ) )
{
DebugOut( L"Failed QueryFullProcessImageNameW for hwnd %p with %d\n", hwnd, GetLastError() );
goto Exit;
}
if( cchTemp >= (cchImage - 1) )
{
goto Exit;
}
pwszImage[cchTemp] = 0;
fResult = TRUE;
Exit:
if( hProcess != INVALID_HANDLE_VALUE )
{
CloseHandle( hProcess );
hProcess = INVALID_HANDLE_VALUE;
}
return fResult;
}