Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5740 lines
152 KiB

  1. /***************************************************************************************
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. DynArray.C
  5. Abstract:
  6. This module deals with the various functionalities such as creation of DynamicArrays, deletion of Dynamic Arrays,insertion
  7. of elements into Dynamic Arrays and various other related functionalities.
  8. Author:
  9. G.V.N Murali Sunil. 1-9-2000
  10. Revision History :
  11. ***************************************************************************************/
  12. #include "pch.h"
  13. #include "cmdline.h"
  14. //
  15. // constants / compiler defines / enumerations
  16. //
  17. // signatures
  18. #define _SIGNATURE_ARRAY 9
  19. #define _SIGNATURE_ITEM 99
  20. // hidden item types
  21. #define _TYPE_NEEDINIT DA_TYPE_NONE
  22. //
  23. // private structures ... structures declared in this area are not exposed to
  24. // the external world ... hidden structures
  25. //
  26. // represents array item
  27. typedef struct __tagItem
  28. {
  29. DWORD dwSignature; // signature ... used for validation
  30. DWORD dwType; // says the type of the current item
  31. DWORD dwSize; // size of the memory allocated
  32. LPVOID pValue; // value of the item ( address )
  33. struct __tagItem* pNext; // pointer to the next item
  34. } __TITEM;
  35. typedef __TITEM* __PTITEM; // pointer typedefintion
  36. // represents the array
  37. typedef struct __tagArray
  38. {
  39. DWORD dwSignature; // signature ... for validating pointer
  40. DWORD dwCount; // count of items in the array
  41. __PTITEM pStart; // pointer to the first item
  42. __PTITEM pLast; // pointer to the last item
  43. } __TARRAY;
  44. typedef __TARRAY* __PTARRAY; // pointer typedefintion
  45. //
  46. // private function(s) ... used only in this file
  47. //
  48. __PTITEM
  49. __DynArrayGetItem(
  50. TARRAY pArray,
  51. DWORD dwIndex,
  52. __PTITEM* ppPreviousItem
  53. )
  54. /*++
  55. Routine Description:
  56. To append any type of item into the Dynamic Array
  57. Arguments:
  58. [ in ] pArray - Dynamic Array containing the result
  59. [ in ] dwIndex - Index of the item
  60. [ in ] ppPreviousItem - pointer to the previous item.
  61. Return Value:
  62. Pointer to the structure containing the Item.
  63. --*/
  64. {
  65. // local variables
  66. DWORD i = 0 ;
  67. __PTITEM pItem = NULL;
  68. __PTITEM pPrevItem = NULL;
  69. __PTARRAY pArrayEx = NULL;
  70. // check whether the array is valid or not
  71. if ( FALSE == IsValidArray( pArray ) )
  72. {
  73. return NULL;
  74. }
  75. // convert the passed memory location info into appropriate structure
  76. pArrayEx = ( __PTARRAY ) pArray;
  77. // check the size of the array with the position of the item required
  78. // if the size is less, return NULL
  79. if ( pArrayEx->dwCount <= dwIndex )
  80. {
  81. return NULL;
  82. }
  83. // traverse thru the list and find the appropriate item
  84. pPrevItem = NULL;
  85. pItem = pArrayEx->pStart;
  86. for( i = 1; i <= dwIndex; i++ )
  87. {
  88. // store the current pointer and fetch the next pointer
  89. pPrevItem = pItem;
  90. pItem = pItem->pNext;
  91. }
  92. // if the previous pointer is also requested, update the previous pointer
  93. if ( NULL != ppPreviousItem ) { *ppPreviousItem = pPrevItem; }
  94. // now return the __TITEM pointer
  95. return pItem;
  96. }
  97. LONG
  98. __DynArrayAppend(
  99. TARRAY pArray,
  100. DWORD dwType,
  101. DWORD dwSize,
  102. LPVOID pValue
  103. )
  104. /*++
  105. Routine Description:
  106. To append any type of item into the Dynamic Array.
  107. Arguments:
  108. [ in ] pArray - Dynamic Array containing the result.
  109. [ in ] dwType - type of the item.
  110. [ in ] dwSize - Size of the item.
  111. [ in ] pValue - pointer to the Item.
  112. Return Value:
  113. If successfully added the item to the list then return index else -1.
  114. --*/
  115. {
  116. // local variables
  117. __PTITEM pItem = NULL;
  118. __PTARRAY pArrayEx = NULL;
  119. // check whether the array is valid or not
  120. if ( FALSE == IsValidArray( pArray ) )
  121. {
  122. return -1;
  123. }
  124. // convert the passed memory location info into appropriate structure
  125. pArrayEx = ( __PTARRAY ) pArray;
  126. // Check for overflow condition.
  127. if( ULONG_MAX == pArrayEx->dwCount )
  128. {
  129. return -1;
  130. }
  131. // create an item and check the result. if memory allocation failed, error
  132. pItem = ( __PTITEM ) AllocateMemory( sizeof( __TITEM ) );
  133. if ( NULL == pItem )
  134. {
  135. return -1;
  136. }
  137. // initialize the newly allocated item structure with appropriate data
  138. pItem->pNext = NULL;
  139. pItem->dwType = dwType;
  140. pItem->dwSize = dwSize;
  141. pItem->pValue = pValue;
  142. pItem->dwSignature = _SIGNATURE_ITEM;
  143. pArrayEx->dwCount++; // update the count of items in array info
  144. // now add the newly created item to the array at the end of the list
  145. if ( NULL == pArrayEx->pStart )
  146. {
  147. // first item in the array
  148. pArrayEx->pStart = pArrayEx->pLast = pItem;
  149. }
  150. else
  151. {
  152. // appending to the existing list
  153. pArrayEx->pLast->pNext = pItem;
  154. pArrayEx->pLast = pItem;
  155. }
  156. // successfully added the item to the list ... return index
  157. return ( pArrayEx->dwCount - 1 ); // count - 1 = index
  158. }
  159. LONG
  160. __DynArrayInsert(
  161. TARRAY pArray,
  162. DWORD dwIndex,
  163. DWORD dwType,
  164. DWORD dwSize,
  165. LPVOID pValue
  166. )
  167. /*++
  168. Routine Description:
  169. To insert an item into the Dynamic Array
  170. Arguments:
  171. [ in ] pArray - Dynamic Array containing the result
  172. [ in ] dwIndex - index of the item
  173. [ in ] dwType - type of the item
  174. [ in ] dwSize - Size to the Item.
  175. [ in ] pValue - pointer to the item.
  176. Return Value:
  177. If successfully added the item to the list then return index else -1
  178. --*/
  179. {
  180. // local variables
  181. DWORD i = 0;
  182. __PTITEM pItem = NULL;
  183. __PTITEM pBeforeInsert = NULL;
  184. __PTARRAY pArrayEx = NULL;
  185. // check whether the array is valid or not
  186. if ( FALSE == IsValidArray( pArray ) )
  187. {
  188. return -1;
  189. }
  190. // convert the passed memory location info into appropriate structure
  191. pArrayEx = ( __PTARRAY ) pArray;
  192. // Check for overflow condition.
  193. if( ULONG_MAX == pArrayEx->dwCount )
  194. {
  195. return -1;
  196. }
  197. // check the size of the array with the position of the insertion that has to be done
  198. // if the size is less, treat this call as just a call to Append function
  199. if ( pArrayEx->dwCount <= dwIndex )
  200. {
  201. return __DynArrayAppend( pArray, dwType, dwSize, pValue );
  202. }
  203. // create an item and check the result. if memory allocation failed, error
  204. pItem = ( __PTITEM ) AllocateMemory( sizeof( __TITEM ) );
  205. if ( NULL == pItem )
  206. {
  207. return -1;
  208. }
  209. // initialize the newly allocated item structure with appropriate data
  210. pItem->pNext = NULL;
  211. pItem->dwType = dwType;
  212. pItem->dwSize = dwSize;
  213. pItem->pValue = pValue;
  214. pItem->dwSignature = _SIGNATURE_ITEM;
  215. // update the count of the array items
  216. pArrayEx->dwCount++;
  217. // check whether the new item has to be added at the begining of the list
  218. if ( 0 == dwIndex )
  219. {
  220. // put the new item at the begining of the list
  221. pItem->pNext = pArrayEx->pStart;
  222. pArrayEx->pStart = pItem;
  223. // return as the operation is completed
  224. return TRUE;
  225. }
  226. // traverse thru the list and find the location where the insertion of
  227. // new element has to be done
  228. pBeforeInsert = pArrayEx->pStart;
  229. for( i = 0; i < dwIndex - 1; i++ )
  230. {
  231. pBeforeInsert = pBeforeInsert->pNext;
  232. }
  233. // insert the new item at the new location and update the chain
  234. pItem->pNext = pBeforeInsert->pNext;
  235. pBeforeInsert->pNext = pItem;
  236. // return as the operation is completed ... return index position
  237. return dwIndex; // passed index itself is return value
  238. }
  239. VOID
  240. __DynArrayFreeItemValue(
  241. __PTITEM pItem
  242. )
  243. /*++
  244. // ***************************************************************************
  245. Routine Description:
  246. Frees the items present in a Dynamic array
  247. Arguments:
  248. [ in ] pItem - pointer to the item to be freed
  249. Return Value:
  250. none
  251. --*/
  252. {
  253. // validate the pointer
  254. if ( NULL == pItem )
  255. {
  256. return;
  257. }
  258. // now free the items value based on its type
  259. switch( pItem->dwType )
  260. {
  261. case DA_TYPE_STRING:
  262. case DA_TYPE_LONG:
  263. case DA_TYPE_DWORD:
  264. case DA_TYPE_BOOL:
  265. case DA_TYPE_FLOAT:
  266. case DA_TYPE_DOUBLE:
  267. case DA_TYPE_HANDLE:
  268. case DA_TYPE_SYSTEMTIME:
  269. case DA_TYPE_FILETIME:
  270. FreeMemory( &( pItem->pValue ) ); // free the value
  271. break;
  272. case DA_TYPE_GENERAL:
  273. break; // user program itself should de-allocate memory for this item
  274. case _TYPE_NEEDINIT:
  275. break; // memory is not yet allocated for value of this item
  276. case DA_TYPE_ARRAY:
  277. // destroy the dynamic array
  278. DestroyDynamicArray( &pItem->pValue );
  279. pItem->pValue = NULL;
  280. break;
  281. default:
  282. break;
  283. }
  284. // return
  285. return;
  286. }
  287. LONG
  288. __DynArrayFind(
  289. TARRAY pArray,
  290. DWORD dwType,
  291. LPVOID pValue,
  292. BOOL bIgnoreCase,
  293. DWORD dwCount
  294. )
  295. /*++
  296. Routine Description:
  297. To find an item in the Dynamic Array
  298. Arguments:
  299. [ in ] pArray - Dynamic Array containing the result
  300. [ in ] dwType - type of the item
  301. [ in ] pValue - Conatains value of the new item.
  302. [ in ] bIgnoreCase - boolean indicating if the search is
  303. case-insensitive
  304. [ in ] dwCount - Contains number characters to compare
  305. for a string item.
  306. Return Value:
  307. If successfully found the item in the DynamicArray then return index
  308. -1 in case of error.
  309. --*/
  310. {
  311. // local variables
  312. DWORD dw = 0;
  313. __PTITEM pItem = NULL;
  314. __PTARRAY pArrayEx = NULL;
  315. // temp variables
  316. FILETIME* pFTime1 = NULL;
  317. FILETIME* pFTime2 = NULL;
  318. SYSTEMTIME* pSTime1 = NULL;
  319. SYSTEMTIME* pSTime2 = NULL;
  320. // validate the array
  321. if ( FALSE == IsValidArray( pArray ) )
  322. {
  323. return -1; // array is not valid
  324. }
  325. // get the reference to the actual array
  326. pArrayEx = ( __PTARRAY ) pArray;
  327. // now traverse thru the array and search for the requested value
  328. pItem = pArrayEx->pStart;
  329. for ( dw = 0; dw < pArrayEx->dwCount; pItem = pItem->pNext, dw++ )
  330. {
  331. // before checking the value, check the data type of the item
  332. if ( pItem->dwType != dwType )
  333. {
  334. continue; // item is not of needed type, skip this item
  335. }
  336. // now check the value of the item with the needed value
  337. switch ( dwType )
  338. {
  339. case DA_TYPE_LONG:
  340. {
  341. // value of type LONG
  342. if ( *( ( LONG* ) pItem->pValue ) == *( ( LONG* ) pValue ) )
  343. {
  344. return dw; // value matched
  345. }
  346. // break the case
  347. break;
  348. }
  349. case DA_TYPE_DWORD:
  350. {
  351. // value of type DWORD
  352. if ( *( ( DWORD* ) pItem->pValue ) == *( ( DWORD* ) pValue ) )
  353. {
  354. return dw; // value matched
  355. }
  356. // break the case
  357. break;
  358. }
  359. case DA_TYPE_FLOAT:
  360. {
  361. // value of type float
  362. if ( *( ( float* ) pItem->pValue ) == *( ( float* ) pValue ) )
  363. {
  364. return dw; // value matched
  365. }
  366. // break the case
  367. break;
  368. }
  369. case DA_TYPE_DOUBLE:
  370. {
  371. // value of type double
  372. if ( *( ( double* ) pItem->pValue ) == *( ( double* ) pValue ) )
  373. {
  374. return dw; // value matched
  375. }
  376. // break the case
  377. break;
  378. }
  379. case DA_TYPE_HANDLE:
  380. {
  381. // value of type HANDLE
  382. if ( *( ( HANDLE* ) pItem->pValue ) == *( ( HANDLE* ) pValue ) )
  383. {
  384. return dw; // value matched
  385. }
  386. // break the case
  387. break;
  388. }
  389. case DA_TYPE_STRING:
  390. {
  391. // value of type string
  392. if ( StringCompare( (LPCWSTR) pItem->pValue,
  393. (LPCWSTR) pValue, bIgnoreCase, dwCount ) == 0 )
  394. {
  395. return dw; // value matched
  396. }
  397. // break the case
  398. break;
  399. }
  400. case DA_TYPE_FILETIME:
  401. {
  402. // get the values ( for readability sake )
  403. pFTime1 = ( FILETIME* ) pValue;
  404. pFTime2 = ( FILETIME* ) pItem->pValue;
  405. if ( pFTime1->dwHighDateTime == pFTime2->dwHighDateTime &&
  406. pFTime1->dwLowDateTime == pFTime2->dwLowDateTime )
  407. {
  408. return dw; // value matched
  409. }
  410. // break the case
  411. break;
  412. }
  413. case DA_TYPE_SYSTEMTIME:
  414. {
  415. // get the values ( for readability sake )
  416. pSTime1 = ( SYSTEMTIME* ) pValue;
  417. pSTime2 = ( SYSTEMTIME* ) pItem->pValue;
  418. if ( pSTime1->wDay == pSTime2->wDay &&
  419. pSTime1->wDayOfWeek == pSTime1->wDayOfWeek &&
  420. pSTime1->wHour == pSTime1->wHour &&
  421. pSTime1->wMilliseconds == pSTime2->wMilliseconds &&
  422. pSTime1->wMinute == pSTime2->wMinute &&
  423. pSTime1->wMonth == pSTime2->wMonth &&
  424. pSTime1->wSecond == pSTime2->wSecond &&
  425. pSTime1->wYear == pSTime2->wYear )
  426. {
  427. return dw; // value matched
  428. }
  429. // break the case
  430. break;
  431. }
  432. default:
  433. {
  434. // just break ... nothin special to do
  435. break;
  436. }
  437. }
  438. }
  439. // value not found
  440. return -1;
  441. }
  442. LONG
  443. __DynArrayFindEx(
  444. TARRAY pArray,
  445. DWORD dwColumn,
  446. DWORD dwType,
  447. LPVOID pValue,
  448. BOOL bIgnoreCase,
  449. DWORD dwCount
  450. )
  451. /*++
  452. Routine Description:
  453. To find an item in the a 2 dimensional Dynamic Array .
  454. this function is private to this module only.
  455. Arguments:
  456. [ in ] pArray - Dynamic Array containing the result
  457. [ in ] dwColumn - The number of columns
  458. [ in ] dwType - type of the item
  459. [ in ] pValue - Size to the Item.
  460. [ in ] bIgnoreCase - boolean indicating if the search is case-insensitive
  461. [ in ] dwCount - used in case of string type comparisions. The number of
  462. characters that have to be compared in a particular column.
  463. Return Value:
  464. If successfully found the item in the DynamicArray then return index
  465. -1 in case of error.
  466. --*/
  467. {
  468. // local variables
  469. DWORD dw = 0;
  470. __PTITEM pItem = NULL;
  471. __PTITEM pColumn = NULL;
  472. __PTARRAY pArrayEx = NULL;
  473. // temp variables
  474. FILETIME* pFTime1 = NULL;
  475. FILETIME* pFTime2 = NULL;
  476. SYSTEMTIME* pSTime1 = NULL;
  477. SYSTEMTIME* pSTime2 = NULL;
  478. // validate the array
  479. if ( FALSE == IsValidArray( pArray ) )
  480. {
  481. return -1; // array is not valid
  482. }
  483. // get the reference to the actual array
  484. pArrayEx = ( __PTARRAY ) pArray;
  485. // now traverse thru the array and search for the requested value
  486. pItem = pArrayEx->pStart;
  487. for ( dw = 0; dw < pArrayEx->dwCount; pItem = pItem->pNext, dw++ )
  488. {
  489. // check whether the current value is of ARRAY type or not
  490. if ( DA_TYPE_ARRAY != pItem->dwType )
  491. {
  492. continue; // item is not of ARRAY type, skip this item
  493. }
  494. // now get the item at the required column
  495. pColumn = __DynArrayGetItem( pItem->pValue, dwColumn, NULL );
  496. if ( NULL == pColumn )
  497. {
  498. continue; // column not found ... skip this item
  499. }
  500. // get the type of the column value
  501. if ( pColumn->dwType != dwType )
  502. {
  503. continue; // column is not of needed type, skip this item also
  504. }
  505. // now check the value of the column with the needed value
  506. switch ( dwType )
  507. {
  508. case DA_TYPE_LONG:
  509. {
  510. // value of type LONG
  511. if ( *( ( LONG* ) pColumn->pValue ) == *( ( LONG* ) pValue ) )
  512. {
  513. return dw; // value matched
  514. }
  515. // break the case
  516. break;
  517. }
  518. case DA_TYPE_DWORD:
  519. {
  520. // value of type DWORD
  521. if ( *( ( DWORD* ) pColumn->pValue ) == *( ( DWORD* ) pValue ) )
  522. {
  523. return dw; // value matched
  524. }
  525. // break the case
  526. break;
  527. }
  528. case DA_TYPE_FLOAT:
  529. {
  530. // value of type float
  531. if ( *( ( float* ) pColumn->pValue ) == *( ( float* ) pValue ) )
  532. {
  533. return dw; // value matched
  534. }
  535. // break the case
  536. break;
  537. }
  538. case DA_TYPE_DOUBLE:
  539. {
  540. // value of type double
  541. if ( *( ( double* ) pColumn->pValue ) == *( ( double* ) pValue ) )
  542. {
  543. return dw; // value matched
  544. }
  545. // break the case
  546. break;
  547. }
  548. case DA_TYPE_HANDLE:
  549. {
  550. // value of type HANDLE
  551. if ( *( ( HANDLE* ) pColumn->pValue ) == *( ( HANDLE* ) pValue ) )
  552. {
  553. return dw; // value matched
  554. }
  555. // break the case
  556. break;
  557. }
  558. case DA_TYPE_STRING:
  559. {
  560. // value of type string
  561. if ( 0 == StringCompare( (LPCWSTR) pColumn->pValue,
  562. (LPCWSTR) pValue, bIgnoreCase, dwCount ) )
  563. {
  564. return dw; // value matched
  565. }
  566. // break the case
  567. break;
  568. }
  569. case DA_TYPE_FILETIME:
  570. {
  571. // get the values ( for readability sake )
  572. pFTime1 = ( FILETIME* ) pValue;
  573. pFTime2 = ( FILETIME* ) pItem->pValue;
  574. if ( pFTime1->dwHighDateTime == pFTime2->dwHighDateTime &&
  575. pFTime1->dwLowDateTime == pFTime2->dwLowDateTime )
  576. {
  577. return dw; // value matched
  578. }
  579. // break the case
  580. break;
  581. }
  582. case DA_TYPE_SYSTEMTIME:
  583. {
  584. // get the values ( for readability sake )
  585. pSTime1 = ( SYSTEMTIME* ) pValue;
  586. pSTime2 = ( SYSTEMTIME* ) pItem->pValue;
  587. if ( pSTime1->wDay == pSTime2->wDay &&
  588. pSTime1->wDayOfWeek == pSTime1->wDayOfWeek &&
  589. pSTime1->wHour == pSTime1->wHour &&
  590. pSTime1->wMilliseconds == pSTime2->wMilliseconds &&
  591. pSTime1->wMinute == pSTime2->wMinute &&
  592. pSTime1->wMonth == pSTime2->wMonth &&
  593. pSTime1->wSecond == pSTime2->wSecond &&
  594. pSTime1->wYear == pSTime2->wYear )
  595. {
  596. return dw; // value matched
  597. }
  598. // break the case
  599. break;
  600. }
  601. default:
  602. {
  603. // just break ... nothing special to do
  604. break;
  605. }
  606. }
  607. }
  608. // value not found
  609. return -1;
  610. }
  611. /*******************************************/
  612. /*** IMPLEMENTATION OF PUBLIC FUNCTIONS ***/
  613. /*******************************************/
  614. BOOL
  615. IsValidArray(
  616. TARRAY pArray
  617. )
  618. /*++
  619. Routine Description:
  620. Validate the array
  621. Arguments:
  622. [ in ] pArray - Dynamic Array
  623. Return Value:
  624. TRUE - if it is a valid array else FALSE
  625. --*/
  626. {
  627. // check the signature
  628. return ( ( NULL != pArray ) &&
  629. ( _SIGNATURE_ARRAY == ( ( __PTARRAY ) pArray )->dwSignature ) );
  630. }
  631. TARRAY
  632. CreateDynamicArray()
  633. /*++
  634. Routine Description:
  635. This function creates a dynamic array.
  636. Arguments:
  637. None.
  638. Return Value:
  639. pointer to the newly created array
  640. --*/
  641. {
  642. // local variables
  643. __PTARRAY pArray;
  644. // memory allocation ... array is being created
  645. pArray = ( __PTARRAY ) AllocateMemory( 1 * sizeof( __TARRAY ) );
  646. // check the allocation result
  647. if ( NULL == pArray )
  648. {
  649. return NULL;
  650. }
  651. // initialize the structure variables
  652. pArray->dwCount = 0;
  653. pArray->pStart = NULL;
  654. pArray->pLast = NULL;
  655. pArray->dwSignature = _SIGNATURE_ARRAY;
  656. // return array reference
  657. return pArray;
  658. }
  659. VOID
  660. DynArrayRemoveAll(
  661. TARRAY pArray
  662. )
  663. /*++
  664. Routine Description:
  665. traverse thru the Dynamic Array and delete elements one by one
  666. Arguments:
  667. [in] pArray - pointer to an array
  668. Return Value:
  669. None.
  670. --*/
  671. {
  672. // local variables
  673. __PTITEM pItem = NULL;
  674. __PTITEM pNextItem = NULL;
  675. __PTARRAY pArrayEx = NULL;
  676. // check whether the array is valid or not
  677. if ( FALSE == IsValidArray( pArray ) )
  678. {
  679. return;
  680. }
  681. // convert the passed memory location info into appropriate structure
  682. pArrayEx = ( __PTARRAY ) pArray;
  683. // traverse thru the list and delete elements one by one
  684. pItem = pArrayEx->pStart;
  685. while ( NULL != pItem )
  686. {
  687. pNextItem = pItem->pNext; // get the next item in the list
  688. __DynArrayFreeItemValue( pItem ); // free memory allocated for data
  689. FreeMemory( &pItem ); // now free the memory allocated for the current item
  690. pItem = pNextItem; // make the previously fetched next item as the current item
  691. }
  692. // as all the items are removed, reset the contents
  693. pArrayEx->dwCount = 0;
  694. pArrayEx->pStart = NULL;
  695. pArrayEx->pLast = NULL;
  696. // return
  697. return;
  698. }
  699. VOID
  700. DestroyDynamicArray(
  701. PTARRAY pArray
  702. )
  703. /*++
  704. Routine Description:
  705. Destory the Dynamic array and free the memory.
  706. Arguments:
  707. [in] pArray - Pointer to the Dynamic array.
  708. Return Value:
  709. none.
  710. --*/
  711. {
  712. // check whether the array is valid or not
  713. if ( FALSE == IsValidArray( *pArray ) )
  714. {
  715. return;
  716. }
  717. // remove all the elements in the array
  718. DynArrayRemoveAll( *pArray );
  719. // now free the memory allocated
  720. FreeMemory( pArray );
  721. }
  722. LONG
  723. DynArrayAppend(
  724. TARRAY pArray,
  725. LPVOID pValue
  726. )
  727. /*++
  728. Routine Description:
  729. To append any type of item into the Dynamic Array
  730. Arguments:
  731. [ in ] pArray - Dynamic Array containing the result
  732. [ in ] pValue - pointer to the Item.
  733. Return Value:
  734. If successfully added the item to the list then return index else -1
  735. --*/
  736. {
  737. // validate the pointer value
  738. if ( NULL == pValue )
  739. {
  740. return -1; // invalid memory address passed
  741. }
  742. // append the value and return the result
  743. return __DynArrayAppend( pArray, DA_TYPE_GENERAL, sizeof( LPVOID ), pValue );
  744. }
  745. LONG
  746. DynArrayAppendString(
  747. TARRAY pArray,
  748. LPCWSTR szValue,
  749. DWORD dwLength
  750. )
  751. /*++
  752. // ***************************************************************************
  753. Routine Description:
  754. To append a string into the Dynamic Array
  755. Arguments:
  756. [ in ] pArray - Dynamic Array containing the result
  757. [ in ] szValue - pointer to the string
  758. [ in ] dwLength - Length of the String to be passed.
  759. Return Value:
  760. If successfully added the item to the list then return index else -1
  761. --*/
  762. {
  763. // local variables
  764. LONG lIndex = -1;
  765. LPWSTR pszValue = NULL;
  766. __PTARRAY pArrayEx = NULL;
  767. // check whether the array is valid or not
  768. if ( FALSE == IsValidArray( pArray ) )
  769. {
  770. return -1;
  771. }
  772. // convert the passed memory location info into appropriate structure
  773. pArrayEx = ( __PTARRAY ) pArray;
  774. // determine the length of string ( memory ) that has to be allocated
  775. if ( 0 == dwLength )
  776. {
  777. dwLength = lstrlen( szValue );
  778. }
  779. // accomodate space for storing NULL character
  780. dwLength += 1;
  781. // allocate memory for value and check the result of memory allocation
  782. pszValue = ( LPWSTR ) AllocateMemory( dwLength * sizeof( WCHAR ) );
  783. if ( NULL == pszValue )
  784. {
  785. return -1;
  786. }
  787. // copy the contents of the string ( copy should be based on the length )
  788. StringCopy( pszValue, szValue, dwLength );
  789. // now add this item to the array
  790. lIndex = __DynArrayAppend( pArray, DA_TYPE_STRING, dwLength * sizeof( WCHAR ), pszValue );
  791. if ( -1 == lIndex )
  792. {
  793. // failed in adding this item to the array
  794. // so, free the memory allocated and return from the function
  795. FreeMemory( &pszValue );
  796. return -1;
  797. }
  798. // added the item to the array
  799. return lIndex;
  800. }
  801. LONG
  802. DynArrayAppendLong(
  803. TARRAY pArray,
  804. LONG lValue
  805. )
  806. /*++
  807. Routine Description:
  808. To append a variable of type Long into the Dynamic Array.
  809. Arguments:
  810. [ in ] pArray - Dynamic Array containing the result
  811. [ in ] lValue - Variable to be appended.
  812. Return Value:
  813. If successfully added the item to the list then return index else -1
  814. --*/
  815. {
  816. // local variables
  817. LONG lIndex = -1;
  818. PLONG plValue = NULL;
  819. // check whether the array is valid or not
  820. if ( FALSE == IsValidArray( pArray ) )
  821. {
  822. return -1;
  823. }
  824. // allocate memory for value and check the result of memory allocation
  825. plValue = ( LONG* ) AllocateMemory( sizeof( LONG ) );
  826. if ( NULL == plValue )
  827. {
  828. return -1;
  829. }
  830. // set the value
  831. *plValue = lValue;
  832. // now add this item value to the array
  833. lIndex = __DynArrayAppend( pArray, DA_TYPE_LONG, sizeof( LONG ), plValue );
  834. if ( -1 == lIndex )
  835. {
  836. // failed in adding this item to the array
  837. // so, free the memory allocated and return from the function
  838. FreeMemory( &plValue );
  839. return -1;
  840. }
  841. // added the item to the array
  842. return lIndex;
  843. }
  844. LONG
  845. DynArrayAppendDWORD(
  846. TARRAY pArray,
  847. DWORD dwValue
  848. )
  849. /*++
  850. Routine Description:
  851. To append a variable of type DWORD into the Dynamic Array.
  852. Arguments:
  853. [ in ] pArray - Dynamic Array containing the result
  854. [ in ] dwValue - DWORD type Variable to be appended.
  855. Return Value:
  856. If successfully added the item to the list then return index else -1
  857. --*/
  858. {
  859. // local variables
  860. LONG lIndex = -1;
  861. PDWORD pdwValue = NULL;
  862. // check whether the array is valid or not
  863. if ( FALSE == IsValidArray( pArray ) )
  864. {
  865. return -1;
  866. }
  867. // allocate memory for value and check the result of memory allocation
  868. pdwValue = ( DWORD* ) AllocateMemory( sizeof( DWORD ) );
  869. if ( NULL == pdwValue )
  870. {
  871. return -1;
  872. }
  873. // set the value
  874. *pdwValue = dwValue;
  875. // now add this item value to the array
  876. lIndex = __DynArrayAppend( pArray, DA_TYPE_DWORD, sizeof( DWORD ), pdwValue );
  877. if ( -1 == lIndex )
  878. {
  879. // failed in adding this item to the array
  880. // so, free the memory allocated and return from the function
  881. FreeMemory( &pdwValue );
  882. return -1;
  883. }
  884. // added the item to the array
  885. return lIndex;
  886. }
  887. LONG
  888. DynArrayAppendBOOL(
  889. TARRAY pArray,
  890. BOOL bValue
  891. )
  892. /*++
  893. Routine Description:
  894. To append a variable of type BOOL into the Dynamic Array
  895. Arguments:
  896. [ in ] pArray - Dynamic Array containing the result
  897. [ in ] bValue - BOOL type Variable to be appended.
  898. Return Value:
  899. If successfully added the item to the list then return index else -1
  900. --*/
  901. {
  902. // local variables
  903. LONG lIndex = -1;
  904. PBOOL pbValue = NULL;
  905. // check whether the array is valid or not
  906. if ( FALSE == IsValidArray( pArray ) )
  907. {
  908. return -1;
  909. }
  910. // allocate memory for value and check the result of memory allocation
  911. pbValue = ( PBOOL ) AllocateMemory( sizeof( BOOL ) );
  912. if ( NULL == pbValue )
  913. {
  914. return -1;
  915. }
  916. // set the value
  917. *pbValue = bValue;
  918. // now add this item value to the array
  919. lIndex = __DynArrayAppend( pArray, DA_TYPE_BOOL, sizeof( BOOL ), pbValue );
  920. if ( -1 == lIndex )
  921. {
  922. // failed in adding this item to the array
  923. // so, free the memory allocated and return from the function
  924. FreeMemory( &pbValue );
  925. return -1;
  926. }
  927. // added the item to the array
  928. return lIndex;
  929. }
  930. LONG
  931. DynArrayAppendFloat(
  932. TARRAY pArray,
  933. float fValue
  934. )
  935. /*++
  936. Routine Description:
  937. To append a variable of type Float into the Dynamic Array.
  938. Arguments:
  939. [ in ] pArray - Dynamic Array containing the result.
  940. [ in ] fValue - Float type Variable to be appended.
  941. Return Value:
  942. If successfully added the item to the list then return index else -1.
  943. --*/
  944. {
  945. // local variables
  946. LONG lIndex = -1;
  947. float* pfValue = NULL;
  948. // check whether the array is valid or not
  949. if ( FALSE == IsValidArray( pArray ) )
  950. {
  951. return -1;
  952. }
  953. // allocate memory for value and check the result of memory allocation
  954. pfValue = ( float* ) AllocateMemory( sizeof( float ) );
  955. if ( NULL == pfValue )
  956. {
  957. return -1;
  958. }
  959. // set the value
  960. *pfValue = fValue;
  961. // now add this item value to the array
  962. lIndex = __DynArrayAppend( pArray, DA_TYPE_FLOAT, sizeof( float ), pfValue );
  963. if ( -1 == lIndex )
  964. {
  965. // failed in adding this item to the array
  966. // so, free the memory allocated and return from the function
  967. FreeMemory( &pfValue );
  968. return -1;
  969. }
  970. // added the item to the array
  971. return lIndex;
  972. }
  973. LONG
  974. DynArrayAppendDouble(
  975. TARRAY pArray,
  976. double dblValue
  977. )
  978. /*++
  979. Routine Description:
  980. To append a variable of type Double into the Dynamic Array
  981. Arguments:
  982. [ in ] pArray - Dynamic Array containing the result
  983. [ in ] dblValue - Double type Variable to be appended.
  984. Return Value:
  985. If successfully added the item to the list then return index else -1
  986. --*/
  987. {
  988. // local variables
  989. LONG lIndex = -1;
  990. double* pdblValue = NULL;
  991. // check whether the array is valid or not
  992. if ( FALSE == IsValidArray( pArray ) )
  993. {
  994. return -1;
  995. }
  996. // allocate memory for value and check the result of memory allocation
  997. pdblValue = ( double* ) AllocateMemory( sizeof( double ) );
  998. if ( NULL == pdblValue )
  999. {
  1000. return -1;
  1001. }
  1002. // set the value
  1003. *pdblValue = dblValue;
  1004. // now add this item value to the array
  1005. lIndex = __DynArrayAppend( pArray, DA_TYPE_DOUBLE, sizeof( double ), pdblValue );
  1006. if ( -1 == lIndex )
  1007. {
  1008. // failed in adding this item to the array
  1009. // so, free the memory allocated and return from the function
  1010. FreeMemory( &pdblValue );
  1011. return -1;
  1012. }
  1013. // added the item to the array
  1014. return lIndex;
  1015. }
  1016. LONG
  1017. DynArrayAppendHandle(
  1018. TARRAY pArray,
  1019. HANDLE hValue
  1020. )
  1021. /*++
  1022. Routine Description:
  1023. To append a variable of type HANDLE into the Dynamic Array
  1024. Arguments:
  1025. [ in ] pArray - Dynamic Array containing the result
  1026. [ in ] hValue - HANDLE to be appended.
  1027. Return Value:
  1028. If successfully added the item to the list then return index else -1.
  1029. --*/
  1030. {
  1031. // local variables
  1032. LONG lIndex = -1;
  1033. HANDLE* phValue = NULL;
  1034. // check whether the array is valid or not
  1035. if ( FALSE == IsValidArray( pArray ) )
  1036. {
  1037. return -1;
  1038. }
  1039. // allocate memory for value and check the result of memory allocation
  1040. phValue = ( HANDLE* ) AllocateMemory( sizeof( HANDLE ) );
  1041. if ( NULL == phValue )
  1042. {
  1043. return -1;
  1044. }
  1045. // set the value
  1046. *phValue = hValue;
  1047. // now add this item value to the array
  1048. lIndex = __DynArrayAppend( pArray, DA_TYPE_HANDLE, sizeof( HANDLE ), phValue );
  1049. if ( -1 == lIndex )
  1050. {
  1051. // failed in adding this item to the array
  1052. // so, free the memory allocated and return from the function
  1053. FreeMemory( ( LPVOID * )&phValue );
  1054. return -1;
  1055. }
  1056. // added the item to the array
  1057. return lIndex;
  1058. }
  1059. LONG
  1060. DynArrayAppendFileTime(
  1061. TARRAY pArray,
  1062. FILETIME ftValue
  1063. )
  1064. /*++
  1065. Routine Description:
  1066. To append a variable of type FILETIME into the Dynamic Array
  1067. Arguments:
  1068. [ in ] pArray - Dynamic Array containing the result
  1069. [ in ] ftValue - FILETIME to be appended.
  1070. Return Value:
  1071. If successfully added the item to the list then return index else -1
  1072. --*/
  1073. {
  1074. // local variables
  1075. LONG lIndex = -1;
  1076. FILETIME* pftValue = NULL;
  1077. // check whether the array is valid or not
  1078. if ( FALSE == IsValidArray( pArray ) )
  1079. {
  1080. return -1;
  1081. }
  1082. // allocate memory for value and check the result of memory allocation
  1083. pftValue = ( FILETIME* ) AllocateMemory( sizeof( FILETIME ) );
  1084. if ( NULL == pftValue )
  1085. {
  1086. return -1;
  1087. }
  1088. // set the value
  1089. *pftValue = ftValue;
  1090. // now add this item value to the array
  1091. lIndex = __DynArrayAppend( pArray, DA_TYPE_FILETIME, sizeof( FILETIME ), pftValue );
  1092. if ( -1 == lIndex )
  1093. {
  1094. // failed in adding this item to the array
  1095. // so, free the memory allocated and return from the function
  1096. FreeMemory( &pftValue );
  1097. return -1;
  1098. }
  1099. // added the item to the array
  1100. return lIndex;
  1101. }
  1102. LONG
  1103. DynArrayAppendSystemTime(
  1104. TARRAY pArray,
  1105. SYSTEMTIME stValue
  1106. )
  1107. /*++
  1108. Routine Description:
  1109. To append a variable of type SYSTEMTIME into the Dynamic Array
  1110. Arguments:
  1111. [ in ] pArray - Dynamic Array containing the result
  1112. [ in ] stValue - variable of type SYSTEMTIME to be appended.
  1113. Return Value:
  1114. If successfully added the item to the list then return index else -1
  1115. --*/
  1116. {
  1117. // local variables
  1118. LONG lIndex = -1;
  1119. SYSTEMTIME* pstValue = NULL;
  1120. // check whether the array is valid or not
  1121. if ( FALSE == IsValidArray( pArray ) )
  1122. {
  1123. return -1;
  1124. }
  1125. // allocate memory for value and check the result of memory allocation
  1126. pstValue = ( SYSTEMTIME* ) AllocateMemory( sizeof( SYSTEMTIME ) );
  1127. if ( NULL == pstValue )
  1128. {
  1129. return -1;
  1130. }
  1131. // set the value
  1132. *pstValue = stValue;
  1133. // now add this item value to the array
  1134. lIndex = __DynArrayAppend( pArray, DA_TYPE_SYSTEMTIME, sizeof( SYSTEMTIME ), pstValue );
  1135. if ( -1 == lIndex )
  1136. {
  1137. // failed in adding this item to the array
  1138. // so, free the memory allocated and return from the function
  1139. FreeMemory( &pstValue );
  1140. return -1;
  1141. }
  1142. // added the item to the array
  1143. return lIndex;
  1144. }
  1145. LONG
  1146. DynArrayAppendRow(
  1147. TARRAY pArray,
  1148. DWORD dwColumns
  1149. )
  1150. /*++
  1151. Routine Description:
  1152. To add a empty Row to the 2-dimensional Dynamic array
  1153. Arguments:
  1154. [ in ] pArray - Dynamic Array
  1155. [ in ] dwColumns - No of columns the Row contains.
  1156. Return Value:
  1157. return the row number of the newly added row if successful else -1.
  1158. --*/
  1159. {
  1160. // local variables
  1161. DWORD dw = 0;
  1162. LONG lIndex = -1;
  1163. TARRAY arrSubArray = NULL;
  1164. // validate the array
  1165. if ( FALSE == IsValidArray( pArray ) )
  1166. {
  1167. return -1; // array is not valid
  1168. }
  1169. // create the dynamic array
  1170. arrSubArray = CreateDynamicArray();
  1171. if ( FALSE == IsValidArray( arrSubArray ) )
  1172. {
  1173. return -1; // failed in creating the dynamic array
  1174. }
  1175. // add the required no. of columns to the sub array
  1176. for( dw = 0; dw < dwColumns; dw++ )
  1177. {
  1178. // add the dummy item to the array and check the result
  1179. // if operation failed, break
  1180. if ( -1 == __DynArrayAppend( arrSubArray, _TYPE_NEEDINIT, 0, NULL ) )
  1181. {
  1182. break;
  1183. }
  1184. }
  1185. // check whether the operation is successfull or not
  1186. if ( dw != dwColumns )
  1187. {
  1188. // adding of columns failed
  1189. // destroy the dynamic array and return
  1190. DestroyDynamicArray( &arrSubArray );
  1191. return -1;
  1192. }
  1193. // now add this sub array to the main array and check the result
  1194. lIndex = __DynArrayAppend( pArray, DA_TYPE_ARRAY, sizeof( TARRAY ), arrSubArray );
  1195. if ( -1 == lIndex )
  1196. {
  1197. // failed in attaching the sub array to the main array
  1198. // destroy the dynamic array and return failure
  1199. DestroyDynamicArray( &arrSubArray );
  1200. return -1;
  1201. }
  1202. // operation is successfull
  1203. return lIndex;
  1204. }
  1205. LONG
  1206. DynArrayAddColumns(
  1207. TARRAY pArray,
  1208. DWORD dwColumns
  1209. )
  1210. /*++
  1211. Routine Description:
  1212. To add 'n' no. of columns to the array
  1213. Arguments:
  1214. [ in ] pArray - Dynamic Array
  1215. [ in ] dwColumns - No of columns the Row contains.
  1216. Return Value:
  1217. returns the no. of columns added
  1218. --*/
  1219. {
  1220. // local variables
  1221. DWORD dw = 0;
  1222. // validate the array
  1223. if ( FALSE == IsValidArray( pArray ) )
  1224. {
  1225. return -1; // array is not valid
  1226. }
  1227. // add the required no. of columns to the sub array
  1228. for( dw = 0; dw < dwColumns; dw++ )
  1229. {
  1230. // add the dummy item to the array and check the result
  1231. // if operation failed, break
  1232. if ( -1 == __DynArrayAppend( pArray, _TYPE_NEEDINIT, 0, NULL ) )
  1233. {
  1234. break;
  1235. }
  1236. }
  1237. // finish ...
  1238. return dw;
  1239. }
  1240. LONG
  1241. DynArrayInsertColumns(
  1242. TARRAY pArray,
  1243. DWORD dwIndex,
  1244. DWORD dwColumns
  1245. )
  1246. /*++
  1247. Routine Description:
  1248. inserts 'n' no. of columns to the array at the n'th location
  1249. Arguments:
  1250. [ in ] pArray - Dynamic Array
  1251. [ in ] dwColumns - No of columns the Row contains.
  1252. Return Value:
  1253. returns the no. of columns added
  1254. --*/
  1255. {
  1256. // local variables
  1257. DWORD dw = 0;
  1258. // validate the array
  1259. if ( FALSE == IsValidArray( pArray ) )
  1260. {
  1261. return -1; // array is not valid
  1262. }
  1263. // add the required no. of columns to the sub array
  1264. for( dw = 0; dw < dwColumns; dw++ )
  1265. {
  1266. // add the dummy item to the array and check the result
  1267. // if operation failed, break
  1268. if ( -1 == __DynArrayInsert( pArray, dwIndex, _TYPE_NEEDINIT, 0, NULL ) )
  1269. {
  1270. break;
  1271. }
  1272. }
  1273. // finish ...
  1274. return dw;
  1275. }
  1276. LONG
  1277. DynArrayAppend2(
  1278. TARRAY pArray,
  1279. DWORD dwRow,
  1280. LPVOID pValue
  1281. )
  1282. /*++
  1283. Routine Description:
  1284. To append a variable to a row in a 2-dimensional Dynamic array
  1285. Arguments:
  1286. [ in ] pArray - Dynamic Array
  1287. [ in ] dwRow - Specifies the row posn for which the new value
  1288. is to be added.
  1289. [ in ] pValue - pointer to the value
  1290. Return Value:
  1291. -1 on failure
  1292. index in the case of success.
  1293. --*/
  1294. {
  1295. // local variables
  1296. __PTITEM pItem = NULL;
  1297. // get the item at the required row
  1298. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1299. if ( ( NULL == pItem ) ||
  1300. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1301. {
  1302. return -1; // no item exists at the specified row or item is not of type array
  1303. }
  1304. // now add the value to the sub array and return the result to the caller
  1305. return DynArrayAppend( pItem->pValue, pValue );
  1306. }
  1307. LONG
  1308. DynArrayAppendString2(
  1309. TARRAY pArray,
  1310. DWORD dwRow,
  1311. LPCWSTR szValue,
  1312. DWORD dwLength
  1313. )
  1314. /*++
  1315. Routine Description:
  1316. To append a string variable to a 2-dimensional Dynamic array
  1317. Arguments:
  1318. [ in ] pArray - Dynamic Array
  1319. [ in ] dwRow - Specifies the row posn for which the new value
  1320. is to be added.
  1321. [ in ] szValue - pointer to the string value
  1322. [ in ] dwLength - length of the string.
  1323. Return Value:
  1324. LONG value on success -1 on failure.
  1325. --*/
  1326. {
  1327. // local variables
  1328. __PTITEM pItem = NULL;
  1329. // get the item at the required row
  1330. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1331. if ( ( NULL == pItem ) ||
  1332. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1333. {
  1334. return -1; // no item exists at the specified row or item is not of type array
  1335. }
  1336. // now add the string to the sub array and return the result to the caller
  1337. return DynArrayAppendString( pItem->pValue, szValue, dwLength );
  1338. }
  1339. LONG
  1340. DynArrayAppendLong2(
  1341. TARRAY pArray,
  1342. DWORD dwRow,
  1343. LONG lValue
  1344. )
  1345. /*++
  1346. Routine Description:
  1347. To append a long type variable to a row in a 2-dimensional Dynamic array
  1348. Arguments:
  1349. [ in ] pArray - Dynamic Array
  1350. [ in ] dwRow - Specifies the row posn for which the new value
  1351. is to be added.
  1352. [ in ] lValue - long type value to be appended.
  1353. Return Value:
  1354. -1 on failure
  1355. index in the case of success.
  1356. --*/
  1357. {
  1358. // local variables
  1359. __PTITEM pItem = NULL;
  1360. // get the item at the required row
  1361. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1362. if ( ( NULL == pItem ) ||
  1363. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1364. {
  1365. return -1; // no item exists at the specified row or item is not of type array
  1366. }
  1367. // now add the string to the sub array and return the result to the caller
  1368. return DynArrayAppendLong( pItem->pValue, lValue );
  1369. }
  1370. LONG
  1371. DynArrayAppendDWORD2(
  1372. TARRAY pArray,
  1373. DWORD dwRow,
  1374. DWORD dwValue
  1375. )
  1376. /*++
  1377. Routine Description:
  1378. To append a DWORD type variable to a row in a 2-dimensional Dynamic array
  1379. Arguments:
  1380. [ in ] pArray - Dynamic Array
  1381. [ in ] dwRow - Specifies the row posn for which the new value
  1382. is to be added.
  1383. [ in ] dwValue - DWORD type value to be appended.
  1384. Return Value:
  1385. -1 on failure
  1386. index in the case of success.
  1387. --*/
  1388. {
  1389. // local variables
  1390. __PTITEM pItem = NULL;
  1391. // get the item at the required row
  1392. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1393. if ( ( NULL == pItem ) ||
  1394. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1395. {
  1396. return -1; // no item exists at the specified row or item is not of type array
  1397. }
  1398. // now add the string to the sub array and return the result to the caller
  1399. return DynArrayAppendDWORD( pItem->pValue, dwValue );
  1400. }
  1401. LONG
  1402. DynArrayAppendBOOL2(
  1403. TARRAY pArray,
  1404. DWORD dwRow,
  1405. BOOL bValue
  1406. )
  1407. /*++
  1408. Routine Description:
  1409. To append a BOOL type variable to a row in a 2-dimensional Dynamic array
  1410. Arguments:
  1411. [ in ] pArray - Dynamic Array
  1412. [ in ] dwRow - Specifies the row posn for which the new value
  1413. is to be added.
  1414. [ in ] bValue - BOOL type value to be appended.
  1415. Return Value:
  1416. -1 on failure
  1417. index in the case of success.
  1418. --*/
  1419. {
  1420. // local variables
  1421. __PTITEM pItem = NULL;
  1422. // get the item at the required row
  1423. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1424. if ( ( NULL == pItem ) ||
  1425. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1426. {
  1427. return -1; // no item exists at the specified row or item is not of type array
  1428. }
  1429. // now add the string to the sub array and return the result to the caller
  1430. return DynArrayAppendBOOL( pItem->pValue, bValue );
  1431. }
  1432. LONG
  1433. DynArrayAppendFloat2(
  1434. TARRAY pArray,
  1435. DWORD dwRow,
  1436. float fValue
  1437. )
  1438. /*++
  1439. Routine Description:
  1440. To append a Float type variable to a row in a 2-dimensional Dynamic array
  1441. Arguments:
  1442. [ in ] pArray - Dynamic Array
  1443. [ in ] dwRow - Specifies the row posn for which the new value
  1444. is to be added.
  1445. [ in ] fValue - Float type value to be appended.
  1446. Return Value:
  1447. -1 on failure
  1448. index in the case of success.
  1449. --*/
  1450. {
  1451. // local variables
  1452. __PTITEM pItem = NULL;
  1453. // get the item at the required row
  1454. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1455. if ( ( NULL == pItem ) ||
  1456. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1457. {
  1458. return -1; // no item exists at the specified row or item is not of type array
  1459. }
  1460. // now add the string to the sub array and return the result to the caller
  1461. return DynArrayAppendFloat( pItem->pValue, fValue );
  1462. }
  1463. LONG
  1464. DynArrayAppendDouble2(
  1465. TARRAY pArray,
  1466. DWORD dwRow,
  1467. double dblValue
  1468. )
  1469. /*++
  1470. Routine Description:
  1471. To append a double type variable to a row in a 2-dimensional Dynamic array
  1472. Arguments:
  1473. [ in ] pArray - Dynamic Array
  1474. [ in ] dwRow - Specifies the row posn for which the new value
  1475. is to be added.
  1476. [ in ] dblValue - dblValue type value to be appended.
  1477. Return Value:
  1478. -1 on failure
  1479. index in the case of success.
  1480. --*/
  1481. {
  1482. // local variables
  1483. __PTITEM pItem = NULL;
  1484. // get the item at the required row
  1485. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1486. if ( ( NULL == pItem ) ||
  1487. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1488. {
  1489. return -1; // no item exists at the specified row or item is not of type array
  1490. }
  1491. // now add the string to the sub array and return the result to the caller
  1492. return DynArrayAppendDouble( pItem->pValue, dblValue );
  1493. }
  1494. LONG
  1495. DynArrayAppendHandle2(
  1496. TARRAY pArray,
  1497. DWORD dwRow,
  1498. HANDLE hValue
  1499. )
  1500. /*++
  1501. Routine Description:
  1502. To append a Handle type variable to a row in a 2-dimensional Dynamic array
  1503. Arguments:
  1504. [ in ] pArray - Dynamic Array
  1505. [ in ] dwRow - Specifies the row posn for which the new value
  1506. is to be added.
  1507. [ in ] hValue - Handle value to be appended.
  1508. Return Value:
  1509. -1 on failure
  1510. index in the case of success.
  1511. --*/
  1512. {
  1513. // local variables
  1514. __PTITEM pItem = NULL;
  1515. // get the item at the required row
  1516. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1517. if ( ( NULL == pItem ) ||
  1518. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1519. {
  1520. return -1; // no item exists at the specified row or item is not of type array
  1521. }
  1522. // now add the string to the sub array and return the result to the caller
  1523. return DynArrayAppendHandle( pItem->pValue, hValue );
  1524. }
  1525. LONG
  1526. DynArrayAppendFileTime2(
  1527. TARRAY pArray,
  1528. DWORD dwRow,
  1529. FILETIME ftValue
  1530. )
  1531. /*++
  1532. Routine Description:
  1533. To append a FILETIME type variable to a row in a 2-dimensional Dynamic array
  1534. Arguments:
  1535. [ in ] pArray - Dynamic Array
  1536. [ in ] dwRow - Specifies the row posn for which the new value
  1537. is to be added.
  1538. [ in ] ftValue - variable of type FILETIME to be appended.
  1539. Return Value:
  1540. -1 on failure
  1541. index in the case of success.
  1542. --*/
  1543. {
  1544. // local variables
  1545. __PTITEM pItem = NULL;
  1546. // get the item at the required row
  1547. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1548. if ( ( NULL == pItem ) ||
  1549. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1550. {
  1551. return -1; // no item exists at the specified row or item is not of type array
  1552. }
  1553. // now add the string to the sub array and return the result to the caller
  1554. return DynArrayAppendFileTime( pItem->pValue, ftValue );
  1555. }
  1556. LONG
  1557. DynArrayAppendSystemTime2(
  1558. TARRAY pArray,
  1559. DWORD dwRow,
  1560. SYSTEMTIME stValue
  1561. )
  1562. /*++
  1563. Routine Description:
  1564. To append a SYSTEMTIME type variable to a row in a 2-dimensional Dynamic array
  1565. Arguments:
  1566. [ in ] pArray - Dynamic Array
  1567. [ in ] dwRow - Specifies the row posn for which the new value
  1568. is to be added.
  1569. [ in ] stValue - variable of type SYSTEMTIME to be appended.
  1570. Return Value:
  1571. -1 on failure
  1572. index in the case of success.
  1573. --*/
  1574. {
  1575. // local variables
  1576. __PTITEM pItem = NULL;
  1577. // get the item at the required row
  1578. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  1579. if ( ( NULL == pItem ) ||
  1580. ( DA_TYPE_ARRAY != pItem->dwType ) )
  1581. {
  1582. return -1; // no item exists at the specified row or item is not of type array
  1583. }
  1584. // now add the string to the sub array and return the result to the caller
  1585. return DynArrayAppendSystemTime( pItem->pValue, stValue );
  1586. }
  1587. LONG
  1588. DynArrayInsert(
  1589. TARRAY pArray,
  1590. DWORD dwIndex,
  1591. LPVOID pValue
  1592. )
  1593. /*++
  1594. Routine Description:
  1595. To insert a variable into a Dynamic array
  1596. Arguments:
  1597. [ in ] pArray - Dynamic Array
  1598. [ in ] dwIndex - Specifies the index.
  1599. [ in ] pValue - value to be inserted.
  1600. Return Value:
  1601. -1 on failure
  1602. index in the case of success.
  1603. --*/
  1604. {
  1605. // validate the pointer value
  1606. if ( NULL == pValue )
  1607. {
  1608. return -1; // invalid memory address passed
  1609. }
  1610. // append the value and return the result
  1611. return __DynArrayInsert( pArray, dwIndex, DA_TYPE_GENERAL, sizeof( LPVOID ), pValue );
  1612. }
  1613. LONG
  1614. DynArrayInsertString(
  1615. TARRAY pArray,
  1616. DWORD dwIndex,
  1617. LPCWSTR szValue,
  1618. DWORD dwLength
  1619. )
  1620. /*++
  1621. Routine Description:
  1622. To insert a string type variable into a Dynamic array
  1623. Arguments:
  1624. [ in ] pArray - Dynamic Array
  1625. [ in ] dwIndex - Specifies the index.
  1626. [ in ] szValue - pointer to the string
  1627. [ in ] dwLength - length of the string.
  1628. Return Value:
  1629. -1 on failure
  1630. index in the case of success.
  1631. --*/
  1632. {
  1633. // local variables
  1634. LONG lIndex = -1;
  1635. LPWSTR pszValue = NULL;
  1636. // check whether the array is valid or not
  1637. if ( FALSE == IsValidArray( pArray ) )
  1638. {
  1639. return -1;
  1640. }
  1641. // determine the length of string ( memory ) that has to be allocated
  1642. if ( 0 == dwLength )
  1643. {
  1644. dwLength = lstrlen( szValue );
  1645. }
  1646. // accomodate space for storing NULL character
  1647. dwLength += 1;
  1648. // allocate memory for and check the result of memory allocation
  1649. pszValue = ( LPWSTR ) AllocateMemory( dwLength * sizeof( WCHAR ) );
  1650. if ( NULL == pszValue )
  1651. {
  1652. return -1;
  1653. }
  1654. // copy the contents of the string ( copy should be based on the length )
  1655. StringCopy( pszValue, szValue, dwLength );
  1656. // now add this item value to the array
  1657. lIndex = __DynArrayInsert( pArray, dwIndex,
  1658. DA_TYPE_STRING, dwLength * sizeof( WCHAR ), pszValue );
  1659. if ( -1 == lIndex )
  1660. {
  1661. // failed in adding this item to the array
  1662. // so, free the memory allocated and return from the function
  1663. FreeMemory( &pszValue );
  1664. return -1;
  1665. }
  1666. // added the item to the array
  1667. return lIndex;
  1668. }
  1669. LONG
  1670. DynArrayInsertLong(
  1671. TARRAY pArray,
  1672. DWORD dwIndex,
  1673. LONG lValue
  1674. )
  1675. /*++
  1676. Routine Description:
  1677. To insert a string type variable into a Dynamic array
  1678. Arguments:
  1679. [ in ] pArray - Dynamic Array
  1680. [ in ] dwIndex - Specifies the index.
  1681. [ in ] lValue - pointer to the string.
  1682. Return Value:
  1683. -1 on failure
  1684. index in the case of success.
  1685. --*/
  1686. {
  1687. // local variables
  1688. LONG lIndex = -1;
  1689. PLONG plValue = NULL;
  1690. // check whether the array is valid or not
  1691. if ( FALSE == IsValidArray( pArray ) )
  1692. {
  1693. return -1;
  1694. }
  1695. // allocate memory for value and check the result of memory allocation
  1696. plValue = ( LONG* ) AllocateMemory( sizeof( LONG ) );
  1697. if ( NULL == plValue )
  1698. {
  1699. return -1;
  1700. }
  1701. // set the value
  1702. *plValue = lValue;
  1703. // now add this item value to the array
  1704. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_LONG, sizeof( LONG ), plValue );
  1705. if ( -1 == lIndex )
  1706. {
  1707. // failed in adding this item to the array
  1708. // so, free the memory allocated and return from the function
  1709. FreeMemory( &plValue );
  1710. return -1;
  1711. }
  1712. // added the item to the array
  1713. return lIndex;
  1714. }
  1715. LONG
  1716. DynArrayInsertDWORD(
  1717. TARRAY pArray,
  1718. DWORD dwIndex,
  1719. DWORD dwValue
  1720. )
  1721. /*++
  1722. Routine Description:
  1723. To insert a DWORD type variable into a Dynamic array
  1724. Arguments:
  1725. [ in ] pArray - Dynamic Array
  1726. [ in ] dwIndex - Specifies the index.
  1727. [ in ] dwValue - specifies the variable to be inserted.
  1728. Return Value:
  1729. -1 on failure
  1730. index in the case of success.
  1731. --*/
  1732. {
  1733. // local variables
  1734. LONG lIndex = -1;
  1735. PDWORD pdwValue = NULL;
  1736. // check whether the array is valid or not
  1737. if ( FALSE == IsValidArray( pArray ) )
  1738. {
  1739. return -1;
  1740. }
  1741. // allocate memory for value and check the result of memory allocation
  1742. pdwValue = ( PDWORD ) AllocateMemory( sizeof( DWORD ) );
  1743. if ( NULL == pdwValue )
  1744. {
  1745. return -1;
  1746. }
  1747. // set the value
  1748. *pdwValue = dwValue;
  1749. // now add this item value to the array
  1750. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_DWORD, sizeof( DWORD ), pdwValue );
  1751. if ( -1 == lIndex )
  1752. {
  1753. // failed in adding this item to the array
  1754. // so, free the memory allocated and return from the function
  1755. FreeMemory( &pdwValue );
  1756. return -1;
  1757. }
  1758. // added the item to the array
  1759. return lIndex;
  1760. }
  1761. LONG
  1762. DynArrayInsertBOOL(
  1763. TARRAY pArray,
  1764. DWORD dwIndex,
  1765. BOOL bValue
  1766. )
  1767. /*++
  1768. Routine Description:
  1769. To insert a BOOL type variable into a Dynamic array
  1770. Arguments:
  1771. [ in ] pArray - Dynamic Array
  1772. [ in ] dwIndex - Specifies the index.
  1773. [ in ] bValue - specifies the BOOL variable to be inserted.
  1774. Return Value:
  1775. -1 on failure
  1776. index in the case of success.
  1777. --*/
  1778. {
  1779. // local variables
  1780. LONG lIndex = -1;
  1781. PBOOL pbValue = NULL;
  1782. // check whether the array is valid or not
  1783. if ( FALSE == IsValidArray( pArray ) )
  1784. {
  1785. return -1;
  1786. }
  1787. // allocate memory for value and check the result of memory allocation
  1788. pbValue = ( PBOOL ) AllocateMemory( sizeof( BOOL ) );
  1789. if ( NULL == pbValue )
  1790. {
  1791. return -1;
  1792. }
  1793. // set the value
  1794. *pbValue = bValue;
  1795. // now add this item value to the array
  1796. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_BOOL, sizeof( BOOL ), pbValue );
  1797. if ( -1 == lIndex )
  1798. {
  1799. // failed in adding this item to the array
  1800. // so, free the memory allocated and return from the function
  1801. FreeMemory( &pbValue );
  1802. return -1;
  1803. }
  1804. // added the item to the array
  1805. return lIndex;
  1806. }
  1807. LONG
  1808. DynArrayInsertFloat(
  1809. TARRAY pArray,
  1810. DWORD dwIndex,
  1811. float fValue
  1812. )
  1813. /*++
  1814. Routine Description:
  1815. To insert a float type variable into a Dynamic array
  1816. Arguments:
  1817. [ in ] pArray - Dynamic Array
  1818. [ in ] dwIndex - Specifies the index.
  1819. [ in ] fValue - specifies the float type variable to be inserted.
  1820. Return Value:
  1821. -1 on failure
  1822. index in the case of success.
  1823. --*/
  1824. {
  1825. // local variables
  1826. LONG lIndex = -1;
  1827. float* pfValue = NULL;
  1828. // check whether the array is valid or not
  1829. if ( FALSE == IsValidArray( pArray ) )
  1830. {
  1831. return -1;
  1832. }
  1833. // allocate memory for value and check the result of memory allocation
  1834. pfValue = ( float* ) AllocateMemory( sizeof( float ) );
  1835. if ( NULL == pfValue )
  1836. {
  1837. return -1;
  1838. }
  1839. // set the value
  1840. *pfValue = fValue;
  1841. // now add this item value to the array
  1842. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_FLOAT, sizeof( float ), pfValue );
  1843. if ( -1 == lIndex )
  1844. {
  1845. // failed in adding this item to the array
  1846. // so, free the memory allocated and return from the function
  1847. FreeMemory( &pfValue );
  1848. return -1;
  1849. }
  1850. // added the item to the array
  1851. return lIndex;
  1852. }
  1853. LONG
  1854. DynArrayInsertDouble(
  1855. TARRAY pArray,
  1856. DWORD dwIndex,
  1857. double dblValue
  1858. )
  1859. /*++
  1860. Routine Description:
  1861. To insert a double type variable into a Dynamic array
  1862. Arguments:
  1863. [ in ] pArray - Dynamic Array
  1864. [ in ] dwIndex - Specifies the index.
  1865. [ in ] dblValue - specifies the double type variable to be inserted.
  1866. Return Value:
  1867. -1 on failure
  1868. index in the case of success.
  1869. --*/
  1870. {
  1871. // local variables
  1872. LONG lIndex = -1;
  1873. double* pdblValue = NULL;
  1874. // check whether the array is valid or not
  1875. if ( FALSE == IsValidArray( pArray ) )
  1876. {
  1877. return -1;
  1878. }
  1879. // allocate memory for value and check the result of memory allocation
  1880. pdblValue = ( double* ) AllocateMemory( sizeof( double ) );
  1881. if ( NULL == pdblValue )
  1882. {
  1883. return -1;
  1884. }
  1885. // set the value
  1886. *pdblValue = dblValue;
  1887. // now add this item value to the array
  1888. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_DOUBLE, sizeof( double ), pdblValue );
  1889. if ( -1 == lIndex )
  1890. {
  1891. // failed in adding this item to the array
  1892. // so, free the memory allocated and return from the function
  1893. FreeMemory( &pdblValue );
  1894. return -1;
  1895. }
  1896. // added the item to the array
  1897. return lIndex;
  1898. }
  1899. LONG
  1900. DynArrayInsertHandle(
  1901. TARRAY pArray,
  1902. DWORD dwIndex,
  1903. HANDLE hValue
  1904. )
  1905. /*++
  1906. Routine Description:
  1907. To insert a HANDLE type variable into a Dynamic array
  1908. Arguments:
  1909. [ in ] pArray - Dynamic Array
  1910. [ in ] dwIndex - Specifies the index.
  1911. [ in ] hValue - specifies the HANDLE type variable to be inserted.
  1912. Return Value:
  1913. -1 on failure
  1914. index in the case of success.
  1915. --*/
  1916. {
  1917. // local variables
  1918. LONG lIndex = -1;
  1919. HANDLE* phValue = NULL;
  1920. // check whether the array is valid or not
  1921. if ( FALSE == IsValidArray( pArray ) )
  1922. {
  1923. return -1;
  1924. }
  1925. // allocate memory for value and check the result of memory allocation
  1926. phValue = ( HANDLE* ) AllocateMemory( sizeof( HANDLE ) );
  1927. if ( NULL == phValue )
  1928. {
  1929. return -1;
  1930. }
  1931. // set the value
  1932. *phValue = hValue;
  1933. // now add this item value to the array
  1934. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_HANDLE, sizeof( HANDLE ), phValue );
  1935. if ( -1 == lIndex )
  1936. {
  1937. // failed in adding this item to the array
  1938. // so, free the memory allocated and return from the function
  1939. FreeMemory( (LPVOID * )&phValue );
  1940. return -1;
  1941. }
  1942. // added the item to the array
  1943. return lIndex;
  1944. }
  1945. LONG
  1946. DynArrayInsertSystemTime(
  1947. TARRAY pArray,
  1948. DWORD dwIndex,
  1949. SYSTEMTIME stValue
  1950. )
  1951. /*++
  1952. Routine Description:
  1953. To insert a SYSTEMTIME type variable into a Dynamic array
  1954. Arguments:
  1955. [ in ] pArray - Dynamic Array
  1956. [ in ] dwIndex - Specifies the index.
  1957. [ in ] stValue - specifies the SYSTEMTIME type variable to be inserted.
  1958. Return Value:
  1959. -1 on failure
  1960. index in the case of success.
  1961. --*/
  1962. {
  1963. // local variables
  1964. LONG lIndex = -1;
  1965. SYSTEMTIME* pstValue = NULL;
  1966. // check whether the array is valid or not
  1967. if ( FALSE == IsValidArray( pArray ) )
  1968. {
  1969. return -1;
  1970. }
  1971. // allocate memory for value and check the result of memory allocation
  1972. pstValue = ( SYSTEMTIME* ) AllocateMemory( sizeof( SYSTEMTIME ) );
  1973. if ( NULL == pstValue )
  1974. {
  1975. return -1;
  1976. }
  1977. // set the value
  1978. *pstValue = stValue;
  1979. // now add this item value to the array
  1980. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_SYSTEMTIME,
  1981. sizeof( SYSTEMTIME ), pstValue );
  1982. if ( -1 == lIndex )
  1983. {
  1984. // failed in adding this item to the array
  1985. // so, free the memory allocated and return from the function
  1986. FreeMemory( &pstValue );
  1987. return -1;
  1988. }
  1989. // added the item to the array
  1990. return lIndex;
  1991. }
  1992. LONG
  1993. DynArrayInsertFileTime(
  1994. TARRAY pArray,
  1995. DWORD dwIndex,
  1996. FILETIME ftValue
  1997. )
  1998. /*++
  1999. Routine Description:
  2000. To insert a SYSTEMTIME type variable into a Dynamic array
  2001. Arguments:
  2002. [ in ] pArray - Dynamic Array
  2003. [ in ] dwIndex - Specifies the index.
  2004. [ in ] ftValue - specifies the SYSTEMTIME type variable to be inserted.
  2005. Return Value:
  2006. -1 on failure
  2007. index in the case of success.
  2008. --*/
  2009. {
  2010. // local variables
  2011. LONG lIndex = -1;
  2012. FILETIME* pftValue = NULL;
  2013. // check whether the array is valid or not
  2014. if ( FALSE == IsValidArray( pArray ) )
  2015. {
  2016. return -1;
  2017. }
  2018. // allocate memory for value and check the result of memory allocation
  2019. pftValue = ( FILETIME* ) AllocateMemory( sizeof( FILETIME ) );
  2020. if ( NULL == pftValue )
  2021. {
  2022. return -1;
  2023. }
  2024. // set the value
  2025. *pftValue = ftValue;
  2026. // now add this item value to the array
  2027. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_FILETIME,
  2028. sizeof( FILETIME ), pftValue );
  2029. if ( -1 == lIndex )
  2030. {
  2031. // failed in adding this item to the array
  2032. // so, free the memory allocated and return from the function
  2033. FreeMemory( &pftValue );
  2034. return -1;
  2035. }
  2036. // added the item to the array
  2037. return lIndex;
  2038. }
  2039. LONG
  2040. DynArrayInsertRow(
  2041. TARRAY pArray,
  2042. DWORD dwIndex,
  2043. DWORD dwColumns
  2044. )
  2045. /*++
  2046. Routine Description:
  2047. this funtion insert a new row to a dynamic array
  2048. Arguments:
  2049. [ in ] pArray - Dynamic Array
  2050. [ in ] dwIndex - Specifies the index.
  2051. [ in ] dwColumns - specifies the number of columns to be inserted.
  2052. Return Value:
  2053. -1 on failure
  2054. index in the case of success.
  2055. --*/
  2056. {
  2057. // local variables
  2058. DWORD dw = 0;
  2059. LONG lIndex = -1;
  2060. TARRAY arrSubArray = NULL;
  2061. // validate the array
  2062. if ( FALSE == IsValidArray( pArray ) )
  2063. {
  2064. return -1; // array is not valid
  2065. }
  2066. // create the dynamic array
  2067. arrSubArray = CreateDynamicArray();
  2068. if ( FALSE == IsValidArray( arrSubArray ) )
  2069. {
  2070. return -1; // failed in creating the dynamic array
  2071. }
  2072. // add the required no. of columns to the sub array
  2073. for( dw = 0; dw < dwColumns; dw++ )
  2074. {
  2075. // add the dummy item to the array and check the result
  2076. // if operation failed, break
  2077. if ( -1 == __DynArrayAppend( arrSubArray, _TYPE_NEEDINIT, 0, NULL ) )
  2078. {
  2079. break;
  2080. }
  2081. }
  2082. // check whether the operation is successfull or not
  2083. if ( dw != dwColumns )
  2084. {
  2085. // adding of columns failed
  2086. // destroy the dynamic array and return
  2087. DestroyDynamicArray( &arrSubArray );
  2088. return -1;
  2089. }
  2090. // now add this sub array to the main array and check the result
  2091. lIndex = __DynArrayInsert( pArray, dwIndex, DA_TYPE_ARRAY,
  2092. sizeof( TARRAY ), arrSubArray );
  2093. if ( -1 == lIndex )
  2094. {
  2095. // failed in attaching the sub array to the main array
  2096. // destroy the dynamic array and return failure
  2097. DestroyDynamicArray( &arrSubArray );
  2098. return -1;
  2099. }
  2100. // operation is successfull
  2101. return lIndex;
  2102. }
  2103. LONG
  2104. DynArrayInsert2(
  2105. TARRAY pArray,
  2106. DWORD dwRow,
  2107. DWORD dwColIndex,
  2108. LPVOID pValue
  2109. )
  2110. /*++
  2111. Routine Description:
  2112. this funtion insert a new row to a 2-dimensional dynamic array
  2113. Arguments:
  2114. [ in ] pArray - Dynamic Array
  2115. [ in ] dwRow - Specifies the row.
  2116. [ in ] dwColIndex - specifies the column
  2117. [ in ] pValue - pointer to the value.
  2118. Return Value:
  2119. -1 on failure
  2120. index in the case of success.
  2121. --*/
  2122. {
  2123. // local variables
  2124. __PTITEM pItem = NULL;
  2125. // get the item at the required row
  2126. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2127. if ( ( NULL == pItem ) ||
  2128. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2129. {
  2130. return -1; // no item exists at the specified row or item is not of type array
  2131. }
  2132. // now add the value to the sub array and return the result to the caller
  2133. return DynArrayInsert( pItem->pValue, dwColIndex, pValue );
  2134. }
  2135. LONG
  2136. DynArrayInsertString2(
  2137. TARRAY pArray,
  2138. DWORD dwRow,
  2139. DWORD dwColIndex,
  2140. LPCWSTR szValue,
  2141. DWORD dwLength
  2142. )
  2143. /*++
  2144. Routine Description:
  2145. this funtion insert a new string into a 2-dimensional dynamic array
  2146. Arguments:
  2147. [ in ] pArray - Dynamic Array
  2148. [ in ] dwRow - Specifies the row.
  2149. [ in ] dwColIndex - specifies the column
  2150. [ in ] szValue - pointer to the value.
  2151. [ in ] dwLength - string length.
  2152. Return Value:
  2153. -1 on failure
  2154. index in the case of success.
  2155. --*/
  2156. {
  2157. // local variables
  2158. __PTITEM pItem = NULL;
  2159. // get the item at the required row
  2160. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2161. if ( ( NULL == pItem ) ||
  2162. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2163. {
  2164. return -1; // no item exists at the specified row or item is not of type array
  2165. }
  2166. // now add the string to the sub array and return the result to the caller
  2167. return DynArrayInsertString( pItem->pValue, dwColIndex, szValue, dwLength );
  2168. }
  2169. LONG
  2170. DynArrayInsertLong2(
  2171. TARRAY pArray,
  2172. DWORD dwRow,
  2173. DWORD dwColIndex,
  2174. LONG lValue
  2175. )
  2176. /*++
  2177. Routine Description:
  2178. this funtion insert a new long type varaible into a 2-dimensional dynamic array
  2179. Arguments:
  2180. [ in ] pArray - Dynamic Array
  2181. [ in ] dwRow - Specifies the row.
  2182. [ in ] dwColIndex - specifies the column
  2183. [ in ] lValue - long type value to be inserted.
  2184. Return Value:
  2185. -1 on failure
  2186. index in the case of success.
  2187. --*/
  2188. {
  2189. // local variables
  2190. __PTITEM pItem = NULL;
  2191. // get the item at the required row
  2192. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2193. if ( ( NULL == pItem ) ||
  2194. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2195. {
  2196. return -1; // no item exists at the specified row or item is not of type array
  2197. }
  2198. // now add the string to the sub array and return the result to the caller
  2199. return DynArrayInsertLong( pItem->pValue, dwColIndex, lValue );
  2200. }
  2201. LONG
  2202. DynArrayInsertDWORD2(
  2203. TARRAY pArray,
  2204. DWORD dwRow,
  2205. DWORD dwColIndex,
  2206. DWORD dwValue
  2207. )
  2208. /*++
  2209. Routine Description:
  2210. this funtion insert a new DWORD type varaible into a 2-dimensional dynamic array
  2211. Arguments:
  2212. [ in ] pArray - Dynamic Array
  2213. [ in ] dwRow - Specifies the row.
  2214. [ in ] dwColIndex - specifies the column
  2215. [ in ] dwValue - DWORD value to be inserted.
  2216. Return Value:
  2217. -1 on failure
  2218. index in the case of success.
  2219. --*/
  2220. {
  2221. // local variables
  2222. __PTITEM pItem = NULL;
  2223. // get the item at the required row
  2224. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2225. if ( ( NULL == pItem ) ||
  2226. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2227. {
  2228. return -1; // no item exists at the specified row or item is not of type array
  2229. }
  2230. // now add the string to the sub array and return the result to the caller
  2231. return DynArrayInsertDWORD( pItem->pValue, dwColIndex, dwValue );
  2232. }
  2233. LONG
  2234. DynArrayInsertBOOL2(
  2235. TARRAY pArray,
  2236. DWORD dwRow,
  2237. DWORD dwColIndex,
  2238. BOOL bValue
  2239. )
  2240. /*++
  2241. Routine Description:
  2242. this funtion insert a new BOOL type variable into a 2-dimensional dynamic array
  2243. Arguments:
  2244. [ in ] pArray - Dynamic Array
  2245. [ in ] dwRow - Specifies the row.
  2246. [ in ] dwColIndex - specifies the column
  2247. [ in ] bValue - BOOL type value to be inserted.
  2248. Return Value:
  2249. -1 on failure
  2250. index in the case of success.
  2251. --*/
  2252. {
  2253. // local variables
  2254. __PTITEM pItem = NULL;
  2255. // get the item at the required row
  2256. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2257. if ( ( NULL == pItem ) ||
  2258. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2259. {
  2260. return -1; // no item exists at the specified row or item is not of type array
  2261. }
  2262. // now add the string to the sub array and return the result to the caller
  2263. return DynArrayInsertBOOL( pItem->pValue, dwColIndex, bValue );
  2264. }
  2265. LONG
  2266. DynArrayInsertFloat2(
  2267. TARRAY pArray,
  2268. DWORD dwRow,
  2269. DWORD dwColIndex,
  2270. float fValue
  2271. )
  2272. /*++
  2273. Routine Description:
  2274. this funtion insert a new float type variable into a 2-dimensional dynamic array
  2275. Arguments:
  2276. [ in ] pArray - Dynamic Array
  2277. [ in ] dwRow - Specifies the row.
  2278. [ in ] dwColIndex - specifies the column
  2279. [ in ] fValue - float type value to be inserted.
  2280. Return Value:
  2281. -1 on failure
  2282. index in the case of success.
  2283. --*/
  2284. {
  2285. // local variables
  2286. __PTITEM pItem = NULL;
  2287. // get the item at the required row
  2288. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2289. if ( ( NULL == pItem ) ||
  2290. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2291. {
  2292. return -1; // no item exists at the specified row or item is not of type array
  2293. }
  2294. // now add the string to the sub array and return the result to the caller
  2295. return DynArrayInsertFloat( pItem->pValue, dwColIndex, fValue );
  2296. }
  2297. LONG
  2298. DynArrayInsertDouble2(
  2299. TARRAY pArray,
  2300. DWORD dwRow,
  2301. DWORD dwColIndex,
  2302. double dblValue
  2303. )
  2304. /*++
  2305. Routine Description:
  2306. this funtion insert a new double type variable into a 2-dimensional dynamic array
  2307. Arguments:
  2308. [ in ] pArray - Dynamic Array
  2309. [ in ] dwRow - Specifies the row.
  2310. [ in ] dwColIndex - specifies the column
  2311. [ in ] dblValue - double type value to be inserted.
  2312. Return Value:
  2313. -1 on failure
  2314. index in the case of success.
  2315. --*/
  2316. {
  2317. // local variables
  2318. __PTITEM pItem = NULL;
  2319. // get the item at the required row
  2320. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2321. if ( ( NULL == pItem ) ||
  2322. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2323. {
  2324. return -1; // no item exists at the specified row or item is not of type array
  2325. }
  2326. // now add the string to the sub array and return the result to the caller
  2327. return DynArrayInsertDouble( pItem->pValue, dwColIndex, dblValue );
  2328. }
  2329. LONG
  2330. DynArrayInsertHandle2(
  2331. TARRAY pArray,
  2332. DWORD dwRow,
  2333. DWORD dwColIndex,
  2334. HANDLE hValue
  2335. )
  2336. /*++
  2337. Routine Description:
  2338. this funtion insert a new double type variable into a 2-dimensional dynamic array.
  2339. Arguments:
  2340. [ in ] pArray - Dynamic Array
  2341. [ in ] dwRow - Specifies the row.
  2342. [ in ] dwColIndex - specifies the column
  2343. [ in ] hValue - HANDLE type value to be inserted.
  2344. Return Value:
  2345. -1 on failure
  2346. index in the case of success.
  2347. --*/
  2348. {
  2349. // local variables
  2350. __PTITEM pItem = NULL;
  2351. // get the item at the required row
  2352. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2353. if ( ( NULL == pItem ) ||
  2354. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2355. {
  2356. return -1; // no item exists at the specified row or item is not of type array
  2357. }
  2358. // now add the string to the sub array and return the result to the caller
  2359. return DynArrayInsertHandle( pItem->pValue, dwColIndex, hValue );
  2360. }
  2361. LONG
  2362. DynArrayInsertSystemTime2(
  2363. TARRAY pArray,
  2364. DWORD dwRow,
  2365. DWORD dwColIndex,
  2366. SYSTEMTIME stValue
  2367. )
  2368. /*++
  2369. Routine Description:
  2370. This funtion insert a new SYSTEMTIME type variable into a 2-dimensional dynamic array.
  2371. Arguments:
  2372. [ in ] pArray - Dynamic Array
  2373. [ in ] dwRow - Specifies the row.
  2374. [ in ] dwColIndex - specifies the column
  2375. [ in ] stValue - SYSTEMTIME type value to be inserted.
  2376. Return Value:
  2377. -1 on failure
  2378. index in the case of success.
  2379. --*/
  2380. {
  2381. // local variables
  2382. __PTITEM pItem = NULL;
  2383. // get the item at the required row
  2384. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2385. if ( ( NULL == pItem ) ||
  2386. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2387. {
  2388. return -1; // no item exists at the specified row or item is not of type array
  2389. }
  2390. // now add the string to the sub array and return the result to the caller
  2391. return DynArrayInsertSystemTime( pItem->pValue, dwColIndex, stValue );
  2392. }
  2393. LONG
  2394. DynArrayInsertFileTime2(
  2395. TARRAY pArray,
  2396. DWORD dwRow,
  2397. DWORD dwColIndex,
  2398. FILETIME ftValue
  2399. )
  2400. /*++
  2401. Routine Description:
  2402. this funtion insert a new FILETIME type variable into a 2-dimensional dynamic array
  2403. Arguments:
  2404. [ in ] pArray - Dynamic Array
  2405. [ in ] dwRow - Specifies the row.
  2406. [ in ] dwColIndex - specifies the column
  2407. [ in ] ftValue - FILETIME type value to be inserted.
  2408. Return Value:
  2409. -1 on failure
  2410. index in the case of success.
  2411. --*/
  2412. {
  2413. // local variables
  2414. __PTITEM pItem = NULL;
  2415. // get the item at the required row
  2416. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2417. if ( ( NULL == pItem ) ||
  2418. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2419. {
  2420. return -1; // no item exists at the specified row or item is not of type array
  2421. }
  2422. // now add the string to the sub array and return the result to the caller
  2423. return DynArrayInsertFileTime( pItem->pValue, dwColIndex, ftValue );
  2424. }
  2425. BOOL
  2426. DynArrayRemove(
  2427. TARRAY pArray,
  2428. DWORD dwIndex
  2429. )
  2430. /*++
  2431. Routine Description:
  2432. This funtion empties the contents of the dynamic array.
  2433. Arguments:
  2434. [ in ] pArray - Dynamic Array
  2435. [ in ] dwIndex - specifies the column
  2436. Return Value:
  2437. false on failure
  2438. true ON SUCCESS.
  2439. --*/
  2440. {
  2441. // local variables
  2442. __PTITEM pItem = NULL;
  2443. __PTITEM pPrevItem = NULL;
  2444. __PTARRAY pArrayEx = NULL;
  2445. // convert the passed memory location info into appropriate structure
  2446. pArrayEx = ( __PTARRAY ) pArray;
  2447. // get the pointer to the item that has to be removed and also its previous item
  2448. pItem = __DynArrayGetItem( pArrayEx, dwIndex, &pPrevItem );
  2449. if ( NULL == pItem )
  2450. {
  2451. return FALSE; // index or array is invalid ... cannot proceed
  2452. }
  2453. // unlink the item from the list first
  2454. // before unlinking, check whether item which is going to deleted
  2455. // is the first item in the list
  2456. // is the last item in the list
  2457. // is the middle item in the list
  2458. // Control should not come here if no items are present in the ARRAY.
  2459. // If middle item or last item.
  2460. if ( pPrevItem != NULL ) { pPrevItem->pNext = pItem->pNext; }
  2461. // If first item of the array.
  2462. if ( pPrevItem == NULL ) { pArrayEx->pStart = pItem->pNext; }
  2463. // If last item of the array.
  2464. if ( pItem == pArrayEx->pLast ) { pArrayEx->pLast = pPrevItem; }
  2465. // update the count of the array item
  2466. pArrayEx->dwCount--;
  2467. // free the memory being used by the currently unlinked item and return success
  2468. __DynArrayFreeItemValue( pItem ); // free the memory allocated for storing data
  2469. FreeMemory( &pItem ); // finally free the memory allocated for item itself
  2470. return TRUE;
  2471. }
  2472. BOOL
  2473. DynArrayRemoveColumn(
  2474. TARRAY pArray,
  2475. DWORD dwRow,
  2476. DWORD dwColumn
  2477. )
  2478. /*++
  2479. Routine Description:
  2480. this funtion REMOVES a column from a dynamic array
  2481. Arguments:
  2482. [ in ] pArray - Dynamic Array
  2483. [ in ] dwRow - specifies the row.
  2484. [ in ] dwColumn - specifies the column
  2485. Return Value:
  2486. false on failure
  2487. true ON SUCCESS.
  2488. --*/
  2489. {
  2490. // local variables
  2491. __PTITEM pItem = NULL;
  2492. // get the item at the required row
  2493. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2494. if ( ( NULL == pItem ) ||
  2495. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2496. {
  2497. return FALSE; // no item exists at the specified row or item is not of type array
  2498. }
  2499. // now add the string to the sub array and return the result to the caller
  2500. return DynArrayRemove( pItem->pValue, dwColumn );
  2501. }
  2502. DWORD
  2503. DynArrayGetCount(
  2504. TARRAY pArray
  2505. )
  2506. /*++
  2507. Routine Description:
  2508. this function retreives the number of rows in a 1-dimensional dynamic array
  2509. Arguments:
  2510. [ in ] pArray - Dynamic Array
  2511. Return Value:
  2512. false on failure
  2513. true ON SUCCESS.
  2514. --*/
  2515. {
  2516. // local variables
  2517. __PTARRAY pArrayEx = NULL;
  2518. // check whether the array is valid or not
  2519. if ( FALSE == IsValidArray( pArray ) )
  2520. {
  2521. return 0;
  2522. }
  2523. // convert the passed memory location info into appropriate structure
  2524. pArrayEx = ( __PTARRAY ) pArray;
  2525. // return the size of the array
  2526. return pArrayEx->dwCount;
  2527. }
  2528. DWORD
  2529. DynArrayGetCount2(
  2530. TARRAY pArray,
  2531. DWORD dwRow
  2532. )
  2533. /*++
  2534. Routine Description:
  2535. this function retreives the number of columns in a 2-dimensional dynamic array
  2536. Arguments:
  2537. [ in ] pArray - Dynamic Array
  2538. [ in ] dwRow - row for which the number of columns have to be got.
  2539. Return Value:
  2540. false on failure
  2541. true ON SUCCESS.
  2542. --*/
  2543. {
  2544. // local variables
  2545. __PTITEM pItem = NULL;
  2546. // get the item at the required row
  2547. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  2548. if ( ( NULL == pItem ) ||
  2549. ( DA_TYPE_ARRAY != pItem->dwType ) )
  2550. {
  2551. return FALSE; // no item exists at the specified row or item is not of type array
  2552. }
  2553. // now add the string to the sub array and return the result to the caller
  2554. return DynArrayGetCount( pItem->pValue );
  2555. }
  2556. LPVOID
  2557. DynArrayItem(
  2558. TARRAY pArray,
  2559. DWORD dwIndex
  2560. )
  2561. /*++
  2562. Routine Description:
  2563. this function retreives the item from a dynamic array.
  2564. Arguments:
  2565. [ in ] pArray - Dynamic Array
  2566. [ in ] dwIndex - index.
  2567. Return Value:
  2568. false on failure
  2569. true ON SUCCESS.
  2570. --*/
  2571. {
  2572. // local variables
  2573. __PTITEM pItem = NULL;
  2574. // get the item at the required index
  2575. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2576. if ( NULL == pItem )
  2577. {
  2578. return NULL; // index / array is not valid
  2579. }
  2580. // check the type of the item first
  2581. // if the type doesn't match, return some default value
  2582. if ( DA_TYPE_GENERAL != pItem->dwType && DA_TYPE_ARRAY != pItem->dwType )
  2583. {
  2584. return NULL;
  2585. }
  2586. // now return the contents of the __TITEM structure
  2587. return pItem->pValue;
  2588. }
  2589. LPCWSTR
  2590. DynArrayItemAsString(
  2591. TARRAY pArray,
  2592. DWORD dwIndex
  2593. )
  2594. /*++
  2595. Routine Description:
  2596. this function retreives the item from a dynamic array as a string.
  2597. Arguments:
  2598. [ in ] pArray - Dynamic Array
  2599. [ in ] dwIndex - index.
  2600. Return Value:
  2601. false on failure
  2602. true ON SUCCESS.
  2603. --*/
  2604. {
  2605. // local variables
  2606. __PTITEM pItem = NULL;
  2607. // get the item at the required index
  2608. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2609. if ( NULL == pItem )
  2610. {
  2611. return NULL; // index / array is not valid
  2612. }
  2613. // check the type of the item first
  2614. // if the type doesn't match, return some default value
  2615. if ( DA_TYPE_STRING != pItem->dwType )
  2616. {
  2617. return NULL;
  2618. }
  2619. // now return the contents of the __TITEM structure
  2620. return ( ( LPCWSTR ) pItem->pValue );
  2621. }
  2622. LONG
  2623. DynArrayItemAsLong(
  2624. TARRAY pArray,
  2625. DWORD dwIndex
  2626. )
  2627. /*++
  2628. Routine Description:
  2629. this function retreives the item from a dynamic array as a Long varaible.
  2630. Arguments:
  2631. [ in ] pArray - Dynamic Array
  2632. [ in ] dwIndex - index.
  2633. Return Value:
  2634. false on failure
  2635. true ON SUCCESS.
  2636. --*/
  2637. {
  2638. // local variables
  2639. __PTITEM pItem = NULL;
  2640. // get the item at the required index
  2641. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2642. if ( NULL == pItem )
  2643. {
  2644. return -1; // index / array is not valid
  2645. }
  2646. // check the type of the item first
  2647. // if the type doesn't match, return some default value
  2648. if ( DA_TYPE_DWORD != pItem->dwType && DA_TYPE_LONG != pItem->dwType )
  2649. {
  2650. return -1;
  2651. }
  2652. // now return the contents of the __TITEM structure
  2653. return ( *( PLONG ) pItem->pValue );
  2654. }
  2655. DWORD
  2656. DynArrayItemAsDWORD(
  2657. TARRAY pArray,
  2658. DWORD dwIndex
  2659. )
  2660. /*++
  2661. Routine Description:
  2662. this function retreives the item from a dynamic array as a DWORD varaible.
  2663. Arguments:
  2664. [ in ] pArray - Dynamic Array
  2665. [ in ] dwIndex - index.
  2666. Return Value:
  2667. false on failure
  2668. true ON SUCCESS.
  2669. --*/
  2670. {
  2671. // local variables
  2672. __PTITEM pItem = NULL;
  2673. // get the item at the required index
  2674. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2675. if ( NULL == pItem )
  2676. {
  2677. return 0; // index / array is not valid
  2678. }
  2679. // check the type of the item first
  2680. // if the type doesn't match, return some default value
  2681. if ( DA_TYPE_DWORD != pItem->dwType && DA_TYPE_LONG != pItem->dwType )
  2682. {
  2683. return 0;
  2684. }
  2685. // now return the contents of the __TITEM structure
  2686. return *( ( PDWORD ) pItem->pValue );
  2687. }
  2688. BOOL
  2689. DynArrayItemAsBOOL(
  2690. TARRAY pArray,
  2691. DWORD dwIndex
  2692. )
  2693. /*++
  2694. Routine Description:
  2695. this function retreives the item from a dynamic array as a bool type varaible.
  2696. Arguments:
  2697. [ in ] pArray - Dynamic Array
  2698. [ in ] dwIndex - index.
  2699. Return Value:
  2700. false on failure
  2701. true ON SUCCESS.
  2702. --*/
  2703. {
  2704. // local variables
  2705. __PTITEM pItem = NULL;
  2706. // get the item at the required index
  2707. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2708. if ( NULL == pItem )
  2709. {
  2710. return FALSE; // index / array is not valid
  2711. }
  2712. // check the type of the item first
  2713. // if the type doesn't match, return some default value
  2714. if ( DA_TYPE_BOOL != pItem->dwType )
  2715. {
  2716. return FALSE;
  2717. }
  2718. // now return the contents of the __TITEM structure
  2719. return *( ( PBOOL ) pItem->pValue );
  2720. }
  2721. float
  2722. DynArrayItemAsFloat(
  2723. TARRAY pArray,
  2724. DWORD dwIndex
  2725. )
  2726. /*++
  2727. Routine Description:
  2728. this function retreives the item from a dynamic array as a float type varaible.
  2729. Arguments:
  2730. [ in ] pArray - Dynamic Array
  2731. [ in ] dwIndex - index.
  2732. Return Value:
  2733. false on failure
  2734. true ON SUCCESS.
  2735. --*/
  2736. {
  2737. // local variables
  2738. __PTITEM pItem = NULL;
  2739. // get the item at the required index
  2740. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2741. if ( NULL == pItem )
  2742. {
  2743. return -1.0f; // index / array is not valid
  2744. }
  2745. // check the type of the item first
  2746. // if the type doesn't match, return some default value
  2747. if ( DA_TYPE_FLOAT != pItem->dwType )
  2748. {
  2749. return -1.0f;
  2750. }
  2751. // now return the contents of the __TITEM structure
  2752. return *( ( float* ) pItem->pValue );
  2753. }
  2754. double
  2755. DynArrayItemAsDouble(
  2756. TARRAY pArray,
  2757. DWORD dwIndex
  2758. )
  2759. /*++
  2760. Routine Description:
  2761. this function retreives the item from a dynamic array as a double type varaible.
  2762. Arguments:
  2763. [ in ] pArray - Dynamic Array
  2764. [ in ] dwIndex - index.
  2765. Return Value:
  2766. false on failure
  2767. true ON SUCCESS.
  2768. --*/
  2769. {
  2770. // local variables
  2771. __PTITEM pItem = NULL;
  2772. // get the item at the required index
  2773. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2774. if ( NULL == pItem )
  2775. {
  2776. return -1.0; // index / array is not valid
  2777. }
  2778. // check the type of the item first
  2779. // if the type doesn't match, return some default value
  2780. if ( DA_TYPE_DOUBLE != pItem->dwType )
  2781. {
  2782. return -1.0;
  2783. }
  2784. // now return the contents of the __TITEM structure
  2785. return *( ( double* ) pItem->pValue );
  2786. }
  2787. HANDLE
  2788. DynArrayItemAsHandle(
  2789. TARRAY pArray,
  2790. DWORD dwIndex
  2791. )
  2792. /*++
  2793. Routine Description:
  2794. This function retreives the item from a dynamic array as a handle type varaible.
  2795. Arguments:
  2796. [ in ] pArray - Dynamic Array
  2797. [ in ] dwIndex - index.
  2798. Return Value:
  2799. false on failure
  2800. true ON SUCCESS.
  2801. --*/
  2802. {
  2803. // local variables
  2804. __PTITEM pItem = NULL;
  2805. // get the item at the required index
  2806. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2807. if ( NULL == pItem )
  2808. {
  2809. return NULL; // index / array is not valid
  2810. }
  2811. // check the type of the item first
  2812. // if the type doesn't match, return some default value
  2813. if ( DA_TYPE_HANDLE != pItem->dwType )
  2814. {
  2815. return NULL;
  2816. }
  2817. // now return the contents of the __TITEM structure
  2818. return *( ( HANDLE* ) pItem->pValue );
  2819. }
  2820. SYSTEMTIME
  2821. DynArrayItemAsSystemTime(
  2822. TARRAY pArray,
  2823. DWORD dwIndex
  2824. )
  2825. /*++
  2826. Routine Description:
  2827. this function retreives the item from a dynamic array as a SYSTEMTIME type varaible.
  2828. Arguments:
  2829. [ in ] pArray - Dynamic Array
  2830. [ in ] dwIndex - index.
  2831. Return Value:
  2832. false on failure
  2833. true ON SUCCESS.
  2834. --*/
  2835. {
  2836. // local variables
  2837. __PTITEM pItem = NULL;
  2838. FILETIME ftTemp;
  2839. SYSTEMTIME stTemp; // dummy
  2840. ZeroMemory( &ftTemp, sizeof( FILETIME ) );
  2841. ZeroMemory( &stTemp, sizeof( SYSTEMTIME ) );
  2842. // get the item at the required index
  2843. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2844. if ( NULL == pItem )
  2845. {
  2846. return stTemp; // index / array is not valid
  2847. }
  2848. // check the type of the item first
  2849. // if the type doesn't match, return some default value
  2850. if ( DA_TYPE_SYSTEMTIME != pItem->dwType && DA_TYPE_FILETIME != pItem->dwType )
  2851. {
  2852. return stTemp;
  2853. }
  2854. // now do the needed manipulations ( if needed )
  2855. if ( pItem->dwType == DA_TYPE_SYSTEMTIME )
  2856. {
  2857. // value itself is of required type
  2858. stTemp = *( ( SYSTEMTIME* ) pItem->pValue );
  2859. }
  2860. else
  2861. {
  2862. // need to do conversions
  2863. ftTemp = *( ( FILETIME* ) pItem->pValue );
  2864. // Intentionally return value is not checked.
  2865. FileTimeToSystemTime( &ftTemp, &stTemp );
  2866. }
  2867. // now return the contents of the __TITEM structure
  2868. return stTemp;
  2869. }
  2870. FILETIME
  2871. DynArrayItemAsFileTime(
  2872. TARRAY pArray,
  2873. DWORD dwIndex
  2874. )
  2875. /*++
  2876. Routine Description:
  2877. this function retreives the item from a dynamic array as a FILETIME type varaible.
  2878. Arguments:
  2879. [ in ] pArray - Dynamic Array
  2880. [ in ] dwIndex - index.
  2881. Return Value:
  2882. false on failure
  2883. true ON SUCCESS.
  2884. --*/
  2885. {
  2886. // local variables
  2887. __PTITEM pItem = NULL;
  2888. FILETIME ftTemp; // dummy
  2889. SYSTEMTIME stTemp; // dummy
  2890. ZeroMemory( &ftTemp, sizeof( FILETIME ) );
  2891. ZeroMemory( &stTemp, sizeof( SYSTEMTIME ) );
  2892. // get the item at the required index
  2893. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2894. if ( NULL == pItem )
  2895. {
  2896. return ftTemp; // index / array is not valid
  2897. }
  2898. // check the type of the item first
  2899. // if the type doesn't match, return some default value
  2900. if ( DA_TYPE_SYSTEMTIME != pItem->dwType && DA_TYPE_FILETIME != pItem->dwType )
  2901. {
  2902. return ftTemp;
  2903. }
  2904. // now do the needed manipulations ( if needed )
  2905. if ( DA_TYPE_FILETIME == pItem->dwType )
  2906. {
  2907. // value itself is of required type
  2908. ftTemp = *( ( FILETIME* ) pItem->pValue );
  2909. }
  2910. else
  2911. {
  2912. // need to do conversions
  2913. stTemp = *( ( SYSTEMTIME* ) pItem->pValue );
  2914. // Intentionally return value is not checked.
  2915. SystemTimeToFileTime( &stTemp, &ftTemp );
  2916. }
  2917. // now return the contents of the __TITEM structure
  2918. return ftTemp;
  2919. }
  2920. DWORD
  2921. DynArrayItemAsStringEx(
  2922. TARRAY pArray,
  2923. DWORD dwIndex,
  2924. LPWSTR szBuffer,
  2925. DWORD dwLength
  2926. )
  2927. /*++
  2928. Routine Description:
  2929. this function retreives the item from a dynamic array in string format.
  2930. Arguments:
  2931. [ in ] pArray - Dynamic Array
  2932. [ in ] dwIndex - index.
  2933. [ in ] szBuffer - buffer to hold the string
  2934. [ in ] dwlength - string length.
  2935. Return Value:
  2936. false on failure
  2937. true ON SUCCESS.
  2938. --*/
  2939. {
  2940. // local variables
  2941. __PTITEM pItem = NULL;
  2942. __MAX_SIZE_STRING szTemp = NULL_STRING;
  2943. // check the length specified
  2944. if ( 0 == dwLength )
  2945. {
  2946. return 0;
  2947. }
  2948. // get the item at the required index
  2949. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  2950. if ( NULL == pItem )
  2951. {
  2952. return 0; // index / array is not valid
  2953. }
  2954. // give the value based on the type of the current item
  2955. StringCopy( szBuffer, NULL_STRING, dwLength ); // clear the existing contents
  2956. // convert and get the values in string format
  2957. switch( pItem->dwType )
  2958. {
  2959. case DA_TYPE_STRING:
  2960. StringCopy( szBuffer, ( LPCWSTR ) pItem->pValue, dwLength );
  2961. break;
  2962. case DA_TYPE_LONG:
  2963. //FORMAT_STRING( szTemp, _T( "%ld" ), *( LONG* ) pItem->pValue );
  2964. StringCchPrintfW( szTemp, MAX_STRING_LENGTH, _T( "%ld" ), *( LONG* ) pItem->pValue );
  2965. StringCopy( szBuffer, szTemp, dwLength );
  2966. break;
  2967. case DA_TYPE_DWORD:
  2968. //FORMAT_STRING( szTemp, _T( "%lu" ), *( DWORD* ) pItem->pValue );
  2969. StringCchPrintfW( szTemp, MAX_STRING_LENGTH, _T( "%lu" ), *( DWORD* ) pItem->pValue );
  2970. StringCopy( szBuffer, szTemp, dwLength );
  2971. break;
  2972. case DA_TYPE_FLOAT:
  2973. //FORMAT_STRING( szTemp, _T( "%f" ), *( float* ) pItem->pValue );
  2974. StringCchPrintfW( szTemp, MAX_STRING_LENGTH, _T( "%f" ), *( float* ) pItem->pValue );
  2975. StringCopy( szBuffer, szTemp, dwLength );
  2976. break;
  2977. case DA_TYPE_DOUBLE:
  2978. //FORMAT_STRING( szTemp, _T( "%f" ), *( double* ) pItem->pValue );
  2979. StringCchPrintfW( szTemp, MAX_STRING_LENGTH, _T( "%f" ), *( double* ) pItem->pValue );
  2980. StringCopy( szBuffer, szTemp, dwLength );
  2981. break;
  2982. case DA_TYPE_BOOL:
  2983. case DA_TYPE_ARRAY:
  2984. case DA_TYPE_HANDLE:
  2985. case DA_TYPE_SYSTEMTIME:
  2986. case DA_TYPE_FILETIME:
  2987. case DA_TYPE_GENERAL:
  2988. case _TYPE_NEEDINIT:
  2989. default:
  2990. break; // no value can be set
  2991. }
  2992. // return
  2993. return lstrlen( szBuffer );
  2994. }
  2995. LPVOID
  2996. DynArrayItem2(
  2997. TARRAY pArray,
  2998. DWORD dwRow,
  2999. DWORD dwColumn
  3000. )
  3001. /*++
  3002. Routine Description:
  3003. This function retreives the item from a 2-dimensional dynamic array.
  3004. Arguments:
  3005. [ in ] pArray - Dynamic Array
  3006. [ in ] dwRow - The number of rows
  3007. [ in ] dwColumn - The number of columns
  3008. Return Value:
  3009. pointer to the item.
  3010. --*/
  3011. {
  3012. // local variables
  3013. __PTITEM pItem = NULL;
  3014. // get the item at the required row
  3015. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3016. if ( ( NULL == pItem ) ||
  3017. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3018. {
  3019. return NULL; // no item exists at the specified row or item is not of type array
  3020. }
  3021. // now add the string to the sub array and return the result to the caller
  3022. return DynArrayItem( pItem->pValue, dwColumn );
  3023. }
  3024. LPCWSTR
  3025. DynArrayItemAsString2(
  3026. TARRAY pArray,
  3027. DWORD dwRow,
  3028. DWORD dwColumn
  3029. )
  3030. /*++
  3031. Routine Description:
  3032. this function retreives the item from a dynamic array as a string.
  3033. Arguments:
  3034. [ in ] pArray - Dynamic Array
  3035. [ in ] dwRow - row .
  3036. [ in ] dwColumn - column
  3037. Return Value:
  3038. pointer to the the constant string.
  3039. --*/
  3040. {
  3041. // local variables
  3042. __PTITEM pItem = NULL;
  3043. // get the item at the required row
  3044. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3045. if ( ( NULL == pItem ) ||
  3046. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3047. {
  3048. return NULL; // no item exists at the specified row or item is not of type array
  3049. }
  3050. // now add the string to the sub array and return the result to the caller
  3051. return DynArrayItemAsString( pItem->pValue, dwColumn );
  3052. }
  3053. LONG
  3054. DynArrayItemAsLong2(
  3055. TARRAY pArray,
  3056. DWORD dwRow,
  3057. DWORD dwColumn
  3058. )
  3059. /*++
  3060. Routine Description:
  3061. this function retreives the item from a dynamic array as a long variable.
  3062. Arguments:
  3063. [ in ] pArray - Dynamic Array
  3064. [ in ] dwRow - row .
  3065. [ in ] dwColumn - column
  3066. Return Value:
  3067. The variable of type Long
  3068. --*/
  3069. {
  3070. // local variables
  3071. __PTITEM pItem = NULL;
  3072. // get the item at the required row
  3073. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3074. if ( ( NULL == pItem ) ||
  3075. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3076. {
  3077. return -1; // no item exists at the specified row or item is not of type array
  3078. }
  3079. // now add the string to the sub array and return the result to the caller
  3080. return DynArrayItemAsLong( pItem->pValue, dwColumn );
  3081. }
  3082. DWORD
  3083. DynArrayItemAsDWORD2(
  3084. TARRAY pArray,
  3085. DWORD dwRow,
  3086. DWORD dwColumn
  3087. )
  3088. /*++
  3089. Routine Description:
  3090. This function retreives the item from a dynamic array as a DWORD variable.
  3091. Arguments:
  3092. [ in ] pArray - Dynamic Array
  3093. [ in ] dwRow - row .
  3094. [ in ] dwColumn - column
  3095. Return Value:
  3096. The variable of type DWORD
  3097. --*/
  3098. {
  3099. // local variables
  3100. __PTITEM pItem = NULL;
  3101. // get the item at the required row
  3102. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3103. if ( ( NULL == pItem ) ||
  3104. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3105. {
  3106. return 0; // no item exists at the specified row or item is not of type array
  3107. }
  3108. // now add the string to the sub array and return the result to the caller
  3109. return DynArrayItemAsDWORD( pItem->pValue, dwColumn );
  3110. }
  3111. BOOL
  3112. DynArrayItemAsBOOL2(
  3113. TARRAY pArray,
  3114. DWORD dwRow,
  3115. DWORD dwColumn
  3116. )
  3117. /*++
  3118. Routine Description:
  3119. This function retreives the item from a dynamic array as a BOOL variable.
  3120. Arguments:
  3121. [ in ] pArray - Dynamic Array
  3122. [ in ] dwRow - row .
  3123. [ in ] dwColumn - column
  3124. Return Value:
  3125. The variable of type BOOL.
  3126. --*/
  3127. {
  3128. // local variables
  3129. __PTITEM pItem = NULL;
  3130. // get the item at the required row
  3131. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3132. if ( ( NULL == pItem ) ||
  3133. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3134. {
  3135. return FALSE; // no item exists at the specified row or item is not of type array
  3136. }
  3137. // now add the string to the sub array and return the result to the caller
  3138. return DynArrayItemAsBOOL( pItem->pValue, dwColumn );
  3139. }
  3140. float
  3141. DynArrayItemAsFloat2(
  3142. TARRAY pArray,
  3143. DWORD dwRow,
  3144. DWORD dwColumn
  3145. )
  3146. /*++
  3147. Routine Description:
  3148. this function retreives the item from a dynamic array as a float variable.
  3149. Arguments:
  3150. [ in ] pArray - Dynamic Array
  3151. [ in ] dwRow - row .
  3152. [ in ] dwColumn - column
  3153. Return Value:
  3154. The variable of type float.
  3155. --*/
  3156. {
  3157. // local variables
  3158. __PTITEM pItem = NULL;
  3159. // get the item at the required row
  3160. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3161. if ( ( NULL == pItem ) ||
  3162. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3163. {
  3164. return -1.0f; // no item exists at the specified row or item is not of type array
  3165. }
  3166. // now add the string to the sub array and return the result to the caller
  3167. return DynArrayItemAsFloat( pItem->pValue, dwColumn );
  3168. }
  3169. double
  3170. DynArrayItemAsDouble2(
  3171. TARRAY pArray,
  3172. DWORD dwRow,
  3173. DWORD dwColumn
  3174. )
  3175. /*++
  3176. Routine Description:
  3177. this function retreives the item from a dynamic array as a double variable.
  3178. Arguments:
  3179. [ in ] pArray - Dynamic Array
  3180. [ in ] dwRow - row .
  3181. [ in ] dwColumn - column
  3182. Return Value:
  3183. The variable of type double.
  3184. --*/
  3185. {
  3186. // local variables
  3187. __PTITEM pItem = NULL;
  3188. // get the item at the required row
  3189. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3190. if ( ( NULL == pItem ) ||
  3191. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3192. {
  3193. return -1.0; // no item exists at the specified row or item is not of type array
  3194. }
  3195. // now add the string to the sub array and return the result to the caller
  3196. return DynArrayItemAsDouble( pItem->pValue, dwColumn );
  3197. }
  3198. HANDLE
  3199. DynArrayItemAsHandle2(
  3200. TARRAY pArray,
  3201. DWORD dwRow,
  3202. DWORD dwColumn
  3203. )
  3204. /*++
  3205. Routine Description:
  3206. This function retreives the item from a dynamic array as a HANDLE variable.
  3207. Arguments:
  3208. [ in ] pArray - Dynamic Array
  3209. [ in ] dwRow - row .
  3210. [ in ] dwColumn - column
  3211. Return Value:
  3212. The variable of type HANDLE.
  3213. --*/
  3214. {
  3215. // local variables
  3216. __PTITEM pItem = NULL;
  3217. // get the item at the required row
  3218. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3219. if ( ( NULL == pItem ) ||
  3220. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3221. {
  3222. return NULL; // no item exists at the specified row or item is not of type array
  3223. }
  3224. // now add the string to the sub array and return the result to the caller
  3225. return DynArrayItemAsHandle( pItem->pValue, dwColumn );
  3226. }
  3227. SYSTEMTIME
  3228. DynArrayItemAsSystemTime2(
  3229. TARRAY pArray,
  3230. DWORD dwRow,
  3231. DWORD dwColumn
  3232. )
  3233. /*++
  3234. Routine Description:
  3235. this function retreives the item from a dynamic array as a SYSTEMTIME type variable.
  3236. Arguments:
  3237. [ in ] pArray - Dynamic Array
  3238. [ in ] dwRow - row .
  3239. [ in ] dwColumn - column
  3240. Return Value:
  3241. The variable of type SYSTEMTIME.
  3242. --*/
  3243. {
  3244. // local variables
  3245. __PTITEM pItem = NULL;
  3246. SYSTEMTIME stTemp; // dummy
  3247. ZeroMemory( &stTemp, sizeof( SYSTEMTIME ) );
  3248. // get the item at the required row
  3249. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3250. if ( ( NULL == pItem ) ||
  3251. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3252. {
  3253. return stTemp; // no item exists at the specified row or item is not of type array
  3254. }
  3255. // now add the string to the sub array and return the result to the caller
  3256. return DynArrayItemAsSystemTime( pItem->pValue, dwColumn );
  3257. }
  3258. DWORD
  3259. DynArrayItemAsStringEx2(
  3260. TARRAY pArray,
  3261. DWORD dwRow,
  3262. DWORD dwColumn,
  3263. LPWSTR szBuffer,
  3264. DWORD dwLength
  3265. )
  3266. /*++
  3267. Routine Description:
  3268. this function retreives the item from a 2 dimensional dynamic array as
  3269. a string type variable.
  3270. Arguments:
  3271. [ in ] pArray - Dynamic Array
  3272. [ in ] dwRow - row .
  3273. [ in ] dwColumn - column
  3274. [ in ] szBuffer - String buffer
  3275. [ in ] dwLength - length of the string.
  3276. Return Value:
  3277. TRUE on success.
  3278. FALSE on failure.
  3279. --*/
  3280. {
  3281. // local variables
  3282. __PTITEM pItem = NULL;
  3283. // get the item at the required row
  3284. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3285. if ( ( NULL == pItem ) ||
  3286. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3287. {
  3288. return 0; // no item exists at the specified row or item is not of type array
  3289. }
  3290. // now add the string to the sub array and return the result to the caller
  3291. return DynArrayItemAsStringEx( pItem->pValue, dwColumn, szBuffer, dwLength );
  3292. }
  3293. FILETIME
  3294. DynArrayItemAsFileTime2(
  3295. TARRAY pArray,
  3296. DWORD dwRow,
  3297. DWORD dwColumn
  3298. )
  3299. /*++
  3300. Routine Description:
  3301. this function retreives the item from a 2 dimensional dynamic array as
  3302. a FILETIME type variable.
  3303. Arguments:
  3304. [ in ] pArray - Dynamic Array
  3305. [ in ] dwRow - row .
  3306. [ in ] dwColumn - column
  3307. Return Value:
  3308. The variable of type FILETIME.
  3309. --*/
  3310. {
  3311. // local variables
  3312. __PTITEM pItem = NULL;
  3313. FILETIME ftTemp; // dummy
  3314. ZeroMemory( &ftTemp, sizeof( FILETIME ) );
  3315. // get the item at the required row
  3316. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3317. if ( ( NULL == pItem ) ||
  3318. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3319. {
  3320. return ftTemp; // no item exists at the specified row or item is not of type array
  3321. }
  3322. // now add the string to the sub array and return the result to the caller
  3323. return DynArrayItemAsFileTime( pItem->pValue, dwColumn );
  3324. }
  3325. BOOL
  3326. DynArraySet(
  3327. TARRAY pArray,
  3328. DWORD dwIndex,
  3329. LPVOID pValue
  3330. )
  3331. /*++
  3332. Routine Description:
  3333. general function which inserts an item into a 1-dimensional array.
  3334. Arguments:
  3335. [ in ] pArray - Dynamic Array
  3336. [ in ] dwIndex - row .
  3337. [ in ] pValue - column
  3338. Return Value:
  3339. TRUE : if successfully inserted the item into the array.
  3340. FALSE : if Unsuccessfull .
  3341. --*/
  3342. {
  3343. // local variables
  3344. __PTITEM pItem = NULL;
  3345. // validate the pointer value
  3346. if ( NULL == pValue )
  3347. {
  3348. return FALSE; // invalid memory address passed
  3349. }
  3350. // get the item at the required index
  3351. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3352. if ( NULL == pItem )
  3353. {
  3354. return FALSE; // item not found / invalid array pointer
  3355. }
  3356. // check the data type ... it should of string type
  3357. if ( DA_TYPE_GENERAL != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3358. {
  3359. return FALSE;
  3360. }
  3361. // if the item is being initialized now ... change the type
  3362. if ( _TYPE_NEEDINIT == pItem->dwType )
  3363. {
  3364. pItem->dwType = DA_TYPE_GENERAL;
  3365. }
  3366. // set the value of the current item
  3367. pItem->pValue = pValue;
  3368. // return the result
  3369. return TRUE;
  3370. }
  3371. BOOL
  3372. DynArraySetString(
  3373. TARRAY pArray,
  3374. DWORD dwIndex,
  3375. LPCWSTR szValue,
  3376. DWORD dwLength
  3377. )
  3378. /*++
  3379. // Routine Description:
  3380. // This function inserts an string variable into a 1-dimensional array.
  3381. //
  3382. // Arguments:
  3383. // [ in ] pArray - Dynamic Array
  3384. // [ in ] dwIndex - position .
  3385. // [ in ] szValue - string to be inserted.
  3386. // [ in ] dwLength - length of the string to be insertes
  3387. //
  3388. // Return Value:
  3389. // TRUE : if successfully inserted the item into the array.
  3390. // FALSE : if Unsuccessfull .
  3391. --*/
  3392. {
  3393. // local variables
  3394. __PTITEM pItem = NULL;
  3395. // get the item at the required index
  3396. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3397. if ( NULL == pItem )
  3398. {
  3399. return FALSE; // item not found / invalid array pointer
  3400. }
  3401. // check the data type ...
  3402. if ( DA_TYPE_STRING != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3403. {
  3404. return FALSE;
  3405. }
  3406. // determine the length of string ( memory ) that has to be allocated
  3407. if ( 0 == dwLength )
  3408. {
  3409. dwLength = lstrlen( szValue );
  3410. }
  3411. // accomodate space for storing NULL character
  3412. dwLength += 1;
  3413. // memory has to adjusted based on the exisiting memory size and new contents size
  3414. // before that, we need to check whether the current is initialized or not
  3415. // if not yet initialized, we have to initialize it now
  3416. if ( _TYPE_NEEDINIT == pItem->dwType )
  3417. {
  3418. // memory has to be initialized now
  3419. pItem->pValue = AllocateMemory( dwLength * sizeof( WCHAR ) );
  3420. if ( NULL == pItem->pValue )
  3421. {
  3422. return FALSE; // failed in allocation
  3423. }
  3424. // set the type and size information
  3425. pItem->dwType = DA_TYPE_STRING;
  3426. pItem->dwSize = dwLength * sizeof( WCHAR );
  3427. }
  3428. else
  3429. {
  3430. if ( pItem->dwSize < dwLength * sizeof( WCHAR ) )
  3431. {
  3432. // release the existing memory pointer/location
  3433. FreeMemory( &( pItem->pValue ) );
  3434. // now allocate the needed memory
  3435. pItem->pValue = NULL;
  3436. pItem->pValue = AllocateMemory( dwLength * sizeof( WCHAR ) );
  3437. if ( NULL == pItem->pValue )
  3438. {
  3439. // failed in re-allocation
  3440. return FALSE;
  3441. }
  3442. // update the size of the buffer
  3443. pItem->dwSize = dwLength * sizeof( WCHAR );
  3444. }
  3445. }
  3446. // copy the contents of the string ( copy should be based on the length )
  3447. StringCopy( ( LPWSTR ) pItem->pValue, szValue, dwLength );
  3448. // copied ... value set successfully
  3449. return TRUE;
  3450. }
  3451. BOOL
  3452. DynArraySetLong(
  3453. TARRAY pArray,
  3454. DWORD dwIndex,
  3455. LONG lValue
  3456. )
  3457. /*++
  3458. // Routine Description:
  3459. // This function inserts an long type variable into a 1-dimensional array.
  3460. //
  3461. // Arguments:
  3462. // [ in ] pArray - Dynamic Array
  3463. // [ in ] dwIndex - position .
  3464. // [ in ] lValue - long value to be inserted.
  3465. //
  3466. // Return Value:
  3467. // TRUE : if successfully inserted the item into the array.
  3468. // FALSE : if Unsuccessfull .
  3469. --*/
  3470. {
  3471. // local variables
  3472. __PTITEM pItem = NULL;
  3473. // get the item at the required index
  3474. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3475. if ( NULL == pItem )
  3476. {
  3477. return FALSE; // item not found / invalid array pointer
  3478. }
  3479. // check the data type ...
  3480. if ( DA_TYPE_LONG != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3481. {
  3482. return FALSE;
  3483. }
  3484. // if item is not yet allocated memory, we have to allocate now
  3485. if ( _TYPE_NEEDINIT == pItem->dwType )
  3486. {
  3487. // allocate memory
  3488. pItem->pValue = AllocateMemory( sizeof( LONG ) );
  3489. if ( NULL == pItem->pValue )
  3490. {
  3491. return FALSE; // failed in memory allocation
  3492. }
  3493. // set the type
  3494. pItem->dwType = DA_TYPE_LONG;
  3495. pItem->dwSize = sizeof( LONG );
  3496. }
  3497. // set the new value
  3498. *( ( LONG* ) pItem->pValue ) = lValue;
  3499. // copied ... value set successfully
  3500. return TRUE;
  3501. }
  3502. BOOL
  3503. DynArraySetDWORD(
  3504. TARRAY pArray,
  3505. DWORD dwIndex,
  3506. DWORD dwValue
  3507. )
  3508. /*++
  3509. Routine Description:
  3510. This function inserts an DWORD type variable into a 1-dimensional array.
  3511. Arguments:
  3512. [ in ] pArray - Dynamic Array
  3513. [ in ] dwIndex - position .
  3514. [ in ] dwValue - DWORD value to be inserted.
  3515. Return Value:
  3516. TRUE : if successfully inserted the item into the array.
  3517. FALSE : if Unsuccessfull .
  3518. --*/
  3519. {
  3520. // local variables
  3521. __PTITEM pItem = NULL;
  3522. // get the item at the required index
  3523. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3524. if ( NULL == pItem )
  3525. {
  3526. return FALSE; // item not found / invalid array pointer
  3527. }
  3528. // check the data type ...
  3529. if ( DA_TYPE_DWORD != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3530. {
  3531. return FALSE;
  3532. }
  3533. // if item is not yet allocated memory, we have to allocate now
  3534. if ( _TYPE_NEEDINIT == pItem->dwType )
  3535. {
  3536. // allocate memory
  3537. pItem->pValue = AllocateMemory( sizeof( DWORD ) );
  3538. if ( NULL == pItem->pValue )
  3539. {
  3540. return FALSE; // failed in memory allocation
  3541. }
  3542. // set the type
  3543. pItem->dwType = DA_TYPE_DWORD;
  3544. pItem->dwSize = sizeof( DWORD );
  3545. }
  3546. // set the new value
  3547. *( ( DWORD* ) pItem->pValue ) = dwValue;
  3548. // copied ... value set successfully
  3549. return TRUE;
  3550. }
  3551. BOOL
  3552. DynArraySetBOOL(
  3553. TARRAY pArray,
  3554. DWORD dwIndex,
  3555. BOOL bValue
  3556. )
  3557. /*++
  3558. // Routine Description:
  3559. // This function inserts an BOOL type variable into a 1-dimensional dynamic array.
  3560. //
  3561. // Arguments:
  3562. // [ in ] pArray - Dynamic Array
  3563. // [ in ] dwIndex - position .
  3564. // [ in ] bValue - BOOL value to be inserted.
  3565. //
  3566. // Return Value:
  3567. // TRUE : if successfully inserted the item into the array.
  3568. // FALSE : if Unsuccessfull .
  3569. --*/
  3570. {
  3571. // local variables
  3572. __PTITEM pItem = NULL;
  3573. // get the item at the required index
  3574. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3575. if ( NULL == pItem )
  3576. {
  3577. return FALSE; // item not found / invalid array pointer
  3578. }
  3579. // check the data type ...
  3580. if ( DA_TYPE_BOOL != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3581. {
  3582. return FALSE;
  3583. }
  3584. // if item is not yet allocated memory, we have to allocate now
  3585. if ( _TYPE_NEEDINIT == pItem->dwType )
  3586. {
  3587. // allocate memory
  3588. pItem->pValue = AllocateMemory( sizeof( BOOL ) );
  3589. if ( NULL == pItem->pValue )
  3590. {
  3591. return FALSE; // failed in memory allocation
  3592. }
  3593. // set the type
  3594. pItem->dwType = DA_TYPE_BOOL;
  3595. pItem->dwSize = sizeof( DWORD );
  3596. }
  3597. // set the new value
  3598. *( ( BOOL* ) pItem->pValue ) = bValue;
  3599. // copied ... value set successfully
  3600. return TRUE;
  3601. }
  3602. BOOL
  3603. DynArraySetFloat(
  3604. TARRAY pArray,
  3605. DWORD dwIndex,
  3606. float fValue
  3607. )
  3608. /*++
  3609. // Routine Description:
  3610. // This function inserts an Float type variable into a 1-dimensional dynamic array.
  3611. //
  3612. // Arguments:
  3613. // [ in ] pArray - Dynamic Array
  3614. // [ in ] dwIndex - position .
  3615. // [ in ] fValue - float type value to be inserted.
  3616. //
  3617. // Return Value:
  3618. // TRUE : if successfully inserted the item into the array.
  3619. // FALSE : if Unsuccessfull .
  3620. --*/
  3621. {
  3622. // local variables
  3623. __PTITEM pItem = NULL;
  3624. // get the item at the required index
  3625. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3626. if ( NULL == pItem )
  3627. {
  3628. return FALSE; // item not found / invalid array pointer
  3629. }
  3630. // check the data type ...
  3631. if ( DA_TYPE_FLOAT != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3632. {
  3633. return FALSE;
  3634. }
  3635. // if item is not yet allocated memory, we have to allocate now
  3636. if ( _TYPE_NEEDINIT == pItem->dwType )
  3637. {
  3638. // allocate memory
  3639. pItem->pValue = AllocateMemory( sizeof( float ) );
  3640. if ( NULL == pItem->pValue )
  3641. {
  3642. return FALSE; // failed in memory allocation
  3643. }
  3644. // set the type
  3645. pItem->dwType = DA_TYPE_FLOAT;
  3646. pItem->dwSize = sizeof( float );
  3647. }
  3648. // set the new value
  3649. *( ( float* ) pItem->pValue ) = fValue;
  3650. // copied ... value set successfully
  3651. return TRUE;
  3652. }
  3653. BOOL
  3654. DynArraySetDouble(
  3655. TARRAY pArray,
  3656. DWORD dwIndex,
  3657. double dblValue
  3658. )
  3659. /*++
  3660. // Routine Description:
  3661. // This function inserts an double type variable into a 1-dimensional dynamic array.
  3662. //
  3663. // Arguments:
  3664. // [ in ] pArray - Dynamic Array
  3665. // [ in ] dwIndex - position .
  3666. // [ in ] dblValue - double type value to be inserted.
  3667. //
  3668. // Return Value:
  3669. // TRUE : if successfully inserted the item into the array.
  3670. // FALSE : if Unsuccessfull .
  3671. //
  3672. --*/
  3673. {
  3674. // local variables
  3675. __PTITEM pItem = NULL;
  3676. // get the item at the required index
  3677. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3678. if ( NULL == pItem )
  3679. {
  3680. return FALSE; // item not found / invalid array pointer
  3681. }
  3682. // check the data type ...
  3683. if ( DA_TYPE_DOUBLE != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3684. {
  3685. return FALSE;
  3686. }
  3687. // if item is not yet allocated memory, we have to allocate now
  3688. if ( _TYPE_NEEDINIT == pItem->dwType )
  3689. {
  3690. // allocate memory
  3691. pItem->pValue = AllocateMemory( sizeof( double ) );
  3692. if ( NULL == pItem->pValue )
  3693. {
  3694. return FALSE; // failed in memory allocation
  3695. }
  3696. // set the type
  3697. pItem->dwType = DA_TYPE_DOUBLE;
  3698. pItem->dwSize = sizeof( double );
  3699. }
  3700. // set the new value
  3701. *( ( double* ) pItem->pValue ) = dblValue;
  3702. // copied ... value set successfully
  3703. return TRUE;
  3704. }
  3705. BOOL
  3706. DynArraySetHandle(
  3707. TARRAY pArray,
  3708. DWORD dwIndex,
  3709. HANDLE hValue
  3710. )
  3711. /*++
  3712. // Routine Description:
  3713. // This function inserts an Handle type variable into a 1-dimensional dynamic array.
  3714. //
  3715. // Arguments:
  3716. // [ in ] pArray - Dynamic Array
  3717. // [ in ] dwIndex - position .
  3718. // [ in ] hValue - Handle type value to be inserted.
  3719. //
  3720. // Return Value:
  3721. // TRUE : if successfully inserted the item into the array.
  3722. // FALSE : if Unsuccessfull .
  3723. --*/
  3724. {
  3725. // local variables
  3726. __PTITEM pItem = NULL;
  3727. // get the item at the required index
  3728. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3729. if ( NULL == pItem )
  3730. {
  3731. return FALSE; // item not found / invalid array pointer
  3732. }
  3733. // check the data type ...
  3734. if ( DA_TYPE_HANDLE != pItem->dwType && _TYPE_NEEDINIT != pItem->dwType )
  3735. {
  3736. return FALSE;
  3737. }
  3738. // if item is not yet allocated memory, we have to allocate now
  3739. if ( pItem->dwType == _TYPE_NEEDINIT )
  3740. {
  3741. // allocate memory
  3742. pItem->pValue = AllocateMemory( sizeof( HANDLE ) );
  3743. if ( NULL == pItem->pValue )
  3744. {
  3745. return FALSE; // failed in memory allocation
  3746. }
  3747. // set the type
  3748. pItem->dwType = DA_TYPE_HANDLE;
  3749. pItem->dwSize = sizeof( HANDLE );
  3750. }
  3751. // set the new value
  3752. *( ( HANDLE* ) pItem->pValue ) = hValue;
  3753. // copied ... value set successfully
  3754. return TRUE;
  3755. }
  3756. BOOL
  3757. DynArraySetSystemTime(
  3758. TARRAY pArray,
  3759. DWORD dwIndex,
  3760. SYSTEMTIME stValue
  3761. )
  3762. /*++
  3763. // Routine Description:
  3764. // This function inserts an SYSTEMTIME type variable into a 1-dimensional dynamic array.
  3765. //
  3766. // Arguments:
  3767. // [ in ] pArray - Dynamic Array
  3768. // [ in ] dwIndex - position .
  3769. // [ in ] stValue - SYSTEMTIME type value to be inserted.
  3770. //
  3771. // Return Value:
  3772. // TRUE : if successfully inserted the item into the array.
  3773. // FALSE : if Unsuccessfull .
  3774. --*/
  3775. {
  3776. // local variables
  3777. __PTITEM pItem = NULL;
  3778. FILETIME ftTemp; // dummy
  3779. ZeroMemory( &ftTemp, sizeof( FILETIME ) );
  3780. // get the item at the required index
  3781. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3782. if ( NULL == pItem )
  3783. {
  3784. return FALSE; // item not found / invalid array pointer
  3785. }
  3786. // check the data type ...
  3787. if ( DA_TYPE_SYSTEMTIME != pItem->dwType &&
  3788. DA_TYPE_FILETIME != pItem->dwType &&
  3789. _TYPE_NEEDINIT != pItem->dwType )
  3790. {
  3791. return FALSE;
  3792. }
  3793. // if item is not yet allocated memory, we have to allocate now
  3794. if ( _TYPE_NEEDINIT == pItem->dwType )
  3795. {
  3796. // allocate memory
  3797. pItem->pValue = AllocateMemory( sizeof( SYSTEMTIME ) );
  3798. if ( NULL == pItem->pValue )
  3799. {
  3800. return FALSE; // failed in memory allocation
  3801. }
  3802. // set the type
  3803. pItem->dwType = DA_TYPE_SYSTEMTIME;
  3804. pItem->dwSize = sizeof( SYSTEMTIME );
  3805. }
  3806. // depending on the type set the value
  3807. if ( DA_TYPE_FILETIME == pItem->dwType )
  3808. {
  3809. // do the needed conversions and then set
  3810. SystemTimeToFileTime( &stValue, &ftTemp );
  3811. *( ( FILETIME* ) pItem->pValue ) = ftTemp;
  3812. }
  3813. else
  3814. {
  3815. // set the new value as it is
  3816. *( ( SYSTEMTIME* ) pItem->pValue ) = stValue;
  3817. }
  3818. // copied ... value set successfully
  3819. return TRUE;
  3820. }
  3821. BOOL
  3822. DynArraySetFileTime(
  3823. TARRAY pArray,
  3824. DWORD dwIndex,
  3825. FILETIME ftValue
  3826. )
  3827. /*++
  3828. // Routine Description:
  3829. // This function inserts an FILETIME type variable into a 1-dimensional dynamic array.
  3830. //
  3831. // Arguments:
  3832. // [ in ] pArray - Dynamic Array
  3833. // [ in ] dwIndex - position .
  3834. // [ in ] ftValue - FILETIME type value to be inserted.
  3835. //
  3836. // Return Value:
  3837. // TRUE : if successfully inserted the item into the array.
  3838. // FALSE : if Unsuccessfull .
  3839. --*/
  3840. {
  3841. // local variables
  3842. __PTITEM pItem = NULL;
  3843. SYSTEMTIME stTemp; // dummy
  3844. ZeroMemory( &stTemp, sizeof( SYSTEMTIME ) );
  3845. // get the item at the required index
  3846. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  3847. if ( NULL == pItem )
  3848. {
  3849. return FALSE; // item not found / invalid array pointer
  3850. }
  3851. // check the data type ...
  3852. if ( DA_TYPE_FILETIME != pItem->dwType &&
  3853. DA_TYPE_SYSTEMTIME != pItem->dwType &&
  3854. _TYPE_NEEDINIT != pItem->dwType )
  3855. {
  3856. return FALSE;
  3857. }
  3858. // if item is not yet allocated memory, we have to allocate now
  3859. if ( _TYPE_NEEDINIT == pItem->dwType )
  3860. {
  3861. // allocate memory
  3862. pItem->pValue = AllocateMemory( sizeof( FILETIME ) );
  3863. if ( NULL ==pItem->pValue )
  3864. {
  3865. return FALSE; // failed in memory allocation
  3866. }
  3867. // set the type
  3868. pItem->dwType = DA_TYPE_FILETIME;
  3869. pItem->dwSize = sizeof( FILETIME );
  3870. }
  3871. // depending on the type set the value
  3872. if ( DA_TYPE_SYSTEMTIME ==pItem->dwType )
  3873. {
  3874. // do the needed conversions and then set
  3875. FileTimeToSystemTime( &ftValue, &stTemp );
  3876. *( ( SYSTEMTIME* ) pItem->pValue ) = stTemp;
  3877. }
  3878. else
  3879. {
  3880. // set the new value as it is
  3881. *( ( FILETIME* ) pItem->pValue ) = ftValue;
  3882. }
  3883. // copied ... value set successfully
  3884. return TRUE;
  3885. }
  3886. BOOL
  3887. DynArraySet2(
  3888. TARRAY pArray,
  3889. DWORD dwRow,
  3890. DWORD dwColumn,
  3891. LPVOID pValue
  3892. )
  3893. /*++
  3894. // Routine Description:
  3895. // This function is a general function to insert an variable into a 2-dimensional dynamic array.
  3896. //
  3897. // Arguments:
  3898. // [ in ] pArray - Dynamic Array
  3899. // [ in ] dwRow - row position .
  3900. // [ in ] dwcolumn - column at which the element is to be inserted.
  3901. // [ in ] pValue - value to be inserted.
  3902. //
  3903. // Return Value:
  3904. // TRUE : if successfully inserted the item into the array.
  3905. // FALSE : if Unsuccessfull .
  3906. --*/
  3907. {
  3908. // local variables
  3909. __PTITEM pItem = NULL;
  3910. // get the item at the required row
  3911. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3912. if ( ( NULL == pItem ) ||
  3913. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3914. {
  3915. return FALSE; // no item exists at the specified row or item is not of type array
  3916. }
  3917. // now add the value to the sub array and return the result to the caller
  3918. return DynArraySet( pItem->pValue, dwColumn, pValue );
  3919. }
  3920. BOOL
  3921. DynArraySetString2(
  3922. TARRAY pArray,
  3923. DWORD dwRow,
  3924. DWORD dwColumn,
  3925. LPCWSTR szValue,
  3926. DWORD dwLength
  3927. )
  3928. /*++
  3929. // Routine Description:
  3930. // This function inserts a string variable into a 2-dimensional dynamic array.
  3931. //
  3932. // Arguments:
  3933. // [ in ] pArray - Dynamic Array
  3934. // [ in ] dwRow - row position .
  3935. // [ in ] dwcolumn - column at which the element is to be inserted.
  3936. // [ in ] szValue - Pointer to the string
  3937. // [ in ] dwlength - length of the string to be inserted
  3938. //
  3939. // Return Value:
  3940. // TRUE : if successfully inserted the item into the array.
  3941. // FALSE : if Unsuccessfull .
  3942. --*/
  3943. {
  3944. // local variables
  3945. __PTITEM pItem = NULL;
  3946. // get the item at the required row
  3947. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3948. if ( ( NULL == pItem ) ||
  3949. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3950. {
  3951. return FALSE; // no item exists at the specified row or item is not of type array
  3952. }
  3953. // now add the value to the sub array and return the result to the caller
  3954. return DynArraySetString( pItem->pValue, dwColumn, szValue, dwLength );
  3955. }
  3956. BOOL
  3957. DynArraySetLong2(
  3958. TARRAY pArray,
  3959. DWORD dwRow,
  3960. DWORD dwColumn,
  3961. LONG lValue
  3962. )
  3963. /*++
  3964. // Routine Description:
  3965. // This function inserts a Long variable into a 2-dimensional dynamic array.
  3966. //
  3967. // Arguments:
  3968. // [ in ] pArray - Dynamic Array
  3969. // [ in ] dwRow - row position .
  3970. // [ in ] dwcolumn - column at which the element is to be inserted.
  3971. // [ in ] lValue - value to be inserted.
  3972. // Return Value:
  3973. // TRUE : if successfully inserted the item into the array.
  3974. // FALSE : if Unsuccessfull .
  3975. --*/
  3976. {
  3977. // local variables
  3978. __PTITEM pItem = NULL;
  3979. // get the item at the required row
  3980. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  3981. if ( ( NULL == pItem ) ||
  3982. ( DA_TYPE_ARRAY != pItem->dwType ) )
  3983. {
  3984. return FALSE; // no item exists at the specified row or item is not of type array
  3985. }
  3986. // now add the value to the sub array and return the result to the caller
  3987. return DynArraySetLong( pItem->pValue, dwColumn, lValue );
  3988. }
  3989. BOOL
  3990. DynArraySetDWORD2(
  3991. TARRAY pArray,
  3992. DWORD dwRow,
  3993. DWORD dwColumn,
  3994. DWORD dwValue
  3995. )
  3996. /*++
  3997. // Routine Description:
  3998. // This function inserts a DWORD variable into a 2-dimensional dynamic array.
  3999. //
  4000. // Arguments:
  4001. // [ in ] pArray - Dynamic Array
  4002. // [ in ] dwRow - row position .
  4003. // [ in ] dwcolumn - column at which the element is to be inserted.
  4004. // [ in ] dwValue - DWORD value to be inserted.
  4005. // Return Value:
  4006. // TRUE : if successfully inserted the item into the array.
  4007. // FALSE : if Unsuccessfull .
  4008. --*/
  4009. {
  4010. // local variables
  4011. __PTITEM pItem = NULL;
  4012. // get the item at the required row
  4013. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4014. if ( ( NULL == pItem ) ||
  4015. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4016. {
  4017. return FALSE; // no item exists at the specified row or item is not of type array
  4018. }
  4019. // now add the value to the sub array and return the result to the caller
  4020. return DynArraySetDWORD( pItem->pValue, dwColumn, dwValue );
  4021. }
  4022. BOOL
  4023. DynArraySetBOOL2(
  4024. TARRAY pArray,
  4025. DWORD dwRow,
  4026. DWORD dwColumn,
  4027. BOOL bValue
  4028. )
  4029. /*++
  4030. // Routine Description:
  4031. // This function inserts a BOOL variable into a 2-dimensional dynamic array.
  4032. //
  4033. // Arguments:
  4034. // [ in ] pArray - Dynamic Array
  4035. // [ in ] dwRow - row position .
  4036. // [ in ] dwcolumn - column at which the element is to be inserted.
  4037. // [ in ] bValue - BOOL value to be inserted.
  4038. // Return Value:
  4039. // TRUE : if successfully inserted the item into the array.
  4040. // FALSE : if Unsuccessfull .
  4041. --*/
  4042. {
  4043. // local variables
  4044. __PTITEM pItem = NULL;
  4045. // get the item at the required row
  4046. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4047. if ( ( NULL == pItem ) ||
  4048. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4049. {
  4050. return FALSE; // no item exists at the specified row or item is not of type array
  4051. }
  4052. // now add the value to the sub array and return the result to the caller
  4053. return DynArraySetBOOL( pItem->pValue, dwColumn, bValue );
  4054. }
  4055. BOOL
  4056. DynArraySetFloat2(
  4057. TARRAY pArray,
  4058. DWORD dwRow,
  4059. DWORD dwColumn,
  4060. float fValue
  4061. )
  4062. /*++
  4063. // Routine Description:
  4064. // This function inserts a float variable into a 2-dimensional dynamic array.
  4065. //
  4066. // Arguments:
  4067. // [ in ] pArray - Dynamic Array
  4068. // [ in ] dwRow - row position .
  4069. // [ in ] dwcolumn - column at which the element is to be inserted.
  4070. // [ in ] fValue - float type value to be inserted.
  4071. // Return Value:
  4072. // TRUE : if successfully inserted the item into the array.
  4073. // FALSE : if Unsuccessfull .
  4074. --*/
  4075. {
  4076. // local variables
  4077. __PTITEM pItem = NULL;
  4078. // get the item at the required row
  4079. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4080. if ( ( NULL == pItem ) ||
  4081. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4082. {
  4083. return FALSE; // no item exists at the specified row or item is not of type array
  4084. }
  4085. // now add the value to the sub array and return the result to the caller
  4086. return DynArraySetFloat( pItem->pValue, dwColumn, fValue );
  4087. }
  4088. BOOL
  4089. DynArraySetDouble2(
  4090. TARRAY pArray,
  4091. DWORD dwRow,
  4092. DWORD dwColumn,
  4093. double dblValue
  4094. )
  4095. /*++
  4096. // Routine Description:
  4097. // This function inserts a Double variable into a 2-dimensional dynamic array.
  4098. //
  4099. // Arguments:
  4100. // [ in ] pArray - Dynamic Array
  4101. // [ in ] dwRow - row position .
  4102. // [ in ] dwcolumn - column at which the element is to be inserted.
  4103. // [ in ] dblValue - Double type value to be inserted.
  4104. // Return Value:
  4105. // TRUE : if successfully inserted the item into the array.
  4106. // FALSE : if Unsuccessfull .
  4107. --*/
  4108. {
  4109. // local variables
  4110. __PTITEM pItem = NULL;
  4111. // get the item at the required row
  4112. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4113. if ( ( NULL == pItem ) ||
  4114. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4115. {
  4116. return FALSE; // no item exists at the specified row or item is not of type array
  4117. }
  4118. // now add the vale to the sub array and return the result to the caller
  4119. return DynArraySetDouble( pItem->pValue, dwColumn, dblValue );
  4120. }
  4121. BOOL
  4122. DynArraySetHandle2(
  4123. TARRAY pArray,
  4124. DWORD dwRow,
  4125. DWORD dwColumn,
  4126. HANDLE hValue
  4127. )
  4128. /*++
  4129. // Routine Description:
  4130. // This function inserts a HANDLE variable into a 2-dimensional dynamic array.
  4131. //
  4132. // Arguments:
  4133. // [ in ] pArray - Dynamic Array
  4134. // [ in ] dwRow - row position .
  4135. // [ in ] dwcolumn - column at which the element is to be inserted.
  4136. // [ in ] hValue - HANDLE type value to be inserted.
  4137. //
  4138. // Return Value:
  4139. // TRUE : if successfully inserted the item into the array.
  4140. // FALSE : if Unsuccessfull .
  4141. --*/
  4142. {
  4143. // local variables
  4144. __PTITEM pItem = NULL;
  4145. // get the item at the required row
  4146. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4147. if ( ( NULL == pItem ) ||
  4148. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4149. {
  4150. return FALSE; // no item exists at the specified row or item is not of type array
  4151. }
  4152. // now add the vale to the sub array and return the result to the caller
  4153. return DynArraySetHandle( pItem->pValue, dwColumn, hValue );
  4154. }
  4155. BOOL
  4156. DynArraySetFileTime2(
  4157. TARRAY pArray,
  4158. DWORD dwRow,
  4159. DWORD dwColumn,
  4160. FILETIME ftValue
  4161. )
  4162. /*++
  4163. // Routine Description:
  4164. // This function inserts a FILETIME variable into a 2-dimensional dynamic array.
  4165. //
  4166. // Arguments:
  4167. // [ in ] pArray - Dynamic Array
  4168. // [ in ] dwRow - row position .
  4169. // [ in ] dwcolumn - column at which the element is to be inserted.
  4170. // [ in ] ftValue - FILETIME type value to be inserted.
  4171. //
  4172. // Return Value:
  4173. // TRUE : if successfully inserted the item into the array.
  4174. // FALSE : if Unsuccessfull .
  4175. --*/
  4176. {
  4177. // local variables
  4178. __PTITEM pItem = NULL;
  4179. // get the item at the required row
  4180. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4181. if ( ( NULL == pItem ) ||
  4182. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4183. {
  4184. return FALSE; // no item exists at the specified row or item is not of type array
  4185. }
  4186. // now add the vale to the sub array and return the result to the caller
  4187. return DynArraySetFileTime( pItem->pValue, dwColumn, ftValue );
  4188. }
  4189. BOOL
  4190. DynArraySetSystemTime2(
  4191. TARRAY pArray,
  4192. DWORD dwRow,
  4193. DWORD dwColumn,
  4194. SYSTEMTIME stValue
  4195. )
  4196. /*++
  4197. // Routine Description:
  4198. // This function inserts a SYSTEMTIME variable into a 2-dimensional dynamic array.
  4199. //
  4200. // Arguments:
  4201. // [ in ] pArray - Dynamic Array
  4202. // [ in ] dwRow - row position .
  4203. // [ in ] dwcolumn - column at which the element is to be inserted.
  4204. // [ in ] stValue - SYSTEMTIME type value to be inserted.
  4205. // Return Value:
  4206. // TRUE : if successfully inserted the item into the array.
  4207. // FALSE : if Unsuccessfull .
  4208. --*/
  4209. {
  4210. // local variables
  4211. __PTITEM pItem = NULL;
  4212. // get the item at the required row
  4213. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4214. if ( ( NULL == pItem ) ||
  4215. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4216. {
  4217. return FALSE; // no item exists at the specified row or item is not of type array
  4218. }
  4219. // now add the vale to the sub array and return the result to the caller
  4220. return DynArraySetSystemTime( pItem->pValue, dwColumn, stValue );
  4221. }
  4222. DWORD
  4223. DynArrayGetItemType(
  4224. TARRAY pArray,
  4225. DWORD dwIndex
  4226. )
  4227. /*++
  4228. // Routine Description:
  4229. // This function retreives the type of a element in a 1-dimensional dynamic array.
  4230. //
  4231. // Arguments:
  4232. // [ in ] pArray - Dynamic Array
  4233. // [ in ] dwIndex - row position .
  4234. //
  4235. // Return Value:
  4236. // the type of array.
  4237. --*/
  4238. {
  4239. // local variables
  4240. __PTITEM pItem = NULL;
  4241. // get the item at the required index
  4242. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  4243. if ( NULL == pItem )
  4244. {
  4245. return DA_TYPE_NONE; // item not found / invalid array pointer
  4246. }
  4247. // return the type of the array
  4248. return pItem->dwType;
  4249. }
  4250. DWORD
  4251. DynArrayGetItemType2(
  4252. TARRAY pArray,
  4253. DWORD dwRow,
  4254. DWORD dwColumn
  4255. )
  4256. /*++
  4257. // Routine Description:
  4258. // This function retreives the type of a element in a 2-dimensional dynamic array.
  4259. //
  4260. // Arguments:
  4261. // [ in ] pArray - Dynamic Array
  4262. // [ in ] dwRow - row position .
  4263. // [ in ] dwColumn - column position
  4264. //
  4265. // Return Value:
  4266. // the type of array.
  4267. --*/
  4268. {
  4269. // local variables
  4270. __PTITEM pItem = NULL;
  4271. // get the item at the required row
  4272. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4273. if ( ( NULL == pItem ) ||
  4274. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4275. {
  4276. return FALSE; // no item exists at the specified row or item is not of type array
  4277. }
  4278. // now add the vale to the sub array and return the result to the caller
  4279. return DynArrayGetItemType( pItem->pValue, dwColumn );
  4280. }
  4281. LONG
  4282. DynArrayFindLong(
  4283. TARRAY pArray,
  4284. LONG lValue
  4285. )
  4286. /*++
  4287. // Routine Description:
  4288. // This function returns the index of the Long variable.
  4289. //
  4290. // Arguments:
  4291. // [ in ] pArray - Dynamic Array
  4292. // [ in ] lValue - the item to be searched. .
  4293. //
  4294. //
  4295. // Return Value:
  4296. // the index of the element .
  4297. --*/
  4298. {
  4299. // return the value
  4300. return __DynArrayFind( pArray, DA_TYPE_LONG, &lValue, FALSE, 0 );
  4301. }
  4302. LONG
  4303. DynArrayFindDWORD(
  4304. TARRAY pArray,
  4305. DWORD dwValue
  4306. )
  4307. /*++
  4308. // Routine Description:
  4309. // This function returns the index of the DWORD variable.
  4310. //
  4311. // Arguments:
  4312. // [ in ] pArray - Dynamic Array
  4313. // [ in ] dwValue - value to be searched.
  4314. //
  4315. // Return Value:
  4316. // the index of the element .
  4317. --*/
  4318. {
  4319. // return the value
  4320. return __DynArrayFind( pArray, DA_TYPE_DWORD, &dwValue, FALSE, 0 );
  4321. }
  4322. LONG
  4323. DynArrayFindFloat(
  4324. TARRAY pArray,
  4325. float fValue
  4326. )
  4327. /*++
  4328. // Routine Description:
  4329. // This function returns the index of the float variable.
  4330. //
  4331. // Arguments:
  4332. // [ in ] pArray - Dynamic Array
  4333. // [ in ] fValue - the item to be searched. .
  4334. //
  4335. // Return Value:
  4336. // the index of the element .
  4337. --*/
  4338. {
  4339. // return the value
  4340. return __DynArrayFind( pArray, DA_TYPE_FLOAT, &fValue, FALSE, 0 );
  4341. }
  4342. LONG
  4343. DynArrayFindDouble(
  4344. TARRAY pArray,
  4345. double dblValue
  4346. )
  4347. /*++
  4348. // Routine Description:
  4349. // This function returns the index of the double type variable.
  4350. //
  4351. // Arguments:
  4352. // [ in ] pArray - Dynamic Array
  4353. // [ in ] dblValue - the item to be searched. .
  4354. //
  4355. // Return Value:
  4356. // the index of the element .
  4357. --*/
  4358. {
  4359. // return the value
  4360. return __DynArrayFind( pArray, DA_TYPE_DOUBLE, &dblValue, FALSE, 0 );
  4361. }
  4362. LONG
  4363. DynArrayFindHandle(
  4364. TARRAY pArray,
  4365. HANDLE hValue
  4366. )
  4367. /*++
  4368. // Routine Description:
  4369. // This function returns the index of the HANDLE type variable.
  4370. //
  4371. // Arguments:
  4372. // [ in ] pArray - Dynamic Array
  4373. // [ in ] hValue - the HANDLE type item to be searched. .
  4374. //
  4375. // Return Value:
  4376. // the index of the element .
  4377. --*/
  4378. {
  4379. // return the value
  4380. return __DynArrayFind( pArray, DA_TYPE_HANDLE, &hValue, FALSE, 0 );
  4381. }
  4382. LONG
  4383. DynArrayFindString(
  4384. TARRAY pArray,
  4385. LPCWSTR szValue,
  4386. BOOL bIgnoreCase,
  4387. DWORD dwCount
  4388. )
  4389. /*++
  4390. // Routine Description:
  4391. // This function returns the index of the String type variable.
  4392. //
  4393. // Arguments:
  4394. // [ in ] pArray - Dynamic Array.
  4395. // [ in ] szValue - pointer to the string.
  4396. // [ in ] bIgnoreCase - boolean indicating if to perform
  4397. // case sensitive search or not.
  4398. // [ in ] dwCount - string length.
  4399. //
  4400. // Return Value:
  4401. // the index of the element .
  4402. --*/
  4403. {
  4404. // return the value
  4405. return __DynArrayFind( pArray, DA_TYPE_STRING, ( LPVOID ) szValue, bIgnoreCase, dwCount );
  4406. }
  4407. LONG
  4408. DynArrayFindSystemTime(
  4409. TARRAY pArray,
  4410. SYSTEMTIME stValue
  4411. )
  4412. /*++
  4413. // Routine Description:
  4414. // This function returns the index of the SYSTEMTIME type variable.
  4415. //
  4416. // Arguments:
  4417. // [ in ] pArray - Dynamic Array
  4418. // [ in ] stValue - the SYSTEMTIME item to be searched. .
  4419. //
  4420. // Return Value:
  4421. // the index of the element .
  4422. --*/
  4423. {
  4424. // return the value
  4425. return __DynArrayFind( pArray, DA_TYPE_SYSTEMTIME, &stValue, FALSE, 0 );
  4426. }
  4427. LONG
  4428. DynArrayFindFileTime(
  4429. TARRAY pArray,
  4430. FILETIME ftValue
  4431. )
  4432. /*++
  4433. // Routine Description:
  4434. // This function returns the index of the FILETIME type variable.
  4435. //
  4436. // Arguments:
  4437. // [ in ] pArray - Dynamic Array
  4438. // [ in ] ftValue - the item of type FILETIME to be searched. .
  4439. //
  4440. // Return Value:
  4441. // the index of the element .
  4442. --*/
  4443. {
  4444. // return the value
  4445. return __DynArrayFind( pArray, DA_TYPE_FILETIME, &ftValue, FALSE, 0 );
  4446. }
  4447. LONG
  4448. DynArrayFindLong2(
  4449. TARRAY pArray,
  4450. DWORD dwRow,
  4451. LONG lValue
  4452. )
  4453. /*++
  4454. // Routine Description:
  4455. // This function returns the index of the LONG type variable from a 2-d dynamic array.
  4456. //
  4457. // Arguments:
  4458. // [ in ] pArray - Dynamic Array
  4459. // [ in ] dwRow - row
  4460. // [ in ] lValue - the item of type LONG to be searched. .
  4461. //
  4462. // Return Value:
  4463. // the index of the element .
  4464. --*/
  4465. {
  4466. // local variables
  4467. __PTITEM pItem = NULL;
  4468. // get the item at the required row
  4469. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4470. if ( ( NULL == pItem ) ||
  4471. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4472. return -1; // no item exists at the specified row or item is not of type array
  4473. // return the value
  4474. return DynArrayFindLong( pItem->pValue, lValue );
  4475. }
  4476. LONG
  4477. DynArrayFindDWORD2(
  4478. TARRAY pArray,
  4479. DWORD dwRow,
  4480. DWORD dwValue
  4481. )
  4482. /*++
  4483. // Routine Description:
  4484. // This function returns the index of the DWORD type variable from a 2-d dynamic array.
  4485. //
  4486. // Arguments:
  4487. // [ in ] pArray - Dynamic Array
  4488. // [ in ] dwRow - row
  4489. // [ in ] dwValue - the item of type DWORD to be searched. .
  4490. //
  4491. // Return Value:
  4492. // the index of the element .
  4493. --*/
  4494. {
  4495. // local variables
  4496. __PTITEM pItem = NULL;
  4497. // get the item at the required row
  4498. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4499. if ( ( NULL == pItem ) ||
  4500. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4501. {
  4502. return -1; // no item exists at the specified row or item is not of type array
  4503. }
  4504. // return the value
  4505. return DynArrayFindDWORD( pItem->pValue, dwValue );
  4506. }
  4507. LONG
  4508. DynArrayFindString2(
  4509. TARRAY pArray,
  4510. DWORD dwRow,
  4511. LPCWSTR szValue,
  4512. BOOL bIgnoreCase,
  4513. DWORD dwCount
  4514. )
  4515. /*++
  4516. // Routine Description:
  4517. // This function returns the index of the DWORD type variable from a 2-d dynamic array.
  4518. //
  4519. // Arguments:
  4520. // [ in ] pArray - Dynamic Array
  4521. // [ in ] dwRow - row
  4522. // [ in ] szValue - pointer to the string.
  4523. // [ in ] bIgnoreCase - boolean for case sensitive search.
  4524. // [ in ] dwCount - string length. .
  4525. //
  4526. // Return Value:
  4527. // the index of the element .
  4528. --*/
  4529. {
  4530. // local variables
  4531. __PTITEM pItem = NULL;
  4532. // get the item at the required row
  4533. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4534. if ( ( NULL == pItem ) ||
  4535. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4536. {
  4537. return -1; // no item exists at the specified row or item is not of type array
  4538. }
  4539. // return the value
  4540. return DynArrayFindString( pItem->pValue, szValue, bIgnoreCase, dwCount );
  4541. }
  4542. LONG
  4543. DynArrayFindFloat2(
  4544. TARRAY pArray,
  4545. DWORD dwRow,
  4546. float fValue
  4547. )
  4548. /*++
  4549. // Routine Description:
  4550. // This function returns the index of the float type variable from a 2-d dynamic array.
  4551. //
  4552. // Arguments:
  4553. // [ in ] pArray - Dynamic Array
  4554. // [ in ] dwRow - row
  4555. // [ in ] fValue - float value.
  4556. //
  4557. // Return Value:
  4558. // the index of the element .
  4559. --*/
  4560. {
  4561. // local variables
  4562. __PTITEM pItem = NULL;
  4563. // get the item at the required row
  4564. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4565. if ( ( NULL == pItem ) ||
  4566. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4567. {
  4568. return -1; // no item exists at the specified row or item is not of type array
  4569. }
  4570. // return the value
  4571. return DynArrayFindFloat( pItem->pValue, fValue );
  4572. }
  4573. LONG
  4574. DynArrayFindDouble2(
  4575. TARRAY pArray,
  4576. DWORD dwRow,
  4577. double dblValue
  4578. )
  4579. /*++
  4580. // Routine Description:
  4581. // This function returns the index of the double type variable from a 2-d array.
  4582. //
  4583. // Arguments:
  4584. // [ in ] pArray - Dynamic Array
  4585. // [ in ] dwRow - row posn
  4586. // [ in ] dblValue - the item to be searched. .
  4587. //
  4588. // Return Value:
  4589. // the index of the element .
  4590. --*/
  4591. {
  4592. // local variables
  4593. __PTITEM pItem = NULL;
  4594. // get the item at the required row
  4595. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4596. if ( ( NULL == pItem ) ||
  4597. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4598. {
  4599. return -1; // no item exists at the specified row or item is not of type array
  4600. }
  4601. // return the value
  4602. return DynArrayFindDouble( pItem->pValue, dblValue );
  4603. }
  4604. LONG
  4605. DynArrayFindHandle2(
  4606. TARRAY pArray,
  4607. DWORD dwRow,
  4608. HANDLE hValue
  4609. )
  4610. /*++
  4611. // Routine Description:
  4612. // This function returns the index of the HANDLE type variable from a 2-d array.
  4613. //
  4614. // Arguments:
  4615. // [ in ] pArray - Dynamic Array
  4616. // [ in ] dwRow - row posn
  4617. // [ in ] hValue - the HANDLE type item to be searched. .
  4618. //
  4619. // Return Value:
  4620. // the index of the element .
  4621. --*/
  4622. {
  4623. // local variables
  4624. __PTITEM pItem = NULL;
  4625. // get the item at the required row
  4626. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4627. if ( ( NULL == pItem ) ||
  4628. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4629. {
  4630. return -1; // no item exists at the specified row or item is not of type array
  4631. }
  4632. // return the value
  4633. return DynArrayFindHandle( pItem->pValue, hValue );
  4634. }
  4635. LONG
  4636. DynArrayFindSystemTime2(
  4637. TARRAY pArray,
  4638. DWORD dwRow,
  4639. SYSTEMTIME stValue
  4640. )
  4641. /*++
  4642. // Routine Description:
  4643. // This function returns the index of the SYSTEMTIME type variable from a 2-d array.
  4644. //
  4645. // Arguments:
  4646. // [ in ] pArray - Dynamic Array
  4647. // [ in ] dwRow - row posn
  4648. // [ in ] stValue - the SYSTEMTIME type item to be searched. .
  4649. //
  4650. // Return Value:
  4651. // the index of the element .
  4652. --*/
  4653. {
  4654. // local variables
  4655. __PTITEM pItem = NULL;
  4656. // get the item at the required row
  4657. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4658. if ( ( NULL == pItem ) ||
  4659. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4660. {
  4661. return -1; // no item exists at the specified row or item is not of type array
  4662. }
  4663. // return the value
  4664. return DynArrayFindSystemTime( pItem->pValue, stValue );
  4665. }
  4666. LONG
  4667. DynArrayFindFileTime2(
  4668. TARRAY pArray,
  4669. DWORD dwRow,
  4670. FILETIME ftValue
  4671. )
  4672. /*++
  4673. // Routine Description:
  4674. // This function returns the index of the FILETIME type variable from a 2-d array.
  4675. //
  4676. // Arguments:
  4677. // [ in ] pArray - Dynamic Array
  4678. // [ in ] dwRow - row posn
  4679. // [ in ] ftValue - the FILETIME type item to be searched. .
  4680. //
  4681. // Return Value:
  4682. // the index of the element .
  4683. --*/
  4684. {
  4685. // local variables
  4686. __PTITEM pItem = NULL;
  4687. // get the item at the required row
  4688. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4689. if ( ( NULL == pItem ) ||
  4690. ( DA_TYPE_ARRAY != pItem->dwType ) )
  4691. {
  4692. return -1; // no item exists at the specified row or item is not of type array
  4693. }
  4694. // return the value
  4695. return DynArrayFindFileTime( pItem->pValue, ftValue );
  4696. }
  4697. LONG
  4698. DynArrayFindLongEx(
  4699. TARRAY pArray,
  4700. DWORD dwColumn,
  4701. LONG lValue
  4702. )
  4703. /*++
  4704. // Routine Description:
  4705. // This function returns the index of the LONG type variable from a 2-d array.
  4706. //
  4707. // Arguments:
  4708. // [ in ] pArray - Dynamic Array
  4709. // [ in ] dwColumn - column posn
  4710. // [ in ] lValue - the LONG type item to be searched. .
  4711. //
  4712. // Return Value:
  4713. // the index of the element .
  4714. --*/
  4715. {
  4716. // return the value
  4717. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_LONG, &lValue, FALSE, 0 );
  4718. }
  4719. LONG
  4720. DynArrayFindDWORDEx(
  4721. TARRAY pArray,
  4722. DWORD dwColumn,
  4723. DWORD dwValue
  4724. )
  4725. /*++
  4726. // Routine Description:
  4727. // This function returns the index of the DWORD type variable from a 2-d array.
  4728. //
  4729. // Arguments:
  4730. // [ in ] pArray - Dynamic Array
  4731. // [ in ] dwColumn - column posn
  4732. // [ in ] dwValue - the DWORD type item to be searched. .
  4733. //
  4734. // Return Value:
  4735. // the index of the element .
  4736. --*/
  4737. {
  4738. // return the value
  4739. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_DWORD, &dwValue, FALSE, 0 );
  4740. }
  4741. LONG
  4742. DynArrayFindFloatEx(
  4743. TARRAY pArray,
  4744. DWORD dwColumn,
  4745. float fValue
  4746. )
  4747. /*++
  4748. // Routine Description:
  4749. // This function returns the index of the fValue type variable from a 2-d array.
  4750. //
  4751. // Arguments:
  4752. // [ in ] pArray - Dynamic Array
  4753. // [ in ] dwColumn - column posn
  4754. // [ in ] fValue - the float type item to be searched. .
  4755. //
  4756. // Return Value:
  4757. // the index of the element .
  4758. --*/
  4759. {
  4760. // return the value
  4761. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_FLOAT, &fValue, FALSE, 0 );
  4762. }
  4763. LONG
  4764. DynArrayFindDoubleEx(
  4765. TARRAY pArray,
  4766. DWORD dwColumn,
  4767. double dblValue
  4768. )
  4769. /*++
  4770. // Routine Description:
  4771. // This function returns the index of the double type variable from a 2-d array.
  4772. //
  4773. // Arguments:
  4774. // [ in ] pArray - Dynamic Array
  4775. // [ in ] dwColumn - column posn
  4776. // [ in ] dblValue - the double type item to be searched. .
  4777. //
  4778. // Return Value:
  4779. // the index of the element .
  4780. --*/
  4781. {
  4782. // return the value
  4783. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_DOUBLE, &dblValue, FALSE, 0 );
  4784. }
  4785. LONG
  4786. DynArrayFindHandleEx(
  4787. TARRAY pArray,
  4788. DWORD dwColumn,
  4789. HANDLE hValue
  4790. )
  4791. /*++
  4792. // Routine Description:
  4793. // This function returns the index of the HANDLE type variable from a 2-d array.
  4794. //
  4795. // Arguments:
  4796. // [ in ] pArray - Dynamic Array
  4797. // [ in ] dwColumn - column posn
  4798. // [ in ] hValue - the HANDLE type item to be searched. .
  4799. //
  4800. // Return Value:
  4801. // the index of the element .
  4802. --*/
  4803. {
  4804. // return the value
  4805. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_HANDLE, &hValue, FALSE, 0 );
  4806. }
  4807. LONG
  4808. DynArrayFindSystemTimeEx(
  4809. TARRAY pArray,
  4810. DWORD dwColumn,
  4811. SYSTEMTIME stValue
  4812. )
  4813. /*++
  4814. // Routine Description:
  4815. // This function returns the index of the SYSTEMTIME type variable from a 2-d array.
  4816. //
  4817. // Arguments:
  4818. // [ in ] pArray - Dynamic Array
  4819. // [ in ] dwColumn - column posn
  4820. // [ in ] stValue - the SYSTEMTIME type item to be searched. .
  4821. //
  4822. // Return Value:
  4823. // the index of the element .
  4824. --*/
  4825. {
  4826. // return the value
  4827. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_SYSTEMTIME, &stValue, FALSE, 0 );
  4828. }
  4829. LONG
  4830. DynArrayFindFileTimeEx(
  4831. TARRAY pArray,
  4832. DWORD dwColumn,
  4833. FILETIME ftValue
  4834. )
  4835. /*++
  4836. // Routine Description:
  4837. // This function returns the index of the FILETIME type variable from a 2-d array.
  4838. //
  4839. // Arguments:
  4840. // [ in ] pArray - Dynamic Array
  4841. // [ in ] dwColumn - column posn
  4842. // [ in ] ftValue - the FILETIME type item to be searched. .
  4843. //
  4844. // Return Value:
  4845. // the index of the element .
  4846. --*/
  4847. {
  4848. // return the value
  4849. return __DynArrayFindEx( pArray, dwColumn, DA_TYPE_FILETIME, &ftValue, FALSE, 0 );
  4850. }
  4851. LONG
  4852. DynArrayFindStringEx(
  4853. TARRAY pArray,
  4854. DWORD dwColumn,
  4855. LPCWSTR szValue,
  4856. BOOL bIgnoreCase,
  4857. DWORD dwCount
  4858. )
  4859. /*++
  4860. // Routine Description:
  4861. // This function returns the index of the string type variable from a 2-d array.
  4862. //
  4863. // Arguments:
  4864. // [ in ] pArray - Dynamic Array
  4865. // [ in ] dwColumn - column posn
  4866. // [ in ] szValue - pointer to the string
  4867. // [ in ] bIgnorecase - boolean for case sensitive search.
  4868. // [ in ] dwCount - string length
  4869. //
  4870. // Return Value:
  4871. // the index of the element .
  4872. --*/
  4873. {
  4874. // return the value
  4875. return __DynArrayFindEx( pArray, dwColumn,
  4876. DA_TYPE_STRING, (LPVOID) szValue, bIgnoreCase, dwCount );
  4877. }
  4878. LONG
  4879. DynArrayAppendEx(
  4880. TARRAY pArray,
  4881. TARRAY pArrItem
  4882. )
  4883. /*++
  4884. // Routine Description:
  4885. // This function returns the index of the FILETIME type variable from a 2-d array.
  4886. //
  4887. // Arguments:
  4888. // [ in ] pArray - Dynamic Array
  4889. // [ in ] pArrItem - Dynamic Array to be appended.
  4890. //
  4891. // Return Value:
  4892. // the pointer to the array.
  4893. --*/
  4894. {
  4895. // validate the array
  4896. if ( ( FALSE == IsValidArray( pArray ) ) ||
  4897. ( FALSE == IsValidArray( pArrItem ) ) )
  4898. {
  4899. return -1; // array is not valid
  4900. }
  4901. // now add this sub array to the main array and return the result
  4902. return __DynArrayAppend( pArray, DA_TYPE_ARRAY, sizeof( TARRAY ), pArrItem );
  4903. }
  4904. LONG
  4905. DynArrayInsertEx(
  4906. TARRAY pArray,
  4907. DWORD dwIndex,
  4908. TARRAY pArrItem
  4909. )
  4910. /*++
  4911. // Routine Description:
  4912. // replaces a element with an dynamic array.
  4913. //
  4914. // Arguments:
  4915. // [ in ] pArray - Dynamic Array
  4916. // [ in ] dwIndex - Dynamic Array to be appended.
  4917. // [ in ] pArrItem - pointer to the TARRAY.
  4918. //
  4919. // Return Value:
  4920. // the pointer to the array..
  4921. --*/
  4922. {
  4923. // validate the array
  4924. if ( ( FALSE == IsValidArray( pArray ) ) ||
  4925. ( FALSE == IsValidArray( pArrItem ) ) )
  4926. {
  4927. return -1; // array is not valid
  4928. }
  4929. // now insert this sub array to the main array and check the result
  4930. return __DynArrayInsert( pArray, dwIndex, DA_TYPE_ARRAY, sizeof( TARRAY ), pArrItem );
  4931. }
  4932. BOOL
  4933. DynArraySetEx(
  4934. TARRAY pArray,
  4935. DWORD dwIndex,
  4936. TARRAY pArrItem
  4937. )
  4938. /*++
  4939. // Routine Description:
  4940. // inserts a dynamic array at the specified posn..
  4941. //
  4942. // Arguments:
  4943. // [ in ] pArray - Dynamic Array
  4944. // [ in ] dwIndex - Dynamic Array to be appended.
  4945. // [ in ] pArrItem - pointer to the TARRAY.
  4946. //
  4947. // Return Value:
  4948. // the pointer to the array..
  4949. --*/
  4950. {
  4951. // local variables
  4952. __PTITEM pItem = NULL;
  4953. // validate the array
  4954. if ( FALSE == IsValidArray( pArray ) ||
  4955. FALSE == IsValidArray( pArrItem ) )
  4956. {
  4957. return FALSE;
  4958. }
  4959. // get the item at the required index
  4960. pItem = __DynArrayGetItem( pArray, dwIndex, NULL );
  4961. if ( NULL == pItem )
  4962. {
  4963. return FALSE; // item not found / invalid array pointer
  4964. }
  4965. // check the data type ... it should not be initialized yet or of array type
  4966. if ( ( DA_TYPE_ARRAY != pItem->dwType ) && ( _TYPE_NEEDINIT != pItem->dwType ) )
  4967. {
  4968. return FALSE;
  4969. }
  4970. // set the value of the current item
  4971. pItem->pValue = pArrItem;
  4972. pItem->dwType = DA_TYPE_ARRAY;
  4973. // return the result
  4974. return TRUE;
  4975. }
  4976. LONG
  4977. DynArrayAppendEx2(
  4978. TARRAY pArray,
  4979. DWORD dwRow,
  4980. TARRAY pArrItem
  4981. )
  4982. /*++
  4983. // Routine Description:
  4984. // appends a dynamic array at the specified posn..
  4985. //
  4986. // Arguments:
  4987. // [ in ] pArray - Dynamic Array
  4988. // [ in ] dwRow - row no
  4989. // [ in ] pArrItem - pointer to the TARRAY.
  4990. //
  4991. // Return Value:
  4992. // the pointer to the array..
  4993. --*/
  4994. {
  4995. // local variables
  4996. __PTITEM pItem = NULL;
  4997. // get the item at the required row
  4998. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  4999. if ( ( NULL == pItem ) ||
  5000. ( DA_TYPE_ARRAY != pItem->dwType ) )
  5001. {
  5002. return -1; // no item exists at the specified row or item is not of type array
  5003. }
  5004. // return the value
  5005. return DynArrayAppendEx( pItem->pValue, pArrItem );
  5006. }
  5007. LONG
  5008. DynArrayInsertEx2(
  5009. TARRAY pArray,
  5010. DWORD dwRow,
  5011. DWORD dwColIndex,
  5012. TARRAY pArrItem
  5013. )
  5014. /*++
  5015. // Routine Description:
  5016. // inserts a dynamic array at the specified posn..
  5017. //
  5018. // Arguments:
  5019. // [ in ] pArray - Dynamic Array
  5020. // [ in ] dwRow - row value
  5021. // [ in ] dwColIndex - column posn.
  5022. // [ in ] pArrItem - pointer to the TARRAY.
  5023. //
  5024. // Return Value:
  5025. // the pointer to the array..
  5026. --*/
  5027. {
  5028. // local variables
  5029. __PTITEM pItem = NULL;
  5030. // get the item at the required row
  5031. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  5032. if ( ( NULL == pItem ) ||
  5033. ( DA_TYPE_ARRAY != pItem->dwType ) )
  5034. {
  5035. return -1; // no item exists at the specified row or item is not of type array
  5036. }
  5037. // return the value
  5038. return DynArrayInsertEx( pItem->pValue, dwColIndex, pArrItem );
  5039. }
  5040. BOOL
  5041. DynArraySetEx2(
  5042. TARRAY pArray,
  5043. DWORD dwRow,
  5044. DWORD dwColumn,
  5045. TARRAY pArrItem
  5046. )
  5047. /*++
  5048. // Routine Description:
  5049. // creates a dynamic array at the specified posn of the 2-d array
  5050. //
  5051. // Arguments:
  5052. // [ in ] pArray - Dynamic Array
  5053. // [ in ] dwRow - row position
  5054. // [ in ] dwColIndex - column posn.
  5055. // [ in ] pArrItem - pointer to the TARRAY.
  5056. //
  5057. // Return Value:
  5058. // the pointer to the array..
  5059. --*/
  5060. {
  5061. // local variables
  5062. __PTITEM pItem = NULL;
  5063. // get the item at the required row
  5064. pItem = __DynArrayGetItem( pArray, dwRow, NULL );
  5065. if ( ( NULL == pItem ) ||
  5066. ( DA_TYPE_ARRAY != pItem->dwType ) )
  5067. {
  5068. return -1; // no item exists at the specified row or item is not of type array
  5069. }
  5070. // return the value
  5071. return DynArraySetEx( pItem->pValue, dwColumn, pArrItem );
  5072. }