3 #pragma warning(push,1) // disable warnings within system headers
11 IMPLEMENT_THUNK( psapi
, WINDOWS
, DWORD
, WINAPI
, GetModuleFileNameExA
, (HANDLE hProcess
, HMODULE hModule
, LPSTR lpFileName
, DWORD nSize
) )
13 DWORD dwProcessId
= 0;
16 if ( !hProcess
|| hProcess
== GetCurrentProcess() || GetCurrentProcessId() == (dwProcessId
= GetProcessId( hProcess
)) )
17 return GetModuleFileNameA( hModule
, lpFileName
, nSize
);
19 HANDLE hSnapshot
= CreateToolhelp32Snapshot( TH32CS_SNAPMODULE
, dwProcessId
);
21 if ( IsValidHandle( hSnapshot
) )
25 me
.dwSize
= sizeof(me
);
26 if ( Module32First( hSnapshot
, &me
) )
30 if ( NULL
== hModule
)
34 fFound
= (me
.hModule
== hModule
);
35 } while ( !fFound
&& Module32Next( hSnapshot
, &me
) );
39 dwResult
= _tcslen( me
.szExePath
);
41 if ( dwResult
> nSize
&& nSize
> 0 )
42 lpFileName
[nSize
-1] = 0;
44 _tcsncpy( lpFileName
, me
.szExePath
, nSize
);
48 CloseHandle( hSnapshot
);