Sync with trunk r58033.
[reactos.git] / dll / win32 / ole32 / ole2.c
index 9e9ca65..1bd4c1a 100644 (file)
@@ -290,7 +290,7 @@ static inline HANDLE get_droptarget_handle(HWND hwnd)
  */
 static inline BOOL is_droptarget(HWND hwnd)
 {
-    return get_droptarget_handle(hwnd) ? TRUE : FALSE;
+    return get_droptarget_handle(hwnd) != 0;
 }
 
 /*************************************************************
@@ -703,10 +703,7 @@ HRESULT WINAPI OleRegGetUserType(
   /*
    * Open the class id Key
    */
-  hres = RegOpenKeyW(HKEY_CLASSES_ROOT,
-                    keyName,
-                    &clsidKey);
-
+  hres = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
   if (hres != ERROR_SUCCESS)
     return REGDB_E_CLASSNOTREG;
 
@@ -902,21 +899,14 @@ HRESULT WINAPI OleRegGetMiscStatus(
   /*
    * Open the class id Key
    */
-  result = RegOpenKeyW(HKEY_CLASSES_ROOT,
-                      keyName,
-                      &clsidKey);
-
+  result = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
   if (result != ERROR_SUCCESS)
     return REGDB_E_CLASSNOTREG;
 
   /*
    * Get the MiscStatus
    */
-  result = RegOpenKeyW(clsidKey,
-                      miscstatusW,
-                      &miscStatusKey);
-
-
+  result = open_classes_key(clsidKey, miscstatusW, MAXIMUM_ALLOWED, &miscStatusKey);
   if (result != ERROR_SUCCESS)
   {
     RegCloseKey(clsidKey);
@@ -933,10 +923,7 @@ HRESULT WINAPI OleRegGetMiscStatus(
    */
   sprintfW(keyName, dfmtW, dwAspect);
 
-  result = RegOpenKeyW(miscStatusKey,
-                      keyName,
-                      &aspectKey);
-
+  result = open_classes_key(miscStatusKey, keyName, MAXIMUM_ALLOWED, &aspectKey);
   if (result == ERROR_SUCCESS)
   {
     OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
@@ -975,7 +962,7 @@ static HRESULT WINAPI EnumOLEVERB_QueryInterface(
     if (IsEqualIID(riid, &IID_IUnknown) ||
         IsEqualIID(riid, &IID_IEnumOLEVERB))
     {
-        IUnknown_AddRef(iface);
+        IEnumOLEVERB_AddRef(iface);
         *ppv = iface;
         return S_OK;
     }
@@ -1333,10 +1320,7 @@ HRESULT WINAPI OleLoad(
   /*
    * Initialize the object with its IPersistStorage interface.
    */
-  hres = IOleObject_QueryInterface(pUnk,
-                                   &IID_IPersistStorage,
-                                   (void**)&persistStorage);
-
+  hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (void**)&persistStorage);
   if (SUCCEEDED(hres))
   {
     hres = IPersistStorage_Load(persistStorage, pStg);
@@ -1660,7 +1644,7 @@ static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDes
     if ( nPos < nWidth )
     {
       /* Odd elements are server menu widths */
-      pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
+      pOleMenuDescriptor->bIsServerItem = i%2;
       break;
     }
   }
@@ -2557,32 +2541,24 @@ HRESULT WINAPI OleDraw(
        IUnknown *pUnk,
        DWORD dwAspect,
        HDC hdcDraw,
-       LPCRECT lprcBounds)
+       LPCRECT rect)
 {
   HRESULT hres;
   IViewObject *viewobject;
 
+  if (!pUnk) return E_INVALIDARG;
+
   hres = IUnknown_QueryInterface(pUnk,
                                 &IID_IViewObject,
                                 (void**)&viewobject);
-
   if (SUCCEEDED(hres))
   {
-    RECTL rectl;
-
-    rectl.left = lprcBounds->left;
-    rectl.right = lprcBounds->right;
-    rectl.top = lprcBounds->top;
-    rectl.bottom = lprcBounds->bottom;
-    hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
-
+    hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, (RECTL*)rect, 0, 0, 0);
     IViewObject_Release(viewobject);
     return hres;
   }
   else
-  {
     return DV_E_NOIVIEWOBJECT;
-  }
 }
 
 /***********************************************************************
@@ -2816,86 +2792,22 @@ static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
 
 /***********************************************************************
  *           PropSysAllocString                            [OLE32.@]
- * NOTES:
- *  Basically a copy of SysAllocStringLen.
+ * NOTES
+ *  Forward to oleaut32.
  */
 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
 {
-    DWORD  bufferSize;
-    DWORD* newBuffer;
-    WCHAR* stringBuffer;
-    int len;
-
-    if (!str) return 0;
-
-    len = lstrlenW(str);
-    /*
-     * Find the length of the buffer passed-in, in bytes.
-     */
-    bufferSize = len * sizeof (WCHAR);
-
-    /*
-     * Allocate a new buffer to hold the string.
-     * Don't forget to keep an empty spot at the beginning of the
-     * buffer for the character count and an extra character at the
-     * end for the NULL.
-     */
-    newBuffer = HeapAlloc(GetProcessHeap(), 0,
-                          bufferSize + sizeof(WCHAR) + sizeof(DWORD));
-
-    /*
-     * If the memory allocation failed, return a null pointer.
-     */
-    if (newBuffer==0)
-      return 0;
-
-    /*
-     * Copy the length of the string in the placeholder.
-     */
-    *newBuffer = bufferSize;
-
-    /*
-     * Skip the byte count.
-     */
-    newBuffer++;
-
-    memcpy(newBuffer, str, bufferSize);
-
-    /*
-     * Make sure that there is a nul character at the end of the
-     * string.
-     */
-    stringBuffer = (WCHAR*)newBuffer;
-    stringBuffer[len] = '\0';
-
-    return stringBuffer;
+    return SysAllocString(str);
 }
 
 /***********************************************************************
  *           PropSysFreeString                     [OLE32.@]
  * NOTES
- *  Copy of SysFreeString.
+ *  Forward to oleaut32.
  */
 void WINAPI PropSysFreeString(LPOLESTR str)
 {
-    DWORD* bufferPointer;
-
-    /* NULL is a valid parameter */
-    if(!str) return;
-
-    /*
-     * We have to be careful when we free a BSTR pointer, it points to
-     * the beginning of the string but it skips the byte count contained
-     * before the string.
-     */
-    bufferPointer = (DWORD*)str;
-
-    bufferPointer--;
-
-    /*
-     * Free the memory from its "real" origin.
-     */
-    HeapFree(GetProcessHeap(), 0, bufferPointer);
+    SysFreeString(str);
 }
 
 /******************************************************************************
@@ -2907,8 +2819,10 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     {
     case VT_EMPTY:
     case VT_NULL:
+    case VT_I1:
     case VT_I2:
     case VT_I4:
+    case VT_I8:
     case VT_R4:
     case VT_R8:
     case VT_CY:
@@ -2920,7 +2834,6 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_UI1:
     case VT_UI2:
     case VT_UI4:
-    case VT_I8:
     case VT_UI8:
     case VT_LPSTR:
     case VT_LPWSTR:
@@ -2933,8 +2846,10 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_BLOB_OBJECT:
     case VT_CF:
     case VT_CLSID:
+    case VT_I1|VT_VECTOR:
     case VT_I2|VT_VECTOR:
     case VT_I4|VT_VECTOR:
+    case VT_I8|VT_VECTOR:
     case VT_R4|VT_VECTOR:
     case VT_R8|VT_VECTOR:
     case VT_CY|VT_VECTOR:
@@ -2946,7 +2861,6 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_UI1|VT_VECTOR:
     case VT_UI2|VT_VECTOR:
     case VT_UI4|VT_VECTOR:
-    case VT_I8|VT_VECTOR:
     case VT_UI8|VT_VECTOR:
     case VT_LPSTR|VT_VECTOR:
     case VT_LPWSTR|VT_VECTOR:
@@ -2979,8 +2893,10 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     {
     case VT_EMPTY:
     case VT_NULL:
+    case VT_I1:
     case VT_I2:
     case VT_I4:
+    case VT_I8:
     case VT_R4:
     case VT_R8:
     case VT_CY:
@@ -2991,7 +2907,6 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     case VT_UI1:
     case VT_UI2:
     case VT_UI4:
-    case VT_I8:
     case VT_UI8:
     case VT_FILETIME:
         break;
@@ -3000,7 +2915,7 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     case VT_STORAGE:
     case VT_STORED_OBJECT:
         if (pvar->u.pStream)
-            IUnknown_Release(pvar->u.pStream);
+            IStream_Release(pvar->u.pStream);
         break;
     case VT_CLSID:
     case VT_LPSTR:
@@ -3014,8 +2929,7 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
         CoTaskMemFree(pvar->u.blob.pBlobData);
         break;
     case VT_BSTR:
-        if (pvar->u.bstrVal)
-            PropSysFreeString(pvar->u.bstrVal);
+        PropSysFreeString(pvar->u.bstrVal);
         break;
     case VT_CF:
         if (pvar->u.pclipdata)