diff options
author | Chris Robinson <[email protected]> | 2011-06-12 03:55:02 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-06-12 03:55:02 -0700 |
commit | 6bfab6427a40de60a7b4c12bce7cf1a687a33e2d (patch) | |
tree | eb714eebba23a074f871ec521b884a33d83d0081 | |
parent | aab4f853834e1ec7cef4c73f09442233f9677002 (diff) |
Avoid calling some function pointers directly
-rw-r--r-- | Alc/dsound.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/Alc/dsound.c b/Alc/dsound.c index 883b84e0..4280f508 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -47,10 +47,14 @@ DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); + static void *ds_handle; static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter); static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext); +#define DirectSoundCreate pDirectSoundCreate +#define DirectSoundEnumerateA pDirectSoundEnumerateA + typedef struct { // DirectSound Playback Device @@ -77,7 +81,8 @@ static void *DSoundLoad(void) { if(!ds_handle) { -#ifdef _WIN32 + ALboolean failed = AL_FALSE; + ds_handle = LoadLibraryA("dsound.dll"); if(ds_handle == NULL) { @@ -85,24 +90,21 @@ static void *DSoundLoad(void) return NULL; } -#define LOAD_FUNC(f) do { \ - p##f = (void*)GetProcAddress((HMODULE)ds_handle, #f); \ - if(p##f == NULL) \ - { \ - FreeLibrary(ds_handle); \ - ds_handle = NULL; \ - AL_PRINT("Could not load %s from dsound.dll\n", #f); \ - return NULL; \ - } \ +#define LOAD_FUNC(x) do { \ + if((p##x = (void*)GetProcAddress((HMODULE)ds_handle, #x)) == NULL) { \ + AL_PRINT("Could not load %s from dsound.dll\n", #x); \ + failed = AL_TRUE; \ + } \ } while(0) -#else - ds_handle = (void*)0xDEADBEEF; -#define LOAD_FUNC(f) p##f = f -#endif - -LOAD_FUNC(DirectSoundCreate); -LOAD_FUNC(DirectSoundEnumerateA); + LOAD_FUNC(DirectSoundCreate); + LOAD_FUNC(DirectSoundEnumerateA); #undef LOAD_FUNC + + if(failed) + { + FreeLibrary(ds_handle); + ds_handle = NULL; + } } return ds_handle; } @@ -275,7 +277,7 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam if(!DeviceList) { - hr = pDirectSoundEnumerateA(DSoundEnumDevices, NULL); + hr = DirectSoundEnumerateA(DSoundEnumDevices, NULL); if(FAILED(hr)) AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr); } @@ -302,7 +304,7 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam } //DirectSound Init code - hr = pDirectSoundCreate(guid, &pData->lpDS, NULL); + hr = DirectSoundCreate(guid, &pData->lpDS, NULL); if(SUCCEEDED(hr)) hr = IDirectSound_SetCooperativeLevel(pData->lpDS, GetForegroundWindow(), DSSCL_PRIORITY); if(FAILED(hr)) @@ -601,7 +603,7 @@ void alcDSoundProbe(int type) DeviceList = NULL; NumDevices = 0; - hr = pDirectSoundEnumerateA(DSoundEnumDevices, NULL); + hr = DirectSoundEnumerateA(DSoundEnumDevices, NULL); if(FAILED(hr)) AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr); else |