Commit 03e4ea17 authored by Alexandre Julliard's avatar Alexandre Julliard

Make GetModuleFileNameA call GetModuleFileNameW. Small cleanups.

parent c85f61b1
...@@ -50,6 +50,14 @@ WINE_MODREF *MODULE_modref_list = NULL; ...@@ -50,6 +50,14 @@ WINE_MODREF *MODULE_modref_list = NULL;
WINE_MODREF *exe_modref; WINE_MODREF *exe_modref;
int process_detaching = 0; /* set on process detach to avoid deadlocks with thread detach */ int process_detaching = 0; /* set on process detach to avoid deadlocks with thread detach */
inline static HMODULE get_exe_module(void)
{
HMODULE mod;
/* FIXME: should look into PEB */
LdrGetDllHandle( 0, 0, NULL, &mod );
return mod;
}
/*********************************************************************** /***********************************************************************
* wait_input_idle * wait_input_idle
* *
...@@ -922,46 +930,24 @@ DWORD WINAPI GetModuleFileNameA( ...@@ -922,46 +930,24 @@ DWORD WINAPI GetModuleFileNameA(
LPSTR lpFileName, /* [out] filenamebuffer */ LPSTR lpFileName, /* [out] filenamebuffer */
DWORD size ) /* [in] size of filenamebuffer */ DWORD size ) /* [in] size of filenamebuffer */
{ {
DWORD len = 0; LPWSTR filenameW = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
lpFileName[0] = 0; if (!filenameW)
RtlEnterCriticalSection( &loader_section );
if (!hModule && !(NtCurrentTeb()->tibflags & TEBF_WIN32))
{ {
/* 16-bit task - get current NE module name */ SetLastError( ERROR_NOT_ENOUGH_MEMORY );
NE_MODULE *pModule = NE_GetPtr( GetCurrentTask() ); return 0;
if (pModule) len = GetLongPathNameA(NE_MODULE_NAME(pModule), lpFileName, size);
}
else if (hModule || LdrGetDllHandle( 0, 0, NULL, &hModule ) == STATUS_SUCCESS)
{
LDR_MODULE* pldr;
NTSTATUS nts;
nts = LdrFindEntryForAddress( hModule, &pldr );
if (nts == STATUS_SUCCESS)
{
WideCharToMultiByte( CP_ACP, 0,
pldr->FullDllName.Buffer, pldr->FullDllName.Length,
lpFileName, size, NULL, NULL );
len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
}
else SetLastError( RtlNtStatusToDosError( nts ) );
} }
RtlLeaveCriticalSection( &loader_section ); GetModuleFileNameW( hModule, filenameW, size );
WideCharToMultiByte( CP_ACP, 0, filenameW, -1, lpFileName, size, NULL, NULL );
TRACE( "%s\n", debugstr_an(lpFileName, len) ); HeapFree( GetProcessHeap(), 0, filenameW );
return len; return strlen( lpFileName );
} }
/*********************************************************************** /***********************************************************************
* GetModuleFileNameW (KERNEL32.@) * GetModuleFileNameW (KERNEL32.@)
*/ */
DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size ) DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size )
{ {
DWORD len = 0;
lpFileName[0] = 0; lpFileName[0] = 0;
RtlEnterCriticalSection( &loader_section ); RtlEnterCriticalSection( &loader_section );
...@@ -973,30 +959,25 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size ...@@ -973,30 +959,25 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size
{ {
WCHAR path[MAX_PATH]; WCHAR path[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, NE_MODULE_NAME(pModule), -1, MultiByteToWideChar( CP_ACP, 0, NE_MODULE_NAME(pModule), -1, path, MAX_PATH );
path, MAX_PATH ); GetLongPathNameW(path, lpFileName, size);
len = GetLongPathNameW(path, lpFileName, size);
} }
} }
else if (hModule || LdrGetDllHandle( 0, 0, NULL, &hModule ) == STATUS_SUCCESS) else
{ {
LDR_MODULE* pldr; LDR_MODULE* pldr;
NTSTATUS nts; NTSTATUS nts;
if (!hModule) hModule = get_exe_module();
nts = LdrFindEntryForAddress( hModule, &pldr ); nts = LdrFindEntryForAddress( hModule, &pldr );
if (nts == STATUS_SUCCESS) if (nts == STATUS_SUCCESS) lstrcpynW(lpFileName, pldr->FullDllName.Buffer, size);
{
len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
strncpyW(lpFileName, pldr->FullDllName.Buffer, len);
if (len < size) lpFileName[len] = 0;
}
else SetLastError( RtlNtStatusToDosError( nts ) ); else SetLastError( RtlNtStatusToDosError( nts ) );
} }
RtlLeaveCriticalSection( &loader_section ); RtlLeaveCriticalSection( &loader_section );
TRACE( "%s\n", debugstr_wn(lpFileName, len) ); TRACE( "%s\n", debugstr_w(lpFileName) );
return len; return strlenW(lpFileName);
} }
/****************************************************************** /******************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment