"Maarten Lankhorst" m.b.lankhorst@gmail.com wrote:
Seems native directsound keeps itself loaded by calling LoadLibrary when attaching. A simple testcase I wrote confirms that at least for xp, by not crashing.
After seeing this, I decided to write my own test, and can confirm now that this patch looks correct: after a successful LoadLibrary("dsound.dll") FreeLibrary needs to be called 2 times before it starts to return FALSE.
Just for fun I tested other dlls as well (GetModuleHandle returns 0 for all of them before the LoadLibrary call): user32 requires 4 FreeLibrary calls after LoadLibrary, dinput - 1, mfc42 - 1, advapi32 - 1, comctl32 - 1.
I'm attaching the program I used for testing.
GetModuleFileNameW(hInstDLL, modname, sizeof(modname)/sizeof(*modname));
LoadLibraryW(modname);
Probably simple LoadLibrary("dsound.dll") should be enough.
Dmitry Timoshkov schreef:
"Maarten Lankhorst" m.b.lankhorst@gmail.com wrote:
Seems native directsound keeps itself loaded by calling LoadLibrary when attaching. A simple testcase I wrote confirms that at least for xp, by not crashing.
After seeing this, I decided to write my own test, and can confirm now that this patch looks correct: after a successful LoadLibrary("dsound.dll") FreeLibrary needs to be called 2 times before it starts to return FALSE.
Just for fun I tested other dlls as well (GetModuleHandle returns 0 for all of them before the LoadLibrary call): user32 requires 4 FreeLibrary calls after LoadLibrary, dinput - 1, mfc42 - 1, advapi32 - 1, comctl32 - 1.
I'm attaching the program I used for testing.
GetModuleFileNameW(hInstDLL, modname,
sizeof(modname)/sizeof(*modname));
LoadLibraryW(modname);
Probably simple LoadLibrary("dsound.dll") should be enough.
I want to be able to rename the dll without having to worry about that line. That's why I'm getting the full file name. Easier to run tests that way.
It gets even more fun in another part:
If you load a dll at link time, then also load it with loadlibrary, you can call freelibrary as many times on it as you like, it won't unload. However in wine it will... potentially causing crashes for badly written programs.
Maarten Lankhorst m.b.lankhorst@gmail.com writes:
I want to be able to rename the dll without having to worry about that line. That's why I'm getting the full file name. Easier to run tests that way.
You should use GetModuleHandleEx to increment the refcount directly from the module handle.