|
| 1 | +#include "sqDSoundClassFactory.h" |
| 2 | +#include "sq.h" |
| 3 | +#include <tchar.h> |
| 4 | + |
| 5 | +#include "sqWin32DPRINTF.h" |
| 6 | + |
| 7 | +typedef HRESULT (CALLBACK * GETCLASSOBJECTPROC)(REFCLSID, REFIID, LPVOID *); |
| 8 | +static HMODULE hDSoundDLL = NULL; |
| 9 | +static GETCLASSOBJECTPROC fProc = NULL; |
| 10 | + |
| 11 | + |
| 12 | +int dsound_InitClassFactory() |
| 13 | +{ |
| 14 | + hDSoundDLL = LoadLibraryA("dsound.dll"); |
| 15 | + if (hDSoundDLL == NULL) { |
| 16 | + DPRINTF(("ERROR dsound_InitClassFactory(): cannot load 'dsound.dll'\n")); |
| 17 | + return 0; |
| 18 | + } |
| 19 | + if (fProc) { |
| 20 | + DPRINTF(("WARNING dsound_InitClassFactory(): 'fProc' already non-NULL\n")); |
| 21 | + } |
| 22 | + fProc = (GETCLASSOBJECTPROC)GetProcAddress(hDSoundDLL, "DllGetClassObject"); |
| 23 | + if (fProc == NULL) { |
| 24 | + DPRINTF(("ERROR dsound_InitClassFactory(): cannot load 'DllGetClassObject()'\n")); |
| 25 | + return 0; |
| 26 | + } |
| 27 | + return 1; |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +int |
| 32 | +dsound_ShutdownClassFactory() |
| 33 | +{ |
| 34 | + if (hDSoundDLL) |
| 35 | + FreeLibrary(hDSoundDLL); |
| 36 | + hDSoundDLL = NULL; |
| 37 | + fProc = NULL; |
| 38 | + return 1; |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +IClassFactory* dsound_GetClassFactory(REFCLSID classID) |
| 43 | +{ |
| 44 | + IClassFactory* factory; |
| 45 | + |
| 46 | + // For some reason, IID_IClassFactory isn't available to the cygwin linker (although |
| 47 | + // it compiles/links fine for MSVC). Instead, I manually construct the IID for |
| 48 | + // IClassFactory. |
| 49 | + //HRESULT hr = fProc(classID, IID_IClassFactory, (void**)&factory); |
| 50 | + IID iid = {NULL}; |
| 51 | + HRESULT hr = IIDFromString((LPOLESTR)(L"{00000001-0000-0000-C000-000000000046}"), &iid); |
| 52 | + if (FAILED(hr)) { |
| 53 | + DPRINTF(("ERROR dsound_GetClassFactory(): failed to initialize IID for IClassFactory\n")); |
| 54 | + return NULL; |
| 55 | + } |
| 56 | + hr = fProc(classID, iid, (void**)&factory); |
| 57 | + if (FAILED(hr)) { |
| 58 | + DPRINTF(("ERROR dsound_GetClassFactory(): failed to obtain class-factory\n")); |
| 59 | + return NULL; |
| 60 | + } |
| 61 | + return factory; |
| 62 | +} |
0 commit comments