[PATCH v2] winmm: Instanciate DirectInput8 class using CoCreateInstance.
Nikolay Sivov
nsivov at codeweavers.com
Fri Dec 17 09:31:40 CST 2021
On 12/17/21 17:24, Rémi Bernon wrote:
> -void joystick_load( HINSTANCE instance )
> +static BOOL WINAPI joystick_load( INIT_ONCE *once, void *param, void **context )
> {
> - HRESULT hr = DirectInput8Create( instance, DIRECTINPUT_VERSION, &IID_IDirectInput8W,
> - (void **)&dinput, NULL );
> - if (FAILED(hr)) WARN( "could not create dinput instance, hr %#x\n", hr );
> + HRESULT hr;
> +
> + CoInitialize( NULL );
> +
> + hr = CoCreateInstance( &CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInput8W,
> + (void **)&dinput );
> + if (FAILED(hr)) goto failed;
> +
> + hr = IDirectInput8_Initialize( dinput, hWinMM32Instance, DIRECTINPUT_VERSION );
> + if (FAILED(hr)) goto failed;
> +
> + return TRUE;
> +
> +failed:
> + if (dinput) IDirectInput8_Release( dinput );
> + dinput = NULL;
> +
> + WARN( "Could not create dinput instance, hr %#x\n", hr );
> + CoUninitialize();
> + return FALSE;
> }
I don't think it's safe to initialize/uninitialize like that. For
example if application already initialized with multithreaded mode.
More information about the wine-devel
mailing list