[PATCH 2/8] Ignore size field when creating with -W calls

Nikolay Sivov nsivov at codeweavers.com
Sat Apr 30 00:49:35 CDT 2011


---
 dlls/comctl32/comctl32undoc.c |  141 ++++++++++++++++++++++-------------------
 dlls/comctl32/tests/mru.c     |   24 +++++--
 2 files changed, 94 insertions(+), 71 deletions(-)

diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index ff94051..7310242 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -168,23 +168,23 @@ DWORD WINAPI GetSize (LPVOID lpMem)
  *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
  *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
  *|
- *|typedef struct tagCREATEMRULIST
+ *|typedef struct tagMRUINFO
  *|{
  *|    DWORD   cbSize;
- *|    DWORD   nMaxItems;
- *|    DWORD   dwFlags;
+ *|    UINT    uMax;
+ *|    UINT    fFlags;
  *|    HKEY    hKey;
  *|    LPTSTR  lpszSubKey;
  *|    PROC    lpfnCompare;
- *|} CREATEMRULIST, *LPCREATEMRULIST;
+ *|} MRUINFO, *LPMRUINFO;
  *
  * MEMBERS
- *  cbSize      [I] The size of the CREATEMRULIST structure. This must be set
- *                  to sizeof(CREATEMRULIST) by the caller.
- *  nMaxItems   [I] The maximum number of items allowed in the list. Because
+ *  cbSize      [I] The size of the MRUINFO structure. This must be set
+ *                  to sizeof(MRUINFO) by the caller. Ignored by -W calls.
+ *  uMax        [I] The maximum number of items allowed in the list. Because
  *                  of the limited number of identifiers, this should be set to
  *                  a value from 1 to 30 by the caller.
- *  dwFlags     [I] If bit 0 is set, the list will be used to store binary
+ *  fFlags      [I] If bit 0 is set, the list will be used to store binary
  *                  data, otherwise it is assumed to store strings. If bit 1
  *                  is set, every change made to the list will be reflected in
  *                  the registry immediately, otherwise changes will only be
@@ -210,11 +210,11 @@ typedef INT (CALLBACK *MRUStringCmpFnA)(LPCSTR lhs, LPCSTR rhs);
 typedef INT (CALLBACK *MRUStringCmpFnW)(LPCWSTR lhs, LPCWSTR rhs);
 typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
 
-typedef struct tagCREATEMRULISTA
+typedef struct tagMRUINFOA
 {
     DWORD  cbSize;
-    DWORD  nMaxItems;
-    DWORD  dwFlags;
+    UINT   uMax;
+    UINT   fFlags;
     HKEY   hKey;
     LPSTR  lpszSubKey;
     union
@@ -222,13 +222,13 @@ typedef struct tagCREATEMRULISTA
         MRUStringCmpFnA string_cmpfn;
         MRUBinaryCmpFn  binary_cmpfn;
     } u;
-} CREATEMRULISTA, *LPCREATEMRULISTA;
+} MRUINFOA, *LPMRUINFOA;
 
-typedef struct tagCREATEMRULISTW
+typedef struct tagMRUINFOW
 {
     DWORD   cbSize;
-    DWORD   nMaxItems;
-    DWORD   dwFlags;
+    UINT    uMax;
+    UINT    fFlags;
     HKEY    hKey;
     LPWSTR  lpszSubKey;
     union
@@ -236,12 +236,12 @@ typedef struct tagCREATEMRULISTW
         MRUStringCmpFnW string_cmpfn;
         MRUBinaryCmpFn  binary_cmpfn;
     } u;
-} CREATEMRULISTW, *LPCREATEMRULISTW;
+} MRUINFOW, *LPMRUINFOW;
 
-/* dwFlags */
-#define MRUF_STRING_LIST  0 /* list will contain strings */
-#define MRUF_BINARY_LIST  1 /* list will contain binary data */
-#define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
+/* fFlags */
+#define MRU_STRING     0 /* list will contain strings, name's guessed */
+#define MRU_BINARY     1 /* list will contain binary data */
+#define MRU_CACHEWRITE 2 /* only save list order to reg. is FreeMRUList */
 
 /* If list is a string list lpfnCompare has the following prototype
  * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
@@ -263,14 +263,14 @@ typedef struct tagWINEMRUITEM
 
 typedef struct tagWINEMRULIST
 {
-    CREATEMRULISTW extview;     /* original create information       */
+    MRUINFOW       extview;     /* original create information       */
     BOOL           isUnicode;   /* is compare fn Unicode */
     DWORD          wineFlags;   /* internal flags                    */
     DWORD          cursize;     /* current size of realMRU           */
     LPWSTR         realMRU;     /* pointer to string of index names  */
     LPWINEMRUITEM  *array;      /* array of pointers to data         */
                                 /* in 'a' to 'z' order               */
-} WINEMRULIST, *LPWINEMRULIST;
+} WINEMRULIST;
 
 /* wineFlags */
 #define WMRUF_CHANGED  0x0001   /* MRU list has changed              */
@@ -280,7 +280,7 @@ typedef struct tagWINEMRULIST
  *
  * Local MRU saving code
  */
-static void MRU_SaveChanged ( LPWINEMRULIST mp )
+static void MRU_SaveChanged ( WINEMRULIST *mp )
 {
     UINT i, err;
     HKEY newkey;
@@ -325,7 +325,7 @@ static void MRU_SaveChanged ( LPWINEMRULIST mp )
 	    witem->itemFlag &= ~WMRUIF_CHANGED;
 	    realname[0] = 'a' + i;
 	    err = RegSetValueExW(newkey, realname, 0,
-				 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
+				 (mp->extview.fFlags & MRU_BINARY) ?
 				 REG_BINARY : REG_SZ,
 				 &witem->datastart, witem->size);
 	    if (err) {
@@ -351,7 +351,7 @@ static void MRU_SaveChanged ( LPWINEMRULIST mp )
  */
 void WINAPI FreeMRUList (HANDLE hMRUList)
 {
-    LPWINEMRULIST mp = hMRUList;
+    WINEMRULIST *mp = hMRUList;
     UINT i;
 
     TRACE("(%p)\n", hMRUList);
@@ -363,7 +363,7 @@ void WINAPI FreeMRUList (HANDLE hMRUList)
 	MRU_SaveChanged( mp );
     }
 
-    for(i=0; i<mp->extview.nMaxItems; i++)
+    for(i = 0; i < mp->extview.uMax; i++)
         Free(mp->array[i]);
 
     Free(mp->realMRU);
@@ -400,7 +400,7 @@ INT WINAPI FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData,
     if (!mp || !mp->extview.u.string_cmpfn)
 	return -1;
 
-    if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
+    if(!(mp->extview.fFlags & MRU_BINARY) && !mp->isUnicode) {
         DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
 					NULL, 0, NULL, NULL);
 	dataA = Alloc(len);
@@ -408,7 +408,7 @@ INT WINAPI FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData,
     }
 
     for(i=0; i<mp->cursize; i++) {
-	if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
+	if (mp->extview.fFlags & MRU_BINARY) {
 	    if (!mp->extview.u.binary_cmpfn(lpData, &mp->array[i]->datastart, cbData))
 		break;
 	}
@@ -465,7 +465,7 @@ INT WINAPI FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData,
  */
 INT WINAPI AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
 {
-    LPWINEMRULIST mp = hList;
+    WINEMRULIST *mp = hList;
     LPWINEMRUITEM witem;
     INT i, replace;
 
@@ -480,7 +480,7 @@ INT WINAPI AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
     }
     else {
 	/* either add a new entry or replace oldest */
-	if (mp->cursize < mp->extview.nMaxItems) {
+	if (mp->cursize < mp->extview.uMax) {
 	    /* Add in a new item */
 	    replace = mp->cursize;
 	    mp->cursize++;
@@ -509,7 +509,7 @@ INT WINAPI AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
     TRACE("(%p, %p, %d) adding data, /%c/ now most current\n",
           hList, lpData, cbData, replace+'a');
 
-    if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
+    if (!(mp->extview.fFlags & MRU_CACHEWRITE)) {
 	/* save changed stuff right now */
 	MRU_SaveChanged( mp );
     }
@@ -649,9 +649,9 @@ INT WINAPI FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
 }
 
 /*************************************************************************
- *                 CreateMRUListLazy_common (internal)
+ *                 create_mru_list (internal)
  */
-static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
+static HANDLE create_mru_list(WINEMRULIST *mp)
 {
     UINT i, err;
     HKEY newkey;
@@ -663,12 +663,12 @@ static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
     /* get space to save indices that will turn into names
      * but in order of most to least recently used
      */
-    mp->realMRU = Alloc((mp->extview.nMaxItems + 2) * sizeof(WCHAR));
+    mp->realMRU = Alloc((mp->extview.uMax + 2) * sizeof(WCHAR));
 
     /* get space to save pointers to actual data in order of
      * 'a' to 'z' (0 to n).
      */
-    mp->array = Alloc(mp->extview.nMaxItems * sizeof(LPVOID));
+    mp->array = Alloc(mp->extview.uMax * sizeof(LPVOID));
 
     /* open the sub key */
     if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
@@ -681,7 +681,7 @@ static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
 				&dwdisp))) {
 	/* error - what to do ??? */
 	ERR("(%u %u %x %p %s %p): Could not open key, error=%d\n",
-	    mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
+	    mp->extview.cbSize, mp->extview.uMax, mp->extview.fFlags,
 	    mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
             mp->extview.u.string_cmpfn, err);
 	return 0;
@@ -689,7 +689,7 @@ static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
 
     /* get values from key 'MRUList' */
     if (newkey) {
-	datasize = (mp->extview.nMaxItems + 1) * sizeof(WCHAR);
+	datasize = (mp->extview.uMax + 1) * sizeof(WCHAR);
 	if((err=RegQueryValueExW( newkey, strMRUList, 0, &type,
 				  (LPBYTE)mp->realMRU, &datasize))) {
 	    /* not present - set size to 1 (will become 0 later) */
@@ -726,7 +726,7 @@ static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
 	mp->cursize = 0;
 
     TRACE("(%u %u %x %p %s %p): Current Size = %d\n",
-	  mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
+	  mp->extview.cbSize, mp->extview.uMax, mp->extview.fFlags,
 	  mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
 	  mp->extview.u.string_cmpfn, mp->cursize);
     return mp;
@@ -735,26 +735,36 @@ static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
 /**************************************************************************
  *                  CreateMRUListLazyW [COMCTL32.404]
  *
- * See CreateMRUListLazyA.
+ *
+ * Creates a most-recently-used list.
+ *
+ * PARAMS
+ *     infoW  [I] ptr to MRUINFOW structure.
+ *     param2 [I] Unknown
+ *     param3 [I] Unknown
+ *     param4 [I] Unknown
+ *
+ * RETURNS
+ *     Handle to MRU list.
  */
-HANDLE WINAPI CreateMRUListLazyW (const CREATEMRULISTW *lpcml, DWORD dwParam2,
-                                  DWORD dwParam3, DWORD dwParam4)
+HANDLE WINAPI CreateMRUListLazyW (const MRUINFOW *infoW, DWORD param2,
+                                  DWORD param3, DWORD param4)
 {
-    LPWINEMRULIST mp;
+    WINEMRULIST *mp;
 
-    /* Native does not check for a NULL lpcml */
+    TRACE("(%p, 0x%08x, 0x%08x, 0x%08x)\n", infoW, param2, param3, param4);
 
-    if (lpcml->cbSize != sizeof(CREATEMRULISTW) || !lpcml->hKey ||
-        IsBadStringPtrW(lpcml->lpszSubKey, -1))
+    /* Native does not check for a NULL infoW */
+    if (!infoW->hKey || IsBadStringPtrW(infoW->lpszSubKey, -1))
 	return NULL;
 
     mp = Alloc(sizeof(WINEMRULIST));
-    memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
-    mp->extview.lpszSubKey = Alloc((strlenW(lpcml->lpszSubKey) + 1) * sizeof(WCHAR));
-    strcpyW(mp->extview.lpszSubKey, lpcml->lpszSubKey);
+    memcpy(&mp->extview, infoW, sizeof(MRUINFOW));
+    mp->extview.lpszSubKey = Alloc((strlenW(infoW->lpszSubKey) + 1) * sizeof(WCHAR));
+    strcpyW(mp->extview.lpszSubKey, infoW->lpszSubKey);
     mp->isUnicode = TRUE;
 
-    return CreateMRUListLazy_common(mp);
+    return create_mru_list(mp);
 }
 
 /**************************************************************************
@@ -771,26 +781,27 @@ HANDLE WINAPI CreateMRUListLazyW (const CREATEMRULISTW *lpcml, DWORD dwParam2,
  * RETURNS
  *     Handle to MRU list.
  */
-HANDLE WINAPI CreateMRUListLazyA (const CREATEMRULISTA *lpcml, DWORD dwParam2,
-                                  DWORD dwParam3, DWORD dwParam4)
+HANDLE WINAPI CreateMRUListLazyA (const MRUINFOA *infoA, DWORD param2,
+                                  DWORD param3, DWORD param4)
 {
-    LPWINEMRULIST mp;
+    WINEMRULIST *mp;
     DWORD len;
 
-    /* Native does not check for a NULL lpcml */
+    TRACE("(%p, 0x%08x, 0x%08x, 0x%08x)\n", infoA, param2, param3, param4);
 
-    if (lpcml->cbSize != sizeof(CREATEMRULISTA) || !lpcml->hKey ||
-        IsBadStringPtrA(lpcml->lpszSubKey, -1))
+    /* Native does not check for a NULL infoA */
+    if (infoA->cbSize != sizeof(MRUINFOA) || !infoA->hKey ||
+        IsBadStringPtrA(infoA->lpszSubKey, -1))
 	return 0;
 
     mp = Alloc(sizeof(WINEMRULIST));
-    memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
-    len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
+    memcpy(&mp->extview, infoA, sizeof(MRUINFOA));
+    len = MultiByteToWideChar(CP_ACP, 0, infoA->lpszSubKey, -1, NULL, 0);
     mp->extview.lpszSubKey = Alloc(len * sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
+    MultiByteToWideChar(CP_ACP, 0, infoA->lpszSubKey, -1,
 			mp->extview.lpszSubKey, len);
     mp->isUnicode = FALSE;
-    return CreateMRUListLazy_common(mp);
+    return create_mru_list(mp);
 }
 
 /**************************************************************************
@@ -798,9 +809,9 @@ HANDLE WINAPI CreateMRUListLazyA (const CREATEMRULISTA *lpcml, DWORD dwParam2,
  *
  * See CreateMRUListA.
  */
-HANDLE WINAPI CreateMRUListW (const CREATEMRULISTW *lpcml)
+HANDLE WINAPI CreateMRUListW(const MRUINFOW *infoW)
 {
-    return CreateMRUListLazyW(lpcml, 0, 0, 0);
+    return CreateMRUListLazyW(infoW, 0, 0, 0);
 }
 
 /**************************************************************************
@@ -809,14 +820,14 @@ HANDLE WINAPI CreateMRUListW (const CREATEMRULISTW *lpcml)
  * Creates a most-recently-used list.
  *
  * PARAMS
- *     lpcml [I] ptr to CREATEMRULIST structure.
+ *     infoA [I] ptr to MRUINFOA structure.
  *
  * RETURNS
  *     Handle to MRU list.
  */
-HANDLE WINAPI CreateMRUListA (const CREATEMRULISTA *lpcml)
+HANDLE WINAPI CreateMRUListA(const MRUINFOA *infoA)
 {
-     return CreateMRUListLazyA (lpcml, 0, 0, 0);
+     return CreateMRUListLazyA(infoA, 0, 0, 0);
 }
 
 
@@ -879,7 +890,7 @@ INT WINAPI EnumMRUListA (HANDLE hList, INT nItemPos, LPVOID lpBuffer,
     desired -= 'a';
     TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
     witem = mp->array[desired];
-    if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
+    if(mp->extview.fFlags & MRU_BINARY) {
         datasize = min( witem->size, nBufferSize );
 	memcpy( lpBuffer, &witem->datastart, datasize);
     } else {
diff --git a/dlls/comctl32/tests/mru.c b/dlls/comctl32/tests/mru.c
index 5def70f..73e82ff 100644
--- a/dlls/comctl32/tests/mru.c
+++ b/dlls/comctl32/tests/mru.c
@@ -558,6 +558,12 @@ static void test_CreateMRUListW(void)
     ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEYA, &hKey),
        "Couldn't create test key \"%s\"\n", REG_TEST_KEYA);
 
+    if (0)
+    {
+        /* NULL argument, crashes on native */
+        hMru = pCreateMRUListW(NULL);
+    }
+
     infoW.cbSize = sizeof(infoW);
     infoW.uMax = 1;
     infoW.fFlags = 0;
@@ -578,7 +584,7 @@ static void test_CreateMRUListW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListW(&infoW);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* increased size */
@@ -590,7 +596,7 @@ static void test_CreateMRUListW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListW(&infoW);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* zero size */
@@ -602,7 +608,7 @@ static void test_CreateMRUListW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListW(&infoW);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* NULL hKey */
@@ -637,6 +643,12 @@ static void test_CreateMRUListLazyW(void)
     named = GetProcAddress(hComctl32, "CreateMRUListLazyW");
     ok(named == NULL, "got %p\n", named);
 
+    if (0)
+    {
+        /* NULL argument, crashes on native */
+        hMru = pCreateMRUListLazyW(NULL, 0, 0, 0);
+    }
+
     ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEYA, &hKey),
        "Couldn't create test key \"%s\"\n", REG_TEST_KEYA);
 
@@ -660,7 +672,7 @@ static void test_CreateMRUListLazyW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListLazyW(&infoW, 0, 0, 0);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* increased size */
@@ -672,7 +684,7 @@ static void test_CreateMRUListLazyW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListLazyW(&infoW, 0, 0, 0);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* zero size */
@@ -684,7 +696,7 @@ static void test_CreateMRUListLazyW(void)
     infoW.lpfnCompare = NULL;
 
     hMru = pCreateMRUListLazyW(&infoW, 0, 0, 0);
-    todo_wine ok(hMru != NULL, "got %p\n", hMru);
+    ok(hMru != NULL, "got %p\n", hMru);
     pFreeMRUList(hMru);
 
     /* NULL hKey */
-- 
1.5.6.5



--------------010706040108050004000509--



More information about the wine-patches mailing list