"Maarten Lankhorst" <[EMAIL PROTECTED]> 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.
#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
   LONG ref_count;
   HANDLE hLib;

   if(argc != 2)
   {
       printf("Syntax: loaddll.exe library.dll\n");
       return -1;
   }

   hLib = GetModuleHandle(argv[1]);
   printf("existing module %s handle is %p\n", argv[1], hLib);

   printf("Loading %s...", argv[1]);

   hLib = LoadLibrary(argv[1]);

   if (hLib)
   {
       printf("\nLibrary loaded successfully. hLib = %p\n", hLib);

       ref_count = 0;
       while (FreeLibrary(hLib)) ref_count++;
       printf("ref count = %d\n", ref_count);
   }
   else
       printf("\nLoadLibrary() failed. Error %u\n", GetLastError());

   return 0;
}


Reply via email to