From: Dr. Doodle on 2 Nov 2009 13:03 Hi, I've been reading some codes other people wrote at my work. One of the interesting thing I found was that when calling SetThreadPreferredUILanguages() and some other functions (kernel32.dll exported functions), the code first loadlibrary'es the kernel32.dll, gets a function pointer to the function of interest, and then calls it. Why don't it just call ::SetThreadPreferredUILanguages() and then let the dll be loaded automatically? I am just trying to understand the benefit/reason of calling the loadlibrary function explicitly before making a call to one of its functions. I'd appreciate for any clarification. Thanks
From: Preben Friis on 2 Nov 2009 14:02 It must be implemented that way for backwards compatibility reasons. SetThreadPreferredUILanguages() was added to kernel32 in Windows Vista. If you were to link directly to that function, your program would not be able to be launched on Windows XP. Loading the library, looking up the address makes it possible to fail gracefully and ignore that the function is not present. "Dr. Doodle" <donglee0(a)gmail.com> wrote: > I am just trying to understand the benefit/reason of calling the > loadlibrary function explicitly before making a call to one of its > functions. I'd appreciate for any clarification.
From: Dr. Doodle on 2 Nov 2009 15:37 Preben, that makes perfect sense. Thank you for your help!
From: Richard Russell on 2 Nov 2009 17:16 On Nov 2, 6:03 pm, "Dr. Doodle" <dongl...(a)gmail.com> wrote: > the code first loadlibrary'es the kernel32.dll I thought kernel32.dll was mapped into the address space of *every* process, so wouldn't it be OK to use GetModuleHandle("kernel32.dll") rather than LoadLibrary("kernel32.dll")? Is there any advantage in doing one rather than the other? Richard. http://www.rtrussell.co.uk/ To reply by email change 'news' to my forename.
|
Pages: 1 Prev: [ANN] Idle Scripting Language 1.0 Next: Windows 7 Test drive or emulator |