7030249: Eliminate use of LoadLibrary and other clean-ups
Dmytro Sheyko
dmytro_sheyko at hotmail.com
Tue Mar 29 16:55:33 UTC 2011
Maybe we should follow this approach (i.e. prefer GetModuleHandleEx to GetModuleHandle) in other places as well.
I found there suspect cases:
./jdk/src/windows/native/java/lang/java_props_md.c: GetModuleHandle(TEXT("kernel32.dll")),
./jdk/test/java/util/Locale/data/deflocale.c: HMODULE hmod = GetModuleHandle(L"kernel32");
./hotspot/src/os/windows/vm/perfMemory_windows.cpp: GetProcAddress(GetModuleHandle(TEXT("advapi32.dll")),
./hotspot/src/os/windows/vm/os_windows.cpp: hmod = GetModuleHandle("NTDLL.DLL");
./hotspot/src/os/windows/vm/os_windows.cpp: HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
./hotspot/src/os/windows/vm/os_windows.cpp: HINSTANCE kernel32 = LoadLibrary("Kernel32.DLL") ;
./hotspot/src/os/windows/vm/os_windows.cpp: HINSTANCE psapi = LoadLibrary( "PSAPI.DLL" ) ;
Regards,
Dmytro
Date: Tue, 29 Mar 2011 16:49:50 +0100
From: Alan.Bateman at oracle.com
To: dmytro_sheyko at hotmail.com
CC: core-libs-dev at openjdk.java.net
Subject: Re: 7030249: Eliminate use of LoadLibrary and other clean-ups
Message body
Dmytro Sheyko wrote:
:
Why we obtain HMODULE for kernel32 this way:
// get handle to kernel32
if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT),
(LPCWSTR)&CreateFileW, &h) != 0)
{
...
instead of
handle = GetModuleHandle("kernel32");
GetModuleHandleExW allows you to provide the address of a function in
the library that you need the handle for and so you avoid issues when
multiple libraries with the same name are loaded.
:
Also according to MSDN GetModuleHandleEx requires at minimum "Windows
XP" or "Windows Server 2003". It means that we do not support "Windows
2000", right?
I don't think it's been possible to install or run jdk7 on Windows 2000
for some time.
-Alan
More information about the core-libs-dev
mailing list