A GetModuleHandle implementation

1.6k Views Asked by At

I need to do it this way because I am in DllMain() therefore, loader lock is held. I've read that GetModuleHandle() also uses the loader lock [page #6] which would result in deadlock.

How could GetModuleHandle() implemented? Some code would be a plus.

Update: Since I am using SetWindowsHookEx on WinXP only. Just going to take advice in the comments, go the easy way, and use GetModuleHandle() the first time the callback gets called.

1

There are 1 best solutions below

4
Sergey Podobry On BEST ANSWER

You can call GetModuleHandle from DllMain. It doesn't load any libraries and doesn't increment module reference count. Other story is with LoadLibrary. Never call it from DllMain.