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 /* working but untrusted implementation */
296 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
297 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
299 nIndex
= hdpa1
->nItemCount
- 1;
300 nCount
= hdpa2
->nItemCount
- 1;
305 if ((nCount
>= 0) && (dwFlags
& DPAM_UNION
)) {
306 /* Now insert the remaining new items into DPA 1 */
307 TRACE("%d items to be inserted at start of DPA 1\n",
309 for (i
=nCount
; i
>=0; i
--) {
312 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
315 DPA_InsertPtr (hdpa1
, 0, ptr
);
321 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
322 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
323 nResult
, nIndex
, nCount
);
329 ptr
= (pfnMerge
)(DPAMM_MERGE
, *pWork1
, *pWork2
, lParam
);
339 else if (nResult
> 0)
341 /* item in DPA 1 missing from DPA 2 */
342 if (dwFlags
& DPAM_INTERSECT
)
344 /* Now delete the extra item in DPA1 */
347 ptr
= DPA_DeletePtr (hdpa1
, nIndex
);
349 (pfnMerge
)(DPAMM_DELETE
, ptr
, NULL
, lParam
);
356 /* new item in DPA 2 */
357 if (dwFlags
& DPAM_UNION
)
359 /* Now insert the new item in DPA 1 */
362 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
365 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
378 /**************************************************************************
379 * DPA_Destroy [COMCTL32.329]
381 * Destroys a dynamic pointer array
384 * hdpa [I] handle (pointer) to the pointer array
390 BOOL WINAPI
DPA_Destroy (HDPA hdpa
)
392 TRACE("(%p)\n", hdpa
);
397 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
400 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
404 /**************************************************************************
405 * DPA_Grow [COMCTL32.330]
407 * Sets the growth amount.
410 * hdpa [I] handle (pointer) to the existing (source) pointer array
411 * nGrow [I] number of items by which the array grows when it's too small
417 BOOL WINAPI
DPA_Grow (HDPA hdpa
, INT nGrow
)
420 TRACE("(%p %d)\n", hdpa
, nGrow
);
425 nGrow
= max( 8, nGrow
);
426 items
= nGrow
* (((hdpa
->nMaxCount
- 1) / nGrow
) + 1);
427 if (items
> hdpa
->nMaxCount
)
432 ptr
= HeapReAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, items
* sizeof(LPVOID
) );
434 ptr
= HeapAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, items
* sizeof(LPVOID
) );
435 if (!ptr
) return FALSE
;
436 hdpa
->nMaxCount
= items
;
445 /**************************************************************************
446 * DPA_Clone [COMCTL32.331]
448 * Copies a pointer array to another one or creates a copy
451 * hdpa [I] handle (pointer) to the existing (source) pointer array
452 * hdpaNew [O] handle (pointer) to the destination pointer array
455 * Success: pointer to the destination pointer array.
459 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
460 * array will be created and its handle (pointer) is returned.
461 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
462 * this implementation just returns NULL.
464 HDPA WINAPI
DPA_Clone (const HDPA hdpa
, HDPA hdpaNew
)
466 INT nNewItems
, nSize
;
472 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
475 /* create a new DPA */
476 hdpaTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
478 hdpaTemp
->hHeap
= hdpa
->hHeap
;
479 hdpaTemp
->nGrow
= hdpa
->nGrow
;
484 if (hdpaTemp
->ptrs
) {
485 /* remove old pointer array */
486 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
487 hdpaTemp
->ptrs
= NULL
;
488 hdpaTemp
->nItemCount
= 0;
489 hdpaTemp
->nMaxCount
= 0;
492 /* create a new pointer array */
493 nNewItems
= hdpaTemp
->nGrow
*
494 (((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
495 nSize
= nNewItems
* sizeof(LPVOID
);
496 hdpaTemp
->ptrs
= HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
497 hdpaTemp
->nMaxCount
= nNewItems
;
499 /* clone the pointer array */
500 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
501 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
502 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
508 /**************************************************************************
509 * DPA_GetPtr [COMCTL32.332]
511 * Retrieves a pointer from a dynamic pointer array
514 * hdpa [I] handle (pointer) to the pointer array
515 * nIndex [I] array index of the desired pointer
521 LPVOID WINAPI
DPA_GetPtr (HDPA hdpa
, INT nIndex
)
523 TRACE("(%p %d)\n", hdpa
, nIndex
);
528 WARN("no pointer array.\n");
531 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
532 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
536 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
538 return hdpa
->ptrs
[nIndex
];
542 /**************************************************************************
543 * DPA_GetPtrIndex [COMCTL32.333]
545 * Retrieves the index of the specified pointer
548 * hdpa [I] handle (pointer) to the pointer array
552 * Success: index of the specified pointer
555 INT WINAPI
DPA_GetPtrIndex (HDPA hdpa
, LPCVOID p
)
559 if (!hdpa
|| !hdpa
->ptrs
)
562 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
563 if (hdpa
->ptrs
[i
] == p
)
571 /**************************************************************************
572 * DPA_InsertPtr [COMCTL32.334]
574 * Inserts a pointer into a dynamic pointer array
577 * hdpa [I] handle (pointer) to the array
579 * p [I] pointer to insert
582 * Success: index of the inserted pointer
585 INT WINAPI
DPA_InsertPtr (HDPA hdpa
, INT i
, LPVOID p
)
587 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
589 if (!hdpa
|| i
< 0) return -1;
591 /* append item if index is out of bounds */
592 i
= min(hdpa
->nItemCount
, i
);
594 /* create empty spot at the end */
595 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
597 if (i
!= hdpa
->nItemCount
- 1)
598 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
,
599 (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
606 /**************************************************************************
607 * DPA_SetPtr [COMCTL32.335]
609 * Sets a pointer in the pointer array
612 * hdpa [I] handle (pointer) to the pointer array
613 * i [I] index of the pointer that will be set
614 * p [I] pointer to be set
620 BOOL WINAPI
DPA_SetPtr (HDPA hdpa
, INT i
, LPVOID p
)
624 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
629 if (hdpa
->nItemCount
<= i
) {
630 /* within the old array */
631 if (hdpa
->nMaxCount
<= i
) {
632 /* resize the block of memory */
634 hdpa
->nGrow
* ((((i
+1) - 1) / hdpa
->nGrow
) + 1);
635 INT nSize
= nNewItems
* sizeof(LPVOID
);
638 lpTemp
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
640 lpTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
645 hdpa
->nMaxCount
= nNewItems
;
648 hdpa
->nItemCount
= i
+1;
651 /* put the new entry in */
658 /**************************************************************************
659 * DPA_DeletePtr [COMCTL32.336]
661 * Removes a pointer from the pointer array.
664 * hdpa [I] handle (pointer) to the pointer array
665 * i [I] index of the pointer that will be deleted
668 * Success: deleted pointer
671 LPVOID WINAPI
DPA_DeletePtr (HDPA hdpa
, INT i
)
673 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
676 TRACE("(%p %d)\n", hdpa
, i
);
678 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
681 lpTemp
= hdpa
->ptrs
[i
];
683 /* do we need to move ?*/
684 if (i
< hdpa
->nItemCount
- 1) {
685 lpDest
= hdpa
->ptrs
+ i
;
687 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
688 TRACE("-- move dest=%p src=%p size=%x\n",
689 lpDest
, lpSrc
, nSize
);
690 memmove (lpDest
, lpSrc
, nSize
);
696 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
697 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
698 nSize
= nNewItems
* sizeof(LPVOID
);
699 lpDest
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
704 hdpa
->nMaxCount
= nNewItems
;
712 /**************************************************************************
713 * DPA_DeleteAllPtrs [COMCTL32.337]
715 * Removes all pointers and reinitializes the array.
718 * hdpa [I] handle (pointer) to the pointer array
724 BOOL WINAPI
DPA_DeleteAllPtrs (HDPA hdpa
)
726 TRACE("(%p)\n", hdpa
);
731 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
734 hdpa
->nItemCount
= 0;
735 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
736 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
737 hdpa
->nMaxCount
* sizeof(LPVOID
));
743 /**************************************************************************
744 * DPA_QuickSort [Internal]
746 * Ordinary quicksort (used by DPA_Sort).
749 * lpPtrs [I] pointer to the pointer array
750 * l [I] index of the "left border" of the partition
751 * r [I] index of the "right border" of the partition
752 * pfnCompare [I] pointer to the compare function
753 * lParam [I] user defined value (3rd parameter in compare function)
758 static VOID
DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
759 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
764 TRACE("l=%i r=%i\n", l
, r
);
766 if (l
==r
) /* one element is always sorted */
768 if (r
<l
) /* oops, got it in the wrong order */
770 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
773 m
= (l
+r
)/2; /* divide by two */
774 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
775 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
777 /* join the two sides */
778 while( (l
<=m
) && (m
<r
) )
780 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
783 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
793 /**************************************************************************
794 * DPA_Sort [COMCTL32.338]
796 * Sorts a pointer array using a user defined compare function
799 * hdpa [I] handle (pointer) to the pointer array
800 * pfnCompare [I] pointer to the compare function
801 * lParam [I] user defined value (3rd parameter of compare function)
807 BOOL WINAPI
DPA_Sort (HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
809 if (!hdpa
|| !pfnCompare
)
812 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
814 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
815 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
822 /**************************************************************************
823 * DPA_Search [COMCTL32.339]
825 * Searches a pointer array for a specified pointer
828 * hdpa [I] handle (pointer) to the pointer array
829 * pFind [I] pointer to search for
830 * nStart [I] start index
831 * pfnCompare [I] pointer to the compare function
832 * lParam [I] user defined value (3rd parameter of compare function)
833 * uOptions [I] search options
836 * Success: index of the pointer in the array.
839 INT WINAPI
DPA_Search (HDPA hdpa
, LPVOID pFind
, INT nStart
,
840 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
842 if (!hdpa
|| !pfnCompare
|| !pFind
)
845 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
846 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
848 if (uOptions
& DPAS_SORTED
) {
849 /* array is sorted --> use binary search */
853 /* for binary search ignore start index */
855 r
= hdpa
->nItemCount
- 1;
859 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
867 if (uOptions
& (DPAS_INSERTBEFORE
|DPAS_INSERTAFTER
)) return l
;
870 /* array is not sorted --> use linear search */
874 nIndex
= (nStart
== -1)? 0 : nStart
;
876 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
877 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0)
886 /**************************************************************************
887 * DPA_CreateEx [COMCTL32.340]
889 * Creates a dynamic pointer array using the specified size and heap.
892 * nGrow [I] number of items by which the array grows when it is filled
893 * hHeap [I] handle to the heap where the array is stored
896 * Success: handle (pointer) to the pointer array.
900 * The DPA_ functions can be used to create and manipulate arrays of
903 HDPA WINAPI
DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
907 TRACE("(%d %p)\n", nGrow
, hHeap
);
910 hdpa
= HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
912 hdpa
= Alloc (sizeof(*hdpa
));
915 hdpa
->nGrow
= max(8, nGrow
);
916 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
917 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
918 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
919 hdpa
->nMaxCount
* sizeof(LPVOID
));
922 TRACE("-- %p\n", hdpa
);
928 /**************************************************************************
929 * DPA_Create [COMCTL32.328]
931 * Creates a dynamic pointer array.
934 * nGrow [I] number of items by which the array grows when it is filled
937 * Success: handle (pointer) to the pointer array.
941 * The DPA_ functions can be used to create and manipulate arrays of
944 HDPA WINAPI
DPA_Create (INT nGrow
)
946 return DPA_CreateEx( nGrow
, 0 );
950 /**************************************************************************
951 * DPA_EnumCallback [COMCTL32.385]
953 * Enumerates all items in a dynamic pointer array.
956 * hdpa [I] handle to the dynamic pointer array
963 VOID WINAPI
DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
968 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
972 if (hdpa
->nItemCount
<= 0)
975 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
976 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
984 /**************************************************************************
985 * DPA_DestroyCallback [COMCTL32.386]
987 * Enumerates all items in a dynamic pointer array and destroys it.
990 * hdpa [I] handle to the dynamic pointer array
997 void WINAPI
DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
1000 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
1002 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
1006 /**************************************************************************
1007 * DPA_GetSize [COMCTL32.@]
1009 * Returns all array allocated memory size
1012 * hdpa [I] handle to the dynamic pointer array
1017 ULONGLONG WINAPI
DPA_GetSize(HDPA hdpa
)
1019 TRACE("(%p)\n", hdpa
);
1021 if (!hdpa
) return 0;
1023 return sizeof(DPA
) + hdpa
->nMaxCount
*sizeof(PVOID
);