Source code of Windows XP (NT5)
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.

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