[STI] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / dll / win32 / sti / sti.c
index 974bd06..19feadc 100644 (file)
@@ -18,6 +18,9 @@
  */
 
 #include <stdarg.h>
+#ifdef __REACTOS__
+#include <wchar.h>
+#endif
 
 #define COBJMACROS
 
 #include "objbase.h"
 #include "sti.h"
 
-#include "sti_private.h"
-
 #include "wine/debug.h"
-#include "wine/unicode.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(sti);
 
@@ -44,33 +44,41 @@ static const WCHAR registeredAppsLaunchPath[] = {
     'R','e','g','i','s','t','e','r','e','d',' ','A','p','p','l','i','c','a','t','i','o','n','s',0
 };
 
-static inline stillimage *impl_from_StillImageW(IStillImageW *iface)
+typedef struct _stillimage
+{
+    IUnknown IUnknown_inner;
+    IStillImageW IStillImageW_iface;
+    IUnknown *outer_unk;
+    LONG ref;
+} stillimage;
+
+static inline stillimage *impl_from_IStillImageW(IStillImageW *iface)
 {
-    return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpVtbl));
+    return CONTAINING_RECORD(iface, stillimage, IStillImageW_iface);
 }
 
 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
-    return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppvObject);
 }
 
 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
 {
-    stillimage *This = impl_from_StillImageW(iface);
-    return IUnknown_AddRef(This->pUnkOuter);
+    stillimage *This = impl_from_IStillImageW(iface);
+    return IUnknown_AddRef(This->outer_unk);
 }
 
 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
 {
-    stillimage *This = impl_from_StillImageW(iface);
-    return IUnknown_Release(This->pUnkOuter);
+    stillimage *This = impl_from_IStillImageW(iface);
+    return IUnknown_Release(This->outer_unk);
 }
 
 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
     return S_OK;
 }
@@ -78,7 +86,7 @@ static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hins
 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
                                                 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
     return E_NOTIMPL;
 }
@@ -86,7 +94,7 @@ static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwTyp
 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
                                                 LPVOID *ppBuffer)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
     return E_NOTIMPL;
 }
@@ -94,7 +102,7 @@ static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwsz
 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
                                                PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
     return E_NOTIMPL;
 }
@@ -102,7 +110,7 @@ static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszD
 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
                                                  LPDWORD pType, LPBYTE pData, LPDWORD cbData)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
         pType, pData, cbData);
     return E_NOTIMPL;
@@ -111,7 +119,7 @@ static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pws
 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
                                                  DWORD type, LPBYTE pData, DWORD cbData)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
         type, pData, cbData);
     return E_NOTIMPL;
@@ -120,7 +128,7 @@ static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pws
 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
                                                           DWORD *pdwEventCode, LPWSTR pwszEventName)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
         pdwEventCode, pwszEventName);
     return E_NOTIMPL;
@@ -136,18 +144,18 @@ static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface,
     HKEY registeredAppsKey = NULL;
     DWORD ret;
     HRESULT hr = S_OK;
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
 
     TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
 
     ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
     if (ret == ERROR_SUCCESS)
     {
-        WCHAR *value = HeapAlloc(GetProcessHeap(), 0,
-            (lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1) * sizeof(WCHAR));
+        size_t len = lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1;
+        WCHAR *value = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
         if (value)
         {
-            sprintfW(value, format, pwszCommandLine, commandLineSuffix);
+            swprintf(value, format, pwszCommandLine, commandLineSuffix);
             ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
                 REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
             if (ret != ERROR_SUCCESS)
@@ -165,7 +173,7 @@ static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface,
 
 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     HKEY registeredAppsKey = NULL;
     DWORD ret;
     HRESULT hr = S_OK;
@@ -188,7 +196,7 @@ static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *ifac
 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
                                                         BOOL bNewState)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
     return E_NOTIMPL;
 }
@@ -196,14 +204,14 @@ static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPC
 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
                                                          BOOL *pbCurrentState)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
     return E_NOTIMPL;
 }
@@ -211,7 +219,7 @@ static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR
 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
                                                              LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
         pStiNotify);
     return E_NOTIMPL;
@@ -219,14 +227,14 @@ static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface
 
 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %p): stub\n", This, pDevInfo);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
 {
-    stillimage *This = impl_from_StillImageW(iface);
+    stillimage *This = impl_from_IStillImageW(iface);
     FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
     return E_NOTIMPL;
 }
@@ -253,21 +261,21 @@ static const struct IStillImageWVtbl stillimagew_vtbl =
     stillimagew_WriteToErrorLog
 };
 
-static inline stillimage *impl_from_InternalUnknown(IUnknown *iface)
+static inline stillimage *impl_from_IUnknown(IUnknown *iface)
 {
-    return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpInternalUnkVtbl));
+    return CONTAINING_RECORD(iface, stillimage, IUnknown_inner);
 }
 
 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
 {
-    stillimage *This = impl_from_InternalUnknown(iface);
+    stillimage *This = impl_from_IUnknown(iface);
 
     TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
 
     if (IsEqualGUID(riid, &IID_IUnknown))
         *ppvObject = iface;
     else if (IsEqualGUID(riid, &IID_IStillImageW))
-        *ppvObject = &This->lpVtbl;
+        *ppvObject = &This->IStillImageW_iface;
     else
     {
         if (IsEqualGUID(riid, &IID_IStillImageA))
@@ -284,14 +292,14 @@ static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void
 
 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
 {
-    stillimage *This = impl_from_InternalUnknown(iface);
+    stillimage *This = impl_from_IUnknown(iface);
     return InterlockedIncrement(&This->ref);
 }
 
 static ULONG WINAPI Internal_Release(IUnknown *iface)
 {
     ULONG ref;
-    stillimage *This = impl_from_InternalUnknown(iface);
+    stillimage *This = impl_from_IUnknown(iface);
 
     ref = InterlockedDecrement(&This->ref);
     if (ref == 0)
@@ -328,21 +336,21 @@ HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LP
     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
     if (This)
     {
-        This->lpVtbl = &stillimagew_vtbl;
-        This->lpInternalUnkVtbl = &internal_unk_vtbl;
+        This->IStillImageW_iface.lpVtbl = &stillimagew_vtbl;
+        This->IUnknown_inner.lpVtbl = &internal_unk_vtbl;
         if (pUnkOuter)
-            This->pUnkOuter = pUnkOuter;
+            This->outer_unk = pUnkOuter;
         else
-            This->pUnkOuter = (IUnknown*) &This->lpInternalUnkVtbl;
+            This->outer_unk = &This->IUnknown_inner;
         This->ref = 1;
 
-        hr = IStillImage_Initialize((IStillImageW*) &This->lpVtbl, hinst, dwVer);
+        hr = IStillImage_Initialize(&This->IStillImageW_iface, hinst, dwVer);
         if (SUCCEEDED(hr))
         {
             if (pUnkOuter)
-                *ppSti = (IStillImageW*) &This->lpInternalUnkVtbl;
+                *ppSti = (IStillImageW*) &This->IUnknown_inner;
             else
-                *ppSti = (IStillImageW*) &This->lpVtbl;
+                *ppSti = &This->IStillImageW_iface;
         }
     }
     else