2 * Dynamic pointer array (DPA) implementation
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * These functions were involuntarily documented by Microsoft in 2002 as
24 * the outcome of an anti-trust suit brought by various U.S. governments.
25 * As a result the specifications on MSDN are inaccurate, incomplete
26 * and misleading. A much more complete (unofficial) documentation is
29 * http://members.ozemail.com.au/~geoffch/samples/win32/shell/comctl32
34 WINE_DEFAULT_DEBUG_CHANNEL(dpa
);
45 typedef struct _STREAMDATA
50 } STREAMDATA
, *PSTREAMDATA
;
52 /**************************************************************************
53 * DPA_LoadStream [COMCTL32.9]
55 * Loads a dynamic pointer array from a stream
58 * phDpa [O] pointer to a handle to a dynamic pointer array
59 * loadProc [I] pointer to a callback function
60 * pStream [I] pointer to a stream
61 * pData [I] pointer to callback data
64 * Success: S_OK, S_FALSE - partial success
65 * Failure: HRESULT error code
68 * No more information available yet!
70 HRESULT WINAPI
DPA_LoadStream (HDPA
*phDpa
, PFNDPASTREAM loadProc
,
71 IStream
*pStream
, LPVOID pData
)
74 LARGE_INTEGER position
;
75 ULARGE_INTEGER initial_pos
;
76 STREAMDATA streamData
;
77 DPASTREAMINFO streamInfo
;
82 TRACE ("phDpa=%p loadProc=%p pStream=%p pData=%p\n",
83 phDpa
, loadProc
, pStream
, pData
);
85 if (!phDpa
|| !loadProc
|| !pStream
)
90 position
.QuadPart
= 0;
92 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &initial_pos
);
96 memset(&streamData
, 0, sizeof(STREAMDATA
));
97 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
101 TRACE ("dwSize=%u dwData2=%u dwItems=%u\n",
102 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
104 if (ulRead
< sizeof(STREAMDATA
) ||
105 streamData
.dwSize
< sizeof(STREAMDATA
) || streamData
.dwData2
!= 1) {
106 /* back to initial position */
107 position
.QuadPart
= initial_pos
.QuadPart
;
108 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
112 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
113 return E_OUTOFMEMORY
;
116 hDpa
= DPA_Create (streamData
.dwItems
);
118 return E_OUTOFMEMORY
;
120 if (!DPA_Grow (hDpa
, streamData
.dwItems
)) {
122 return E_OUTOFMEMORY
;
125 /* load data from the stream into the dpa */
127 for (streamInfo
.iPos
= 0; streamInfo
.iPos
< streamData
.dwItems
; streamInfo
.iPos
++) {
128 errCode
= (loadProc
)(&streamInfo
, pStream
, pData
);
129 if (errCode
!= S_OK
) {
134 *ptr
= streamInfo
.pvItem
;
138 /* set the number of items */
139 hDpa
->nItemCount
= streamInfo
.iPos
;
141 /* store the handle to the dpa */
143 TRACE ("new hDpa=%p, errorcode=%x\n", hDpa
, errCode
);
149 /**************************************************************************
150 * DPA_SaveStream [COMCTL32.10]
152 * Saves a dynamic pointer array to a stream
155 * hDpa [I] handle to a dynamic pointer array
156 * saveProc [I] pointer to a callback function
157 * pStream [I] pointer to a stream
158 * pData [I] pointer to callback data
161 * Success: S_OK, S_FALSE - partial success
162 * Failure: HRESULT error code
165 * No more information available yet!
167 HRESULT WINAPI
DPA_SaveStream (HDPA hDpa
, PFNDPASTREAM saveProc
,
168 IStream
*pStream
, LPVOID pData
)
170 LARGE_INTEGER position
;
171 ULARGE_INTEGER initial_pos
, curr_pos
;
172 STREAMDATA streamData
;
173 DPASTREAMINFO streamInfo
;
177 TRACE ("hDpa=%p saveProc=%p pStream=%p pData=%p\n",
178 hDpa
, saveProc
, pStream
, pData
);
180 if (!hDpa
|| !saveProc
|| !pStream
) return E_INVALIDARG
;
182 /* save initial position to write header after completion */
183 position
.QuadPart
= 0;
184 hr
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &initial_pos
);
188 /* write empty header */
189 streamData
.dwSize
= sizeof(streamData
);
190 streamData
.dwData2
= 1;
191 streamData
.dwItems
= 0;
193 hr
= IStream_Write (pStream
, &streamData
, sizeof(streamData
), NULL
);
195 position
.QuadPart
= initial_pos
.QuadPart
;
196 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
200 /* no items - we're done */
201 if (hDpa
->nItemCount
== 0) return S_OK
;
204 for (streamInfo
.iPos
= 0; streamInfo
.iPos
< hDpa
->nItemCount
; streamInfo
.iPos
++) {
205 streamInfo
.pvItem
= *ptr
;
206 hr
= (saveProc
)(&streamInfo
, pStream
, pData
);
214 /* write updated header */
215 position
.QuadPart
= 0;
216 IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &curr_pos
);
218 streamData
.dwSize
= curr_pos
.QuadPart
- initial_pos
.QuadPart
;
219 streamData
.dwData2
= 1;
220 streamData
.dwItems
= streamInfo
.iPos
;
222 position
.QuadPart
= initial_pos
.QuadPart
;
223 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
224 IStream_Write (pStream
, &streamData
, sizeof(streamData
), NULL
);
226 position
.QuadPart
= curr_pos
.QuadPart
;
227 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
233 /**************************************************************************
234 * DPA_Merge [COMCTL32.11]
236 * Merge two dynamic pointers arrays.
239 * hdpa1 [I] handle to a dynamic pointer array
240 * hdpa2 [I] handle to a dynamic pointer array
242 * pfnCompare [I] pointer to sort function
243 * pfnMerge [I] pointer to merge function
244 * lParam [I] application specific value
251 * No more information available yet!
253 BOOL WINAPI
DPA_Merge (HDPA hdpa1
, HDPA hdpa2
, DWORD dwFlags
,
254 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
,
258 LPVOID
*pWork1
, *pWork2
;
262 TRACE("(%p %p %08x %p %p %08lx)\n",
263 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
265 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
268 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
271 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
274 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
277 if (!(dwFlags
& DPAM_SORTED
)) {
278 TRACE("sorting dpa's!\n");
279 if (hdpa1
->nItemCount
> 0)
280 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
281 TRACE ("dpa 1 sorted!\n");
282 if (hdpa2
->nItemCount
> 0)
283 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
284 TRACE ("dpa 2 sorted!\n");
287 if (hdpa2
->nItemCount
< 1)
290 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
291 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
294 nIndex
= hdpa1
->nItemCount
- 1;
295 nCount
= hdpa2
->nItemCount
- 1;
299 pWork1
= &hdpa1
->ptrs
[nIndex
];
300 pWork2
= &hdpa2
->ptrs
[nCount
];
303 if ((nCount
>= 0) && (dwFlags
& DPAM_UNION
)) {
304 /* Now insert the remaining new items into DPA 1 */
305 TRACE("%d items to be inserted at start of DPA 1\n",
307 for (i
=nCount
; i
>=0; i
--) {
310 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
313 DPA_InsertPtr (hdpa1
, 0, ptr
);
319 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
320 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
321 nResult
, nIndex
, nCount
);
327 ptr
= (pfnMerge
)(DPAMM_MERGE
, *pWork1
, *pWork2
, lParam
);
335 else if (nResult
> 0)
337 /* item in DPA 1 missing from DPA 2 */
338 if (dwFlags
& DPAM_INTERSECT
)
340 /* Now delete the extra item in DPA1 */
343 ptr
= DPA_DeletePtr (hdpa1
, nIndex
);
345 (pfnMerge
)(DPAMM_DELETE
, ptr
, NULL
, lParam
);
351 /* new item in DPA 2 */
352 if (dwFlags
& DPAM_UNION
)
354 /* Now insert the new item in DPA 1 */
357 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
360 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
372 /**************************************************************************
373 * DPA_Destroy [COMCTL32.329]
375 * Destroys a dynamic pointer array
378 * hdpa [I] handle (pointer) to the pointer array
384 BOOL WINAPI
DPA_Destroy (HDPA hdpa
)
386 TRACE("(%p)\n", hdpa
);
391 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
394 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
398 /**************************************************************************
399 * DPA_Grow [COMCTL32.330]
401 * Sets the growth amount.
404 * hdpa [I] handle (pointer) to the existing (source) pointer array
405 * nGrow [I] number of items by which the array grows when it's too small
411 BOOL WINAPI
DPA_Grow (HDPA hdpa
, INT nGrow
)
414 TRACE("(%p %d)\n", hdpa
, nGrow
);
419 nGrow
= max( 8, nGrow
);
420 items
= nGrow
* (((hdpa
->nMaxCount
- 1) / nGrow
) + 1);
421 if (items
> hdpa
->nMaxCount
)
426 ptr
= HeapReAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, items
* sizeof(LPVOID
) );
428 ptr
= HeapAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, items
* sizeof(LPVOID
) );
429 if (!ptr
) return FALSE
;
430 hdpa
->nMaxCount
= items
;
439 /**************************************************************************
440 * DPA_Clone [COMCTL32.331]
442 * Copies a pointer array to another one or creates a copy
445 * hdpa [I] handle (pointer) to the existing (source) pointer array
446 * hdpaNew [O] handle (pointer) to the destination pointer array
449 * Success: pointer to the destination pointer array.
453 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
454 * array will be created and its handle (pointer) is returned.
455 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
456 * this implementation just returns NULL.
458 HDPA WINAPI
DPA_Clone (const HDPA hdpa
, HDPA hdpaNew
)
460 INT nNewItems
, nSize
;
466 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
469 /* create a new DPA */
470 hdpaTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
472 hdpaTemp
->hHeap
= hdpa
->hHeap
;
473 hdpaTemp
->nGrow
= hdpa
->nGrow
;
478 if (hdpaTemp
->ptrs
) {
479 /* remove old pointer array */
480 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
481 hdpaTemp
->ptrs
= NULL
;
482 hdpaTemp
->nItemCount
= 0;
483 hdpaTemp
->nMaxCount
= 0;
486 /* create a new pointer array */
487 nNewItems
= hdpaTemp
->nGrow
*
488 (((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
489 nSize
= nNewItems
* sizeof(LPVOID
);
490 hdpaTemp
->ptrs
= HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
491 hdpaTemp
->nMaxCount
= nNewItems
;
493 /* clone the pointer array */
494 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
495 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
496 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
502 /**************************************************************************
503 * DPA_GetPtr [COMCTL32.332]
505 * Retrieves a pointer from a dynamic pointer array
508 * hdpa [I] handle (pointer) to the pointer array
509 * nIndex [I] array index of the desired pointer
515 LPVOID WINAPI
DPA_GetPtr (HDPA hdpa
, INT nIndex
)
517 TRACE("(%p %d)\n", hdpa
, nIndex
);
522 WARN("no pointer array.\n");
525 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
526 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
530 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
532 return hdpa
->ptrs
[nIndex
];
536 /**************************************************************************
537 * DPA_GetPtrIndex [COMCTL32.333]
539 * Retrieves the index of the specified pointer
542 * hdpa [I] handle (pointer) to the pointer array
546 * Success: index of the specified pointer
549 INT WINAPI
DPA_GetPtrIndex (HDPA hdpa
, LPCVOID p
)
553 if (!hdpa
|| !hdpa
->ptrs
)
556 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
557 if (hdpa
->ptrs
[i
] == p
)
565 /**************************************************************************
566 * DPA_InsertPtr [COMCTL32.334]
568 * Inserts a pointer into a dynamic pointer array
571 * hdpa [I] handle (pointer) to the array
573 * p [I] pointer to insert
576 * Success: index of the inserted pointer
579 INT WINAPI
DPA_InsertPtr (HDPA hdpa
, INT i
, LPVOID p
)
581 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
583 if (!hdpa
|| i
< 0) return -1;
585 /* append item if index is out of bounds */
586 i
= min(hdpa
->nItemCount
, i
);
588 /* create empty spot at the end */
589 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
591 if (i
!= hdpa
->nItemCount
- 1)
592 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
,
593 (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
600 /**************************************************************************
601 * DPA_SetPtr [COMCTL32.335]
603 * Sets a pointer in the pointer array
606 * hdpa [I] handle (pointer) to the pointer array
607 * i [I] index of the pointer that will be set
608 * p [I] pointer to be set
614 BOOL WINAPI
DPA_SetPtr (HDPA hdpa
, INT i
, LPVOID p
)
618 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
623 if (hdpa
->nItemCount
<= i
) {
624 /* within the old array */
625 if (hdpa
->nMaxCount
<= i
) {
626 /* resize the block of memory */
628 hdpa
->nGrow
* ((((i
+1) - 1) / hdpa
->nGrow
) + 1);
629 INT nSize
= nNewItems
* sizeof(LPVOID
);
632 lpTemp
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
634 lpTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
639 hdpa
->nMaxCount
= nNewItems
;
642 hdpa
->nItemCount
= i
+1;
645 /* put the new entry in */
652 /**************************************************************************
653 * DPA_DeletePtr [COMCTL32.336]
655 * Removes a pointer from the pointer array.
658 * hdpa [I] handle (pointer) to the pointer array
659 * i [I] index of the pointer that will be deleted
662 * Success: deleted pointer
665 LPVOID WINAPI
DPA_DeletePtr (HDPA hdpa
, INT i
)
667 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
670 TRACE("(%p %d)\n", hdpa
, i
);
672 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
675 lpTemp
= hdpa
->ptrs
[i
];
677 /* do we need to move ?*/
678 if (i
< hdpa
->nItemCount
- 1) {
679 lpDest
= hdpa
->ptrs
+ i
;
681 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
682 TRACE("-- move dest=%p src=%p size=%x\n",
683 lpDest
, lpSrc
, nSize
);
684 memmove (lpDest
, lpSrc
, nSize
);
690 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
691 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
692 nSize
= nNewItems
* sizeof(LPVOID
);
693 lpDest
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
698 hdpa
->nMaxCount
= nNewItems
;
706 /**************************************************************************
707 * DPA_DeleteAllPtrs [COMCTL32.337]
709 * Removes all pointers and reinitializes the array.
712 * hdpa [I] handle (pointer) to the pointer array
718 BOOL WINAPI
DPA_DeleteAllPtrs (HDPA hdpa
)
720 TRACE("(%p)\n", hdpa
);
725 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
728 hdpa
->nItemCount
= 0;
729 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
730 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
731 hdpa
->nMaxCount
* sizeof(LPVOID
));
737 /**************************************************************************
738 * DPA_QuickSort [Internal]
740 * Ordinary quicksort (used by DPA_Sort).
743 * lpPtrs [I] pointer to the pointer array
744 * l [I] index of the "left border" of the partition
745 * r [I] index of the "right border" of the partition
746 * pfnCompare [I] pointer to the compare function
747 * lParam [I] user defined value (3rd parameter in compare function)
752 static VOID
DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
753 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
758 TRACE("l=%i r=%i\n", l
, r
);
760 if (l
==r
) /* one element is always sorted */
762 if (r
<l
) /* oops, got it in the wrong order */
764 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
767 m
= (l
+r
)/2; /* divide by two */
768 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
769 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
771 /* join the two sides */
772 while( (l
<=m
) && (m
<r
) )
774 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
777 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
787 /**************************************************************************
788 * DPA_Sort [COMCTL32.338]
790 * Sorts a pointer array using a user defined compare function
793 * hdpa [I] handle (pointer) to the pointer array
794 * pfnCompare [I] pointer to the compare function
795 * lParam [I] user defined value (3rd parameter of compare function)
801 BOOL WINAPI
DPA_Sort (HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
803 if (!hdpa
|| !pfnCompare
)
806 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
808 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
809 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
816 /**************************************************************************
817 * DPA_Search [COMCTL32.339]
819 * Searches a pointer array for a specified pointer
822 * hdpa [I] handle (pointer) to the pointer array
823 * pFind [I] pointer to search for
824 * nStart [I] start index
825 * pfnCompare [I] pointer to the compare function
826 * lParam [I] user defined value (3rd parameter of compare function)
827 * uOptions [I] search options
830 * Success: index of the pointer in the array.
833 INT WINAPI
DPA_Search (HDPA hdpa
, LPVOID pFind
, INT nStart
,
834 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
836 if (!hdpa
|| !pfnCompare
|| !pFind
)
839 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
840 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
842 if (uOptions
& DPAS_SORTED
) {
843 /* array is sorted --> use binary search */
847 /* for binary search ignore start index */
849 r
= hdpa
->nItemCount
- 1;
853 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
861 if (uOptions
& (DPAS_INSERTBEFORE
|DPAS_INSERTAFTER
)) return l
;
864 /* array is not sorted --> use linear search */
868 nIndex
= (nStart
== -1)? 0 : nStart
;
870 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
871 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0)
880 /**************************************************************************
881 * DPA_CreateEx [COMCTL32.340]
883 * Creates a dynamic pointer array using the specified size and heap.
886 * nGrow [I] number of items by which the array grows when it is filled
887 * hHeap [I] handle to the heap where the array is stored
890 * Success: handle (pointer) to the pointer array.
894 * The DPA_ functions can be used to create and manipulate arrays of
897 HDPA WINAPI
DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
901 TRACE("(%d %p)\n", nGrow
, hHeap
);
904 hdpa
= HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
906 hdpa
= Alloc (sizeof(*hdpa
));
909 hdpa
->nGrow
= max(8, nGrow
);
910 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
911 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
912 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
913 hdpa
->nMaxCount
* sizeof(LPVOID
));
916 TRACE("-- %p\n", hdpa
);
922 /**************************************************************************
923 * DPA_Create [COMCTL32.328]
925 * Creates a dynamic pointer array.
928 * nGrow [I] number of items by which the array grows when it is filled
931 * Success: handle (pointer) to the pointer array.
935 * The DPA_ functions can be used to create and manipulate arrays of
938 HDPA WINAPI
DPA_Create (INT nGrow
)
940 return DPA_CreateEx( nGrow
, 0 );
944 /**************************************************************************
945 * DPA_EnumCallback [COMCTL32.385]
947 * Enumerates all items in a dynamic pointer array.
950 * hdpa [I] handle to the dynamic pointer array
957 VOID WINAPI
DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
962 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
966 if (hdpa
->nItemCount
<= 0)
969 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
970 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
978 /**************************************************************************
979 * DPA_DestroyCallback [COMCTL32.386]
981 * Enumerates all items in a dynamic pointer array and destroys it.
984 * hdpa [I] handle to the dynamic pointer array
991 void WINAPI
DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
994 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
996 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
1000 /**************************************************************************
1001 * DPA_GetSize [COMCTL32.@]
1003 * Returns all array allocated memory size
1006 * hdpa [I] handle to the dynamic pointer array
1011 ULONGLONG WINAPI
DPA_GetSize(HDPA hdpa
)
1013 TRACE("(%p)\n", hdpa
);
1015 if (!hdpa
) return 0;
1017 return sizeof(DPA
) + hdpa
->nMaxCount
*sizeof(PVOID
);