dinput: in DirectInputCreateh(), NULL hInst should return DIERR_INVALIDPARAM

Austin English austinenglish at gmail.com
Thu Oct 1 15:33:18 CDT 2009


See bug 15336. Tested on XP SP3/Wine.

-- 
-Austin
-------------- next part --------------
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
old mode 100644
new mode 100755
index 9769d74..fa4bb27
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -115,6 +115,10 @@ HRESULT WINAPI DirectInputCreateEx(
 
     TRACE("(%p,%04x,%s,%p,%p)\n", hinst, dwVersion, debugstr_guid(riid), ppDI, punkOuter);
 
+    if (!hinst)
+        return DIERR_INVALIDPARAM;
+
+
     if (IsEqualGUID( &IID_IUnknown,       riid ) ||
         IsEqualGUID( &IID_IDirectInputA,  riid ) ||
         IsEqualGUID( &IID_IDirectInput2A, riid ) ||
diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c
old mode 100644
new mode 100755
index 83c18f1..85608fc
--- a/dlls/dinput/tests/device.c
+++ b/dlls/dinput/tests/device.c
@@ -146,6 +146,15 @@ static void device_tests(void)
     HWND hwnd;
     struct enum_data data;
 
+    /* Check that DirectInputCreate with null hInstance fails. */
+    hr = DirectInputCreate(NULL, DIRECTINPUT_VERSION, &pDI, NULL);
+    ok(hr == DIERR_INVALIDPARAM, "DirectInputCreate() failed. Expected DIERR_INVALIDPARAM, got %08x\n", hr);
+    if (SUCCEEDED(hr) && pDI)
+    {
+        IUnknown_Release(pDI);
+        pDI = NULL;
+    }
+
     hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
     if (hr == DIERR_OLDDIRECTINPUTVERSION)
     {
diff --git a/dlls/dinput/tests/joystick.c b/dlls/dinput/tests/joystick.c
old mode 100644
new mode 100755
index aad8049..491510b
--- a/dlls/dinput/tests/joystick.c
+++ b/dlls/dinput/tests/joystick.c
@@ -613,6 +613,15 @@ static void joystick_tests(DWORD version)
     ULONG ref;
     HINSTANCE hInstance = GetModuleHandle(NULL);
 
+    /* Check that DirectInputCreate with null hInstance fails. */
+    hr = DirectInputCreate(NULL, DIRECTINPUT_VERSION, &pDI, NULL);
+    ok(hr == DIERR_INVALIDPARAM, "DirectInputCreate() failed. Expected DIERR_INVALIDPARAM, got %08x\n", hr);
+    if (SUCCEEDED(hr) && pDI)
+    {
+        IUnknown_Release(pDI);
+        pDI = NULL;
+    }
+
     trace("-- Testing Direct Input Version 0x%04x --\n", version);
     hr = DirectInputCreate(hInstance, version, &pDI, NULL);
     ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION,
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
old mode 100644
new mode 100755
index 2d4a12f..efdd395
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -138,6 +138,15 @@ static void keyboard_tests(DWORD version)
     HWND hwnd;
     ULONG ref = 0;
 
+    /* Check that DirectInputCreate with null hInstance fails. */
+    hr = DirectInputCreate(NULL, DIRECTINPUT_VERSION, &pDI, NULL);
+    ok(hr == DIERR_INVALIDPARAM, "DirectInputCreate() failed. Expected DIERR_INVALIDPARAM, got %08x\n", hr);
+    if (SUCCEEDED(hr) && pDI)
+    {
+        IUnknown_Release(pDI);
+        pDI = NULL;
+    }
+
     hr = DirectInputCreate(hInstance, version, &pDI, NULL);
     if (hr == DIERR_OLDDIRECTINPUTVERSION)
     {
diff --git a/dlls/dinput/tests/mouse.c b/dlls/dinput/tests/mouse.c
old mode 100644
new mode 100755
index 520a867..a8ab4ee
--- a/dlls/dinput/tests/mouse.c
+++ b/dlls/dinput/tests/mouse.c
@@ -115,6 +115,15 @@ static void mouse_tests(void)
     HWND hwnd;
     ULONG ref = 0;
 
+    /* Check that DirectInputCreate with null hInstance fails. */
+    hr = DirectInputCreate(NULL, DIRECTINPUT_VERSION, &pDI, NULL);
+    ok(hr == DIERR_INVALIDPARAM, "DirectInputCreate() failed. Expected DIERR_INVALIDPARAM, got %08x\n", hr);
+    if (SUCCEEDED(hr) && pDI)
+    {
+        IUnknown_Release(pDI);
+        pDI = NULL;
+    }
+
     hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
     if (hr == DIERR_OLDDIRECTINPUTVERSION)
     {


More information about the wine-patches mailing list