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
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dpa
);
57 typedef struct _STREAMDATA
62 } STREAMDATA
, *PSTREAMDATA
;
64 /**************************************************************************
65 * DPA_LoadStream [COMCTL32.9]
67 * Loads a dynamic pointer array from a stream
70 * phDpa [O] pointer to a handle to a dynamic pointer array
71 * loadProc [I] pointer to a callback function
72 * pStream [I] pointer to a stream
73 * pData [I] pointer to callback data
76 * Success: S_OK, S_FALSE - partial success
77 * Failure: HRESULT error code
80 * No more information available yet!
82 HRESULT WINAPI
DPA_LoadStream (HDPA
*phDpa
, PFNDPASTREAM loadProc
,
83 IStream
*pStream
, LPVOID pData
)
86 LARGE_INTEGER position
;
87 ULARGE_INTEGER initial_pos
;
88 STREAMDATA streamData
;
89 DPASTREAMINFO streamInfo
;
94 TRACE ("phDpa=%p loadProc=%p pStream=%p pData=%p\n",
95 phDpa
, loadProc
, pStream
, pData
);
97 if (!phDpa
|| !loadProc
|| !pStream
)
102 position
.QuadPart
= 0;
104 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &initial_pos
);
108 memset(&streamData
, 0, sizeof(STREAMDATA
));
109 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
113 TRACE ("dwSize=%u dwData2=%u dwItems=%u\n",
114 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
116 if (ulRead
< sizeof(STREAMDATA
) ||
117 streamData
.dwSize
< sizeof(STREAMDATA
) || streamData
.dwData2
!= 1) {
118 /* back to initial position */
119 position
.QuadPart
= initial_pos
.QuadPart
;
120 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
124 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
125 return E_OUTOFMEMORY
;
128 hDpa
= DPA_Create (streamData
.dwItems
);
130 return E_OUTOFMEMORY
;
132 if (!DPA_Grow (hDpa
, streamData
.dwItems
)) {
134 return E_OUTOFMEMORY
;
137 /* load data from the stream into the dpa */
139 for (streamInfo
.iPos
= 0; streamInfo
.iPos
< streamData
.dwItems
; streamInfo
.iPos
++) {
140 errCode
= (loadProc
)(&streamInfo
, pStream
, pData
);
141 if (errCode
!= S_OK
) {
146 *ptr
= streamInfo
.pvItem
;
150 /* set the number of items */
151 hDpa
->nItemCount
= streamInfo
.iPos
;
153 /* store the handle to the dpa */
155 TRACE ("new hDpa=%p, errorcode=%x\n", hDpa
, errCode
);
161 /**************************************************************************
162 * DPA_SaveStream [COMCTL32.10]
164 * Saves a dynamic pointer array to a stream
167 * hDpa [I] handle to a dynamic pointer array
168 * saveProc [I] pointer to a callback function
169 * pStream [I] pointer to a stream
170 * pData [I] pointer to callback data
173 * Success: S_OK, S_FALSE - partial success
174 * Failure: HRESULT error code
177 * No more information available yet!
179 HRESULT WINAPI
DPA_SaveStream (HDPA hDpa
, PFNDPASTREAM saveProc
,
180 IStream
*pStream
, LPVOID pData
)
182 LARGE_INTEGER position
;
183 ULARGE_INTEGER initial_pos
, curr_pos
;
184 STREAMDATA streamData
;
185 DPASTREAMINFO streamInfo
;
189 TRACE ("hDpa=%p saveProc=%p pStream=%p pData=%p\n",
190 hDpa
, saveProc
, pStream
, pData
);
192 if (!hDpa
|| !saveProc
|| !pStream
) return E_INVALIDARG
;
194 /* save initial position to write header after completion */
195 position
.QuadPart
= 0;
196 hr
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &initial_pos
);
200 /* write empty header */
201 streamData
.dwSize
= sizeof(streamData
);
202 streamData
.dwData2
= 1;
203 streamData
.dwItems
= 0;
205 hr
= IStream_Write (pStream
, &streamData
, sizeof(streamData
), NULL
);
207 position
.QuadPart
= initial_pos
.QuadPart
;
208 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
212 /* no items - we're done */
213 if (hDpa
->nItemCount
== 0) return S_OK
;
216 for (streamInfo
.iPos
= 0; streamInfo
.iPos
< hDpa
->nItemCount
; streamInfo
.iPos
++) {
217 streamInfo
.pvItem
= *ptr
;
218 hr
= (saveProc
)(&streamInfo
, pStream
, pData
);
226 /* write updated header */
227 position
.QuadPart
= 0;
228 IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &curr_pos
);
230 streamData
.dwSize
= curr_pos
.QuadPart
- initial_pos
.QuadPart
;
231 streamData
.dwData2
= 1;
232 streamData
.dwItems
= streamInfo
.iPos
;
234 position
.QuadPart
= initial_pos
.QuadPart
;
235 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
236 IStream_Write (pStream
, &streamData
, sizeof(streamData
), NULL
);
238 position
.QuadPart
= curr_pos
.QuadPart
;
239 IStream_Seek (pStream
, position
, STREAM_SEEK_SET
, NULL
);
245 /**************************************************************************
246 * DPA_Merge [COMCTL32.11]
248 * Merge two dynamic pointers arrays.
251 * hdpa1 [I] handle to a dynamic pointer array
252 * hdpa2 [I] handle to a dynamic pointer array
254 * pfnCompare [I] pointer to sort function
255 * pfnMerge [I] pointer to merge function
256 * lParam [I] application specific value
263 * No more information available yet!
265 BOOL WINAPI
DPA_Merge (HDPA hdpa1
, HDPA hdpa2
, DWORD dwFlags
,
266 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
,
270 LPVOID
*pWork1
, *pWork2
;
274 TRACE("(%p %p %08x %p %p %08lx)\n",
275 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
277 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
280 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
283 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
286 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
289 if (!(dwFlags
& DPAM_SORTED
)) {
290 TRACE("sorting dpa's.\n");
291 if (hdpa1
->nItemCount
> 0)
292 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
293 TRACE ("dpa 1 sorted.\n");
294 if (hdpa2
->nItemCount
> 0)
295 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
296 TRACE ("dpa 2 sorted.\n");
299 if (hdpa2
->nItemCount
< 1)
302 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
303 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
306 nIndex
= hdpa1
->nItemCount
- 1;
307 nCount
= hdpa2
->nItemCount
- 1;
311 pWork1
= &hdpa1
->ptrs
[nIndex
];
312 pWork2
= &hdpa2
->ptrs
[nCount
];
315 if ((nCount
>= 0) && (dwFlags
& DPAM_UNION
)) {
316 /* Now insert the remaining new items into DPA 1 */
317 TRACE("%d items to be inserted at start of DPA 1\n",
319 for (i
=nCount
; i
>=0; i
--) {
322 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
325 DPA_InsertPtr (hdpa1
, 0, ptr
);
331 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
332 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
333 nResult
, nIndex
, nCount
);
339 ptr
= (pfnMerge
)(DPAMM_MERGE
, *pWork1
, *pWork2
, lParam
);
347 else if (nResult
> 0)
349 /* item in DPA 1 missing from DPA 2 */
350 if (dwFlags
& DPAM_INTERSECT
)
352 /* Now delete the extra item in DPA1 */
355 ptr
= DPA_DeletePtr (hdpa1
, nIndex
);
357 (pfnMerge
)(DPAMM_DELETE
, ptr
, NULL
, lParam
);
363 /* new item in DPA 2 */
364 if (dwFlags
& DPAM_UNION
)
366 /* Now insert the new item in DPA 1 */
369 ptr
= (pfnMerge
)(DPAMM_INSERT
, *pWork2
, NULL
, lParam
);
372 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
384 /**************************************************************************
385 * DPA_Destroy [COMCTL32.329]
387 * Destroys a dynamic pointer array
390 * hdpa [I] handle (pointer) to the pointer array
396 BOOL WINAPI
DPA_Destroy (HDPA hdpa
)
398 TRACE("(%p)\n", hdpa
);
403 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
406 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
410 /**************************************************************************
411 * DPA_Grow [COMCTL32.330]
413 * Sets the growth amount.
416 * hdpa [I] handle (pointer) to the existing (source) pointer array
417 * nGrow [I] number of items by which the array grows when it's too small
423 BOOL WINAPI
DPA_Grow (HDPA hdpa
, INT nGrow
)
426 TRACE("(%p %d)\n", hdpa
, nGrow
);
431 nGrow
= max( 8, nGrow
);
432 items
= nGrow
* (((hdpa
->nMaxCount
- 1) / nGrow
) + 1);
433 if (items
> hdpa
->nMaxCount
)
438 ptr
= HeapReAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, items
* sizeof(LPVOID
) );
440 ptr
= HeapAlloc( hdpa
->hHeap
, HEAP_ZERO_MEMORY
, items
* sizeof(LPVOID
) );
441 if (!ptr
) return FALSE
;
442 hdpa
->nMaxCount
= items
;
451 /**************************************************************************
452 * DPA_Clone [COMCTL32.331]
454 * Copies a pointer array to another one or creates a copy
457 * hdpa [I] handle (pointer) to the existing (source) pointer array
458 * hdpaNew [O] handle (pointer) to the destination pointer array
461 * Success: pointer to the destination pointer array.
465 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
466 * array will be created and its handle (pointer) is returned.
467 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
468 * this implementation just returns NULL.
470 HDPA WINAPI
DPA_Clone (const HDPA hdpa
, HDPA hdpaNew
)
472 INT nNewItems
, nSize
;
478 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
481 /* create a new DPA */
482 hdpaTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
484 hdpaTemp
->hHeap
= hdpa
->hHeap
;
485 hdpaTemp
->nGrow
= hdpa
->nGrow
;
490 if (hdpaTemp
->ptrs
) {
491 /* remove old pointer array */
492 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
493 hdpaTemp
->ptrs
= NULL
;
494 hdpaTemp
->nItemCount
= 0;
495 hdpaTemp
->nMaxCount
= 0;
498 /* create a new pointer array */
499 nNewItems
= hdpaTemp
->nGrow
*
500 (((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
501 nSize
= nNewItems
* sizeof(LPVOID
);
502 hdpaTemp
->ptrs
= HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
503 hdpaTemp
->nMaxCount
= nNewItems
;
505 /* clone the pointer array */
506 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
507 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
508 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
514 /**************************************************************************
515 * DPA_GetPtr [COMCTL32.332]
517 * Retrieves a pointer from a dynamic pointer array
520 * hdpa [I] handle (pointer) to the pointer array
521 * nIndex [I] array index of the desired pointer
527 LPVOID WINAPI
DPA_GetPtr (HDPA hdpa
, INT nIndex
)
529 TRACE("(%p %d)\n", hdpa
, nIndex
);
534 WARN("no pointer array.\n");
537 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
538 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
542 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
544 return hdpa
->ptrs
[nIndex
];
548 /**************************************************************************
549 * DPA_GetPtrIndex [COMCTL32.333]
551 * Retrieves the index of the specified pointer
554 * hdpa [I] handle (pointer) to the pointer array
558 * Success: index of the specified pointer
561 INT WINAPI
DPA_GetPtrIndex (HDPA hdpa
, LPCVOID p
)
565 if (!hdpa
|| !hdpa
->ptrs
)
568 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
569 if (hdpa
->ptrs
[i
] == p
)
577 /**************************************************************************
578 * DPA_InsertPtr [COMCTL32.334]
580 * Inserts a pointer into a dynamic pointer array
583 * hdpa [I] handle (pointer) to the array
585 * p [I] pointer to insert
588 * Success: index of the inserted pointer
591 INT WINAPI
DPA_InsertPtr (HDPA hdpa
, INT i
, LPVOID p
)
593 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
595 if (!hdpa
|| i
< 0) return -1;
597 /* append item if index is out of bounds */
598 i
= min(hdpa
->nItemCount
, i
);
600 /* create empty spot at the end */
601 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
603 if (i
!= hdpa
->nItemCount
- 1)
604 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
,
605 (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
612 /**************************************************************************
613 * DPA_SetPtr [COMCTL32.335]
615 * Sets a pointer in the pointer array
618 * hdpa [I] handle (pointer) to the pointer array
619 * i [I] index of the pointer that will be set
620 * p [I] pointer to be set
626 BOOL WINAPI
DPA_SetPtr (HDPA hdpa
, INT i
, LPVOID p
)
630 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
635 if (hdpa
->nItemCount
<= i
) {
636 /* within the old array */
637 if (hdpa
->nMaxCount
<= i
) {
638 /* resize the block of memory */
640 hdpa
->nGrow
* ((((i
+1) - 1) / hdpa
->nGrow
) + 1);
641 INT nSize
= nNewItems
* sizeof(LPVOID
);
644 lpTemp
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
646 lpTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
651 hdpa
->nMaxCount
= nNewItems
;
654 hdpa
->nItemCount
= i
+1;
657 /* put the new entry in */
664 /**************************************************************************
665 * DPA_DeletePtr [COMCTL32.336]
667 * Removes a pointer from the pointer array.
670 * hdpa [I] handle (pointer) to the pointer array
671 * i [I] index of the pointer that will be deleted
674 * Success: deleted pointer
677 LPVOID WINAPI
DPA_DeletePtr (HDPA hdpa
, INT i
)
679 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
682 TRACE("(%p %d)\n", hdpa
, i
);
684 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
687 lpTemp
= hdpa
->ptrs
[i
];
689 /* do we need to move ?*/
690 if (i
< hdpa
->nItemCount
- 1) {
691 lpDest
= hdpa
->ptrs
+ i
;
693 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
694 TRACE("-- move dest=%p src=%p size=%x\n",
695 lpDest
, lpSrc
, nSize
);
696 memmove (lpDest
, lpSrc
, nSize
);
702 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
703 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
704 nSize
= nNewItems
* sizeof(LPVOID
);
705 lpDest
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
710 hdpa
->nMaxCount
= nNewItems
;
718 /**************************************************************************
719 * DPA_DeleteAllPtrs [COMCTL32.337]
721 * Removes all pointers and reinitializes the array.
724 * hdpa [I] handle (pointer) to the pointer array
730 BOOL WINAPI
DPA_DeleteAllPtrs (HDPA hdpa
)
732 TRACE("(%p)\n", hdpa
);
737 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
740 hdpa
->nItemCount
= 0;
741 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
742 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
743 hdpa
->nMaxCount
* sizeof(LPVOID
));
749 /**************************************************************************
750 * DPA_QuickSort [Internal]
752 * Ordinary quicksort (used by DPA_Sort).
755 * lpPtrs [I] pointer to the pointer array
756 * l [I] index of the "left border" of the partition
757 * r [I] index of the "right border" of the partition
758 * pfnCompare [I] pointer to the compare function
759 * lParam [I] user defined value (3rd parameter in compare function)
764 static VOID
DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
765 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
770 TRACE("l=%i r=%i\n", l
, r
);
772 if (l
==r
) /* one element is always sorted */
774 if (r
<l
) /* oops, got it in the wrong order */
776 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
779 m
= (l
+r
)/2; /* divide by two */
780 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
781 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
783 /* join the two sides */
784 while( (l
<=m
) && (m
<r
) )
786 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
789 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
799 /**************************************************************************
800 * DPA_Sort [COMCTL32.338]
802 * Sorts a pointer array using a user defined compare function
805 * hdpa [I] handle (pointer) to the pointer array
806 * pfnCompare [I] pointer to the compare function
807 * lParam [I] user defined value (3rd parameter of compare function)
813 BOOL WINAPI
DPA_Sort (HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
815 if (!hdpa
|| !pfnCompare
)
818 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
820 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
821 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
828 /**************************************************************************
829 * DPA_Search [COMCTL32.339]
831 * Searches a pointer array for a specified pointer
834 * hdpa [I] handle (pointer) to the pointer array
835 * pFind [I] pointer to search for
836 * nStart [I] start index
837 * pfnCompare [I] pointer to the compare function
838 * lParam [I] user defined value (3rd parameter of compare function)
839 * uOptions [I] search options
842 * Success: index of the pointer in the array.
845 INT WINAPI
DPA_Search (HDPA hdpa
, LPVOID pFind
, INT nStart
,
846 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
848 if (!hdpa
|| !pfnCompare
|| !pFind
)
851 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
852 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
854 if (uOptions
& DPAS_SORTED
) {
855 /* array is sorted --> use binary search */
859 /* for binary search ignore start index */
861 r
= hdpa
->nItemCount
- 1;
865 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
873 if (uOptions
& (DPAS_INSERTBEFORE
|DPAS_INSERTAFTER
)) return l
;
876 /* array is not sorted --> use linear search */
880 nIndex
= (nStart
== -1)? 0 : nStart
;
882 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
883 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0)
892 /**************************************************************************
893 * DPA_CreateEx [COMCTL32.340]
895 * Creates a dynamic pointer array using the specified size and heap.
898 * nGrow [I] number of items by which the array grows when it is filled
899 * hHeap [I] handle to the heap where the array is stored
902 * Success: handle (pointer) to the pointer array.
906 * The DPA_ functions can be used to create and manipulate arrays of
909 HDPA WINAPI
DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
913 TRACE("(%d %p)\n", nGrow
, hHeap
);
916 hdpa
= HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
918 hdpa
= Alloc (sizeof(*hdpa
));
921 hdpa
->nGrow
= max(8, nGrow
);
922 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
923 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
924 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
925 hdpa
->nMaxCount
* sizeof(LPVOID
));
928 TRACE("-- %p\n", hdpa
);
934 /**************************************************************************
935 * DPA_Create [COMCTL32.328]
937 * Creates a dynamic pointer array.
940 * nGrow [I] number of items by which the array grows when it is filled
943 * Success: handle (pointer) to the pointer array.
947 * The DPA_ functions can be used to create and manipulate arrays of
950 HDPA WINAPI
DPA_Create (INT nGrow
)
952 return DPA_CreateEx( nGrow
, 0 );
956 /**************************************************************************
957 * DPA_EnumCallback [COMCTL32.385]
959 * Enumerates all items in a dynamic pointer array.
962 * hdpa [I] handle to the dynamic pointer array
969 VOID WINAPI
DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
974 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
978 if (hdpa
->nItemCount
<= 0)
981 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
982 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
990 /**************************************************************************
991 * DPA_DestroyCallback [COMCTL32.386]
993 * Enumerates all items in a dynamic pointer array and destroys it.
996 * hdpa [I] handle to the dynamic pointer array
1003 void WINAPI
DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
1006 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
1008 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
1012 /**************************************************************************
1013 * DPA_GetSize [COMCTL32.@]
1015 * Returns all array allocated memory size
1018 * hdpa [I] handle to the dynamic pointer array
1023 ULONGLONG WINAPI
DPA_GetSize(HDPA hdpa
)
1025 TRACE("(%p)\n", hdpa
);
1027 if (!hdpa
) return 0;
1029 return sizeof(DPA
) + hdpa
->nMaxCount
*sizeof(PVOID
);