Updated dynamic library loading
This commit is contained in:
@@ -129,17 +129,92 @@ extern "C" {
|
|||||||
DWORD MouseButton;
|
DWORD MouseButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
static char dinput8_dll[] = {"dinput8.dll\0"};
|
||||||
extern HMODULE hM_dinput8, hM_ddraw, hM_dsound;
|
static char dinput8_imp[] = {"DirectInput8Create\0"};
|
||||||
|
|
||||||
|
static char ddraw_dll[] = {"ddraw.dll\0"};
|
||||||
|
static char ddraw_imp[] = {"DirectDrawCreateEx\0"};
|
||||||
|
|
||||||
|
static char dsound_dll[] = {"dsound.dll\0"};
|
||||||
|
static char dsound_imp[] = {"DirectSoundCreate8\0"};
|
||||||
|
|
||||||
|
static HMODULE hM_ddraw = NULL, hM_dsound = NULL,hM_dinput8 = NULL;
|
||||||
|
|
||||||
typedef HRESULT (WINAPI* lpDirectInput8Create)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter);
|
typedef HRESULT (WINAPI* lpDirectInput8Create)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter);
|
||||||
extern lpDirectInput8Create pDirectInput8Create;
|
static lpDirectInput8Create pDirectInput8Create;
|
||||||
|
|
||||||
typedef HRESULT (WINAPI* lpDirectDrawCreateEx)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter);
|
typedef HRESULT (WINAPI* lpDirectDrawCreateEx)( GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter );
|
||||||
extern lpDirectDrawCreateEx pDirectDrawCreateEx;
|
static lpDirectDrawCreateEx pDirectDrawCreateEx;
|
||||||
|
|
||||||
typedef HRESULT (WINAPI* lpDirectSoundCreate8)(LPCGUID pcGuidDevice, LPDIRECTSOUND8 *ppDS8, LPUNKNOWN pUnkOuter);
|
typedef HRESULT (WINAPI* lpDirectSoundCreate8)(LPCGUID pcGuidDevice, LPDIRECTSOUND8 *ppDS8, LPUNKNOWN pUnkOuter);
|
||||||
extern lpDirectSoundCreate8 pDirectSoundCreate8;
|
static lpDirectSoundCreate8 pDirectSoundCreate8;
|
||||||
|
|
||||||
|
extern "C" void ImportDirectX(void)
|
||||||
|
{
|
||||||
|
hM_dinput8 = LoadLibrary(dinput8_dll);
|
||||||
|
|
||||||
|
if (hM_dinput8 == NULL)
|
||||||
|
{
|
||||||
|
if (MessageBox(NULL, "Sorry, you need DirectX v8.0 or higher to use\nZSNESW. Would you like to go to the DirectX homepage?", "Error", MB_ICONINFORMATION | MB_YESNO) == IDYES)
|
||||||
|
ShellExecute(NULL, NULL, "http://www.microsoft.com/directx/", NULL, NULL, 0);
|
||||||
|
goto startup_error_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDirectInput8Create = (lpDirectInput8Create) GetProcAddress(hM_dinput8, dinput8_imp);
|
||||||
|
|
||||||
|
if (pDirectInput8Create == NULL)
|
||||||
|
{
|
||||||
|
char err[256];
|
||||||
|
wsprintf(err,"Failed to import %s:%s", dinput8_dll, dinput8_imp);
|
||||||
|
MessageBox(NULL, err, "Error", MB_ICONERROR);
|
||||||
|
goto startup_dinput8_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
hM_ddraw = LoadLibrary(ddraw_dll);
|
||||||
|
|
||||||
|
if (hM_ddraw == NULL)
|
||||||
|
{
|
||||||
|
char err[256];
|
||||||
|
wsprintf(err,"Failed to import %s",ddraw_dll);
|
||||||
|
MessageBox(NULL, err,"Error",MB_ICONERROR);
|
||||||
|
goto startup_dinput8_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDirectDrawCreateEx = (lpDirectDrawCreateEx) GetProcAddress(hM_ddraw, ddraw_imp);
|
||||||
|
|
||||||
|
if (pDirectDrawCreateEx == NULL)
|
||||||
|
{
|
||||||
|
char err[256];
|
||||||
|
wsprintf(err,"Failed to import %s:%s", ddraw_dll, ddraw_imp);
|
||||||
|
MessageBox(NULL, err, "Error", MB_ICONERROR);
|
||||||
|
goto startup_ddraw_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
hM_dsound = LoadLibrary(dsound_dll);
|
||||||
|
|
||||||
|
if (hM_dsound == NULL)
|
||||||
|
{
|
||||||
|
char err[256];
|
||||||
|
wsprintf(err,"Failed to import %s",dsound_dll);
|
||||||
|
MessageBox(NULL, err,"Error",MB_ICONERROR);
|
||||||
|
goto startup_ddraw_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDirectSoundCreate8 = (lpDirectSoundCreate8) GetProcAddress(hM_dsound, dsound_imp);
|
||||||
|
|
||||||
|
if (pDirectSoundCreate8 == NULL)
|
||||||
|
{
|
||||||
|
char err[256];
|
||||||
|
wsprintf(err,"Failed to import %s:%s", dsound_dll, dsound_imp);
|
||||||
|
MessageBox(NULL, err, "Error", MB_ICONERROR);
|
||||||
|
FreeLibrary(hM_dsound);
|
||||||
|
startup_ddraw_error:
|
||||||
|
FreeLibrary(hM_ddraw);
|
||||||
|
startup_dinput8_error:
|
||||||
|
FreeLibrary(hM_dinput8);
|
||||||
|
startup_error_exit:
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UPDATE_TICKS_GAME 1000.855001760297741789468390082/60 // milliseconds per world update
|
#define UPDATE_TICKS_GAME 1000.855001760297741789468390082/60 // milliseconds per world update
|
||||||
|
|||||||
Reference in New Issue
Block a user