Rémi Bernon (@rbernon) commented about dlls/windows.media.playback.mediaplayer/main.c:
- HSTRING str = NULL;
- HRESULT hr;
- FIXME( "shell integration not implemented.\n" );
- if (!(*window = CreateWindowExA( 0, "static", NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandleA( NULL ), NULL ))) return HRESULT_FROM_WIN32( GetLastError() );
- if (FAILED(hr = WindowsCreateString( media_control_statics_name, wcslen( media_control_statics_name ), &str ))) return hr;
- if (SUCCEEDED(hr)) hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
- if (SUCCEEDED(hr)) hr = IActivationFactory_QueryInterface( factory, &IID_ISystemMediaTransportControlsInterop, (void **)&media_control_interop_statics );
- if (SUCCEEDED(hr)) hr = ISystemMediaTransportControlsInterop_GetForWindow( media_control_interop_statics, *window, &IID_ISystemMediaTransportControls, (void **)controls );
- if (media_control_interop_statics) ISystemMediaTransportControlsInterop_Release( media_control_interop_statics );
- if (factory) IActivationFactory_Release( factory );
- WindowsDeleteString( str );
- return hr;
In general it is better for any function to either succeed, or fail completely without anything for the caller to cleanup. This should destroy the window on failure if it was created:
```suggestion:-10+0 HWND hwnd;
if (!(hwnd = CreateWindowExW( 0, L"static", NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandleA( NULL ), NULL ))) return HRESULT_FROM_WIN32( GetLastError() );
if (FAILED(hr = WindowsCreateString( media_control_statics_name, wcslen( media_control_statics_name ), &str ))) goto done; if (SUCCEEDED(hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ))) { hr = IActivationFactory_QueryInterface( factory, &IID_ISystemMediaTransportControlsInterop, (void **)&media_control_interop_statics ); IActivationFactory_Release( factory ); } if (SUCCEEDED(hr)) { hr = ISystemMediaTransportControlsInterop_GetForWindow( media_control_interop_statics, *window, &IID_ISystemMediaTransportControls, (void **)controls ); ISystemMediaTransportControlsInterop_Release( media_control_interop_statics ); } WindowsDeleteString( str );
done: if (FAILED(hr)) DestroyWindow( hwnd ); else *window = hwnd; return hr; ```
Also, as I changed it here as well, we usually prefer to use the unicode version of any user32 function. It avoids any unnecessary locale conversion.