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.

817 lines
20 KiB

  1. #include "stdafx.h"
  2. // defined with iisrtl2.lib
  3. //DEBUG_PRINTS * g_pDebug;
  4. // open an existing key
  5. // if failure, return NULL pointer and put error into SetLastError();
  6. CRegKey :: CRegKey (HKEY hKeyBase, LPCTSTR pchSubKey,REGSAM regSam ) : m_hKey( NULL ), m_dwDisposition( 0 )
  7. {
  8. LONG err = ERROR_SUCCESS ;
  9. SetLastError(ERROR_SUCCESS);
  10. m_iDisplayWarnings = TRUE;
  11. if ( pchSubKey )
  12. {err = ::RegOpenKeyEx( hKeyBase, pchSubKey, 0, regSam, & m_hKey ) ;}
  13. else
  14. {m_hKey = hKeyBase ;}
  15. if ( err != ERROR_SUCCESS )
  16. {
  17. if (m_hKey) {::RegCloseKey(m_hKey);}
  18. m_hKey = NULL ;
  19. // Check if the error is because it simply doesn't exist.
  20. // if this is the case then don't say failed. Say WARNING.
  21. if ( err == ERROR_FILE_NOT_FOUND )
  22. {
  23. if (m_iDisplayWarnings)
  24. {iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("CRegKey:CRegKey() %s Key doesn't exist. WARNING. Code=0x%x\n"), pchSubKey, err));}
  25. }
  26. else
  27. {
  28. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey:CRegKey() %s FAILED. Err=0x%x\n"), pchSubKey, err));
  29. }
  30. SetLastError(err);
  31. }
  32. }
  33. // Constructor creating a new key/opening a key if already exist, and set value if specified
  34. CRegKey :: CRegKey (LPCTSTR lpSubKey,HKEY hKeyBase,LPCTSTR lpValueName,DWORD dwType,LPBYTE lpValueData,DWORD cbValueData): m_hKey( NULL ),m_dwDisposition( 0 )
  35. {
  36. LONG err = ERROR_SUCCESS;
  37. SetLastError(ERROR_SUCCESS);
  38. m_iDisplayWarnings = TRUE;
  39. err = ::RegCreateKeyEx( hKeyBase, lpSubKey, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, & m_hKey, & m_dwDisposition ) ;
  40. if ( err != ERROR_SUCCESS)
  41. {
  42. if ( m_hKey ) {::RegCloseKey( m_hKey ) ;}
  43. m_hKey = NULL ;
  44. // Check if the error is because it simply doesn't exist.
  45. // if this is the case then don't say failed. Say WARNING.
  46. if ( err == ERROR_FILE_NOT_FOUND )
  47. {
  48. if (m_iDisplayWarnings)
  49. {iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("CRegKey:CRegKey() %s Key doesn't exist. WARNING. Code=0x%x\n"), lpSubKey, err));}
  50. }
  51. else
  52. {
  53. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::CRegKey() Open %s FAILED. err=0x%x\n"), lpSubKey, err));
  54. }
  55. SetLastError(err);
  56. }
  57. else
  58. {
  59. if (lpValueName)
  60. {
  61. ::RegSetValueEx(m_hKey, lpValueName, 0, dwType, (const LPBYTE)lpValueData, cbValueData);
  62. if ( err != ERROR_SUCCESS)
  63. {
  64. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::CRegKey() RegSetValueEx %s, %s FAILED. err=0x%x\n"), lpSubKey,lpValueName, err));
  65. SetLastError(err);
  66. }
  67. }
  68. }
  69. }
  70. CRegKey :: ~ CRegKey ()
  71. {
  72. if (m_hKey) {::RegCloseKey( m_hKey );}
  73. }
  74. // Prepare to read a value by finding the value's size.
  75. LONG CRegKey :: PrepareValue (LPCTSTR pchValueName, DWORD * pdwType,DWORD * pcbSize,BYTE ** ppbData )
  76. {
  77. LONG err = 0 ;
  78. BYTE chDummy[2] ;
  79. DWORD cbData = 0 ;
  80. do
  81. {
  82. // Set the resulting buffer size to 0.
  83. *pcbSize = 0 ;
  84. *ppbData = NULL ;
  85. err = ::RegQueryValueEx( *this, (TCHAR *) pchValueName, 0, pdwType, chDummy, & cbData ) ;
  86. // The only error we should get here is ERROR_MORE_DATA, but
  87. // we may get no error if the value has no data.
  88. if ( err == 0 )
  89. {
  90. cbData = sizeof (LONG) ; // Just a fudgy number
  91. }
  92. else
  93. if ( err != ERROR_MORE_DATA )
  94. break ;
  95. // Allocate a buffer large enough for the data.
  96. *ppbData = new BYTE [ (*pcbSize = cbData) + sizeof (LONG) ] ;
  97. if ( *ppbData == NULL )
  98. {
  99. err = ERROR_NOT_ENOUGH_MEMORY ;
  100. break ;
  101. }
  102. // Now that have a buffer, re-fetch the value.
  103. err = ::RegQueryValueEx( *this, (TCHAR *) pchValueName, 0, pdwType, *ppbData, pcbSize ) ;
  104. } while ( FALSE ) ;
  105. if ( err ) {delete [] *ppbData ;}
  106. return err ;
  107. }
  108. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  109. // if data exists but not in correct form to deliver into result object.
  110. LONG CRegKey :: QueryValue ( LPCTSTR pchValueName, CString & strResult )
  111. {
  112. LONG err = 0 ;
  113. DWORD dwType ;
  114. DWORD cbData ;
  115. BYTE * pabData = NULL ;
  116. do
  117. {
  118. if ( err = PrepareValue( pchValueName, & dwType, & cbData, & pabData ) )
  119. {break ;}
  120. if (( dwType != REG_SZ ) && ( dwType != REG_EXPAND_SZ ))
  121. {
  122. err = ERROR_INVALID_PARAMETER ;
  123. break ;
  124. }
  125. // Guarantee that the data looks like a string
  126. pabData[cbData] = 0 ;
  127. // Catch exceptions trying to assign to the caller's string
  128. TRY
  129. {
  130. strResult = (TCHAR *) pabData ;
  131. }
  132. CATCH_ALL(e)
  133. {
  134. err = ERROR_NOT_ENOUGH_MEMORY ;
  135. }
  136. END_CATCH_ALL
  137. }
  138. while ( FALSE ) ;
  139. // Memory leak....
  140. //if ( err )
  141. //{
  142. delete [] pabData ;
  143. //}
  144. if (err)
  145. {
  146. if ( err == ERROR_FILE_NOT_FOUND )
  147. {
  148. if (m_iDisplayWarnings)
  149. {iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::QueryValue(): %s Not found. WARNING. code=0x%x\n"), pchValueName, err));}
  150. }
  151. else
  152. {
  153. if (err != ERROR_INVALID_PARAMETER)
  154. {
  155. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryValue(): %s FAILED. err=0x%x\n"), pchValueName, err));
  156. }
  157. }
  158. }
  159. return err ;
  160. }
  161. LONG CRegKey :: QueryValue ( LPCTSTR pchValueName, CStringList & strList )
  162. {
  163. LONG err = 0 ;
  164. DWORD dwType ;
  165. DWORD cbData ;
  166. BYTE * pabData = NULL ;
  167. TCHAR * pbTemp, * pbTempLimit ;
  168. do
  169. {
  170. if ( err = PrepareValue( pchValueName, & dwType, & cbData, & pabData ) )
  171. {break ;}
  172. if ( dwType != REG_MULTI_SZ )
  173. {
  174. err = ERROR_INVALID_PARAMETER ;
  175. break ;
  176. }
  177. // Guarantee that the trailing data looks like a string
  178. pabData[cbData] = 0 ;
  179. pbTemp = (TCHAR *) pabData ;
  180. pbTempLimit = (TCHAR *) (& pabData[cbData]) ;
  181. // Catch exceptions trying to build the list
  182. TRY
  183. {
  184. for ( ; pbTemp < pbTempLimit ; )
  185. {
  186. strList.AddTail( pbTemp ) ;
  187. pbTemp += ::_tcslen( pbTemp ) + 1 ;
  188. }
  189. }
  190. CATCH_ALL(e)
  191. {
  192. err = ERROR_NOT_ENOUGH_MEMORY ;
  193. }
  194. END_CATCH_ALL
  195. }
  196. while ( FALSE ) ;
  197. delete [] pabData ;
  198. if (err)
  199. {
  200. if ( err == ERROR_FILE_NOT_FOUND )
  201. {
  202. if (m_iDisplayWarnings)
  203. {iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::QueryValue(): %s Not found. WARNING. code=0x%x\n"), pchValueName, err));}
  204. }
  205. else
  206. {
  207. if (err != ERROR_INVALID_PARAMETER)
  208. {
  209. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryValue(): %s FAILED. err=0x%x.\n"), pchValueName, err));
  210. }
  211. }
  212. }
  213. return err ;
  214. }
  215. LONG CRegKey :: QueryValue ( LPCTSTR pchValueName, DWORD & dwResult )
  216. {
  217. LONG err = 0 ;
  218. DWORD dwType ;
  219. DWORD cbData ;
  220. BYTE * pabData = NULL ;
  221. do
  222. {
  223. if ( err = PrepareValue( pchValueName, & dwType, & cbData, & pabData ) )
  224. break ;
  225. if ( dwType != REG_DWORD || cbData != sizeof dwResult )
  226. {
  227. err = ERROR_INVALID_PARAMETER ;
  228. break ;
  229. }
  230. dwResult = *((DWORD *) pabData) ;
  231. }
  232. while ( FALSE ) ;
  233. // Memory leak...
  234. //if ( err )
  235. //{
  236. delete [] pabData ;
  237. //}
  238. if (err)
  239. {
  240. if ( err == ERROR_FILE_NOT_FOUND )
  241. {
  242. if (m_iDisplayWarnings)
  243. {iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::QueryValue(): %s Not found. WARNING. code=0x%x\n"), pchValueName, err));}
  244. }
  245. else
  246. {
  247. if (err != ERROR_INVALID_PARAMETER)
  248. {
  249. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryValue(): %s FAILED. err=0x%x.\n"), pchValueName, err));
  250. }
  251. }
  252. }
  253. return err ;
  254. }
  255. LONG CRegKey :: QueryValue ( LPCTSTR pchValueName, CByteArray & abResult )
  256. {
  257. LONG err = 0 ;
  258. DWORD dwType ;
  259. DWORD cbData ;
  260. BYTE * pabData = NULL ;
  261. do
  262. {
  263. if ( err = PrepareValue( pchValueName, & dwType, & cbData, & pabData ) )
  264. break ;
  265. if ( dwType != REG_BINARY )
  266. {
  267. err = ERROR_INVALID_PARAMETER ;
  268. break ;
  269. }
  270. // Catch exceptions trying to grow the result array
  271. TRY
  272. {
  273. abResult.SetSize( cbData ) ;
  274. }
  275. CATCH_ALL(e)
  276. {
  277. err = ERROR_NOT_ENOUGH_MEMORY ;
  278. }
  279. END_CATCH_ALL
  280. if ( err )
  281. break ;
  282. // Move the data to the result array.
  283. for ( DWORD i = 0 ; i < cbData ; i++ )
  284. {
  285. abResult[i] = pabData[i] ;
  286. }
  287. }
  288. while ( FALSE ) ;
  289. // Memory leak....
  290. //if ( err )
  291. //{
  292. delete [] pabData ;
  293. //}
  294. if (err)
  295. {
  296. if ( err == ERROR_FILE_NOT_FOUND )
  297. {
  298. if (m_iDisplayWarnings)
  299. {iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::QueryValue(): %s Not found. WARNING. code=0x%x\n"), pchValueName, err));}
  300. }
  301. else
  302. {
  303. if (err != ERROR_INVALID_PARAMETER)
  304. {
  305. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryValue(): %s FAILED. err=0x%x.\n"), pchValueName, err));
  306. }
  307. }
  308. }
  309. return err ;
  310. }
  311. LONG CRegKey :: QueryValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize )
  312. {
  313. LONG err = 0 ;
  314. DWORD dwType ;
  315. DWORD cbData ;
  316. BYTE * pabData = NULL ;
  317. do
  318. {
  319. if ( err = PrepareValue( pchValueName, & dwType, & cbData, & pabData ) )
  320. break ;
  321. if ( dwType != REG_BINARY )
  322. {
  323. err = ERROR_INVALID_PARAMETER ;
  324. break ;
  325. }
  326. if ( cbSize < cbData )
  327. {
  328. err = ERROR_MORE_DATA;
  329. break;
  330. }
  331. ::memcpy(pvResult, pabData, cbData);
  332. }
  333. while ( FALSE ) ;
  334. // Memory leak....
  335. //if ( err )
  336. //{
  337. delete [] pabData ;
  338. //}
  339. if (err)
  340. {
  341. if ( err == ERROR_FILE_NOT_FOUND )
  342. {
  343. if (m_iDisplayWarnings)
  344. {iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::QueryValue(): %s Not found. WARNING. code=0x%x\n"), pchValueName, err));}
  345. }
  346. else
  347. {
  348. if (err != ERROR_INVALID_PARAMETER)
  349. {
  350. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryValue(): %s FAILED. err=0x%x.\n"), pchValueName, err));
  351. }
  352. }
  353. }
  354. return err ;
  355. }
  356. // Overloaded value setting members.
  357. LONG CRegKey :: SetValue ( LPCTSTR pchValueName, LPCTSTR szResult, BOOL fExpand )
  358. {
  359. LONG err = 0;
  360. err = ::RegSetValueEx( *this, pchValueName,0,fExpand ? REG_EXPAND_SZ : REG_SZ,(const BYTE *) szResult,(_tcsclen(szResult) + 1) * sizeof(_TCHAR) ) ;
  361. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::SetValue(): %s FAILED, err=0x%x\n"), pchValueName,err));}
  362. return err ;
  363. }
  364. LONG CRegKey :: SetValue ( LPCTSTR pchValueName, CStringList & strList )
  365. {
  366. LONG err = 0;
  367. DWORD cbSize ;
  368. BYTE * pbData = NULL ;
  369. err = FlattenValue( strList, & cbSize, & pbData ) ;
  370. if ( err == 0 )
  371. {
  372. err = ::RegSetValueEx( *this, pchValueName,0,REG_MULTI_SZ,pbData, cbSize ) ;
  373. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::SetValue(): %s FAILED, err=0x%x\n"), pchValueName,err));}
  374. }
  375. delete pbData ;
  376. return err ;
  377. }
  378. LONG CRegKey :: SetValue ( LPCTSTR pchValueName, DWORD dwResult )
  379. {
  380. LONG err = 0;
  381. err = ::RegSetValueEx( *this, pchValueName,0,REG_DWORD,(const BYTE *) & dwResult,sizeof dwResult ) ;
  382. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::SetValue(): %s FAILED, err=0x%x\n"), pchValueName,err));}
  383. return err ;
  384. }
  385. LONG CRegKey :: SetValue ( LPCTSTR pchValueName, CByteArray & abResult )
  386. {
  387. LONG err = 0;
  388. DWORD cbSize ;
  389. BYTE * pbData = NULL ;
  390. err = FlattenValue( abResult, & cbSize, & pbData ) ;
  391. if ( err == 0 )
  392. {
  393. err = ::RegSetValueEx( *this, pchValueName,0,REG_BINARY,pbData, cbSize ) ;
  394. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::SetValue(): %s FAILED, err=0x%x\n"), pchValueName,err));}
  395. }
  396. delete pbData ;
  397. return err ;
  398. }
  399. LONG CRegKey :: SetValue ( LPCTSTR pchValueName, void * pvResult, DWORD cbSize )
  400. {
  401. LONG err = 0;
  402. err = ::RegSetValueEx( *this, pchValueName,0,REG_BINARY,(const BYTE *)pvResult, cbSize ) ;
  403. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::SetValue(): %s FAILED, err=0x%x\n"), pchValueName,err));}
  404. return err ;
  405. }
  406. LONG CRegKey::DeleteValue( LPCTSTR pchKeyName )
  407. {
  408. LONG err = 0;
  409. err = ::RegDeleteValue( *this, pchKeyName );
  410. if (err != ERROR_SUCCESS)
  411. {
  412. if ( err != ERROR_FILE_NOT_FOUND )
  413. {
  414. if (m_iDisplayWarnings)
  415. iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::DeleteValue(): %s FAILED, err=0x%x\n"), pchKeyName,err));
  416. }
  417. }
  418. return(err);
  419. }
  420. LONG CRegKey::DeleteTree( LPCTSTR pchKeyName )
  421. {
  422. LONG err = 0;
  423. CRegKey regSubKey( *this, pchKeyName );
  424. if ( NULL != (HKEY) regSubKey )
  425. {
  426. CString strName;
  427. CTime cTime;
  428. while (TRUE)
  429. {
  430. CRegKeyIter regEnum( regSubKey );
  431. if ( regEnum.Next( &strName, &cTime ) != ERROR_SUCCESS )
  432. {
  433. break;
  434. }
  435. regSubKey.DeleteTree( strName );
  436. }
  437. // delete myself
  438. err = ::RegDeleteKey( *this, pchKeyName );
  439. }
  440. return(err);
  441. }
  442. LONG CRegKey :: FlattenValue ( CStringList & strList, DWORD * pcbSize, BYTE ** ppbData )
  443. {
  444. LONG err = 0 ;
  445. POSITION pos ;
  446. CString * pstr ;
  447. int cbTotal = 0 ;
  448. // Walk the list accumulating sizes
  449. for ( pos = strList.GetHeadPosition() ; pos != NULL && (pstr = & strList.GetNext( pos )) ; )
  450. {
  451. cbTotal += ((pstr->GetLength() + 1)*sizeof(TCHAR));
  452. }
  453. // Allocate and fill a temporary buffer
  454. if (*pcbSize = cbTotal)
  455. {
  456. TRY
  457. {
  458. *ppbData = new BYTE[ *pcbSize ] ;
  459. if (*ppbData)
  460. {
  461. BYTE * pbData = *ppbData ;
  462. // Populate the buffer with the strings.
  463. for ( pos = strList.GetHeadPosition() ; pos != NULL && (pstr = & strList.GetNext( pos )) ; )
  464. {
  465. int cb = (pstr->GetLength() + 1)*sizeof(TCHAR) ;
  466. ::memcpy( pbData, (LPCTSTR) *pstr, cb ) ;
  467. pbData += cb ;
  468. }
  469. }
  470. else
  471. {
  472. err = ERROR_NOT_ENOUGH_MEMORY ;
  473. }
  474. }
  475. CATCH_ALL(e)
  476. {
  477. err = ERROR_NOT_ENOUGH_MEMORY ;
  478. }
  479. END_CATCH_ALL
  480. }
  481. else
  482. {
  483. *ppbData = NULL;
  484. }
  485. if (err)
  486. {
  487. iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::FlattenValue(): %s FAILED. err=0x%x.\n"), strList, err));
  488. }
  489. return err ;
  490. }
  491. LONG CRegKey :: FlattenValue ( CByteArray & abData,DWORD * pcbSize,BYTE ** ppbData )
  492. {
  493. LONG err = 0 ;
  494. DWORD i ;
  495. // Allocate and fill a temporary buffer
  496. if (*pcbSize = (DWORD)abData.GetSize())
  497. {
  498. TRY
  499. {
  500. *ppbData = new BYTE[*pcbSize] ;
  501. if (*ppbData)
  502. {
  503. for ( i = 0 ; i < *pcbSize ; i++ )
  504. {
  505. (*ppbData)[i] = abData[i] ;
  506. }
  507. }
  508. else
  509. {
  510. err = ERROR_NOT_ENOUGH_MEMORY ;
  511. }
  512. }
  513. CATCH_ALL(e)
  514. {
  515. err = ERROR_NOT_ENOUGH_MEMORY ;
  516. }
  517. END_CATCH_ALL
  518. }
  519. else
  520. {
  521. *ppbData = NULL;
  522. }
  523. if (err)
  524. {
  525. iisDebugOut((LOG_TYPE_WARN, _T("CRegKey::FlattenValue(): FAILED. err=0x%x.\n"), err));
  526. }
  527. return err ;
  528. }
  529. LONG CRegKey :: QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo )
  530. {
  531. LONG err = 0 ;
  532. pRegKeyInfo->dwClassNameSize = sizeof pRegKeyInfo->chBuff - 1 ;
  533. err = ::RegQueryInfoKey( *this,pRegKeyInfo->chBuff,& pRegKeyInfo->dwClassNameSize,NULL,& pRegKeyInfo->dwNumSubKeys,& pRegKeyInfo->dwMaxSubKey,& pRegKeyInfo->dwMaxClass,& pRegKeyInfo->dwMaxValues,& pRegKeyInfo->dwMaxValueName,& pRegKeyInfo->dwMaxValueData,& pRegKeyInfo->dwSecDesc,& pRegKeyInfo->ftKey ) ;
  534. if (err != ERROR_SUCCESS) {iisDebugOut((LOG_TYPE_ERROR, _T("CRegKey::QueryKeyInfo(): FAILED. err=0x%x.\n"), err));}
  535. return err ;
  536. }
  537. CRegKeyIter :: CRegKeyIter ( CRegKey & regKey ) : m_rk_iter( regKey ),m_p_buffer( NULL ),m_cb_buffer( 0 )
  538. {
  539. LONG err = 0 ;
  540. CRegKey::CREGKEY_KEY_INFO regKeyInfo ;
  541. Reset() ;
  542. err = regKey.QueryKeyInfo( & regKeyInfo ) ;
  543. if ( err == 0 )
  544. {
  545. TRY
  546. {
  547. m_cb_buffer = regKeyInfo.dwMaxSubKey + sizeof (DWORD) ;
  548. m_p_buffer = new TCHAR [ m_cb_buffer ] ;
  549. }
  550. CATCH_ALL(e)
  551. {
  552. err = ERROR_NOT_ENOUGH_MEMORY ;
  553. }
  554. END_CATCH_ALL
  555. }
  556. if (err)
  557. {
  558. if (ERROR_NO_MORE_ITEMS != err)
  559. {
  560. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKeyIter::CRegKeyIter(): FAILED. err=0x%x.\n"), err));
  561. }
  562. }
  563. }
  564. CRegKeyIter :: ~ CRegKeyIter ()
  565. {
  566. delete [] m_p_buffer ;
  567. }
  568. // Get the name (and optional last write time) of the next key.
  569. LONG CRegKeyIter :: Next ( CString * pstrName, CTime * pTime )
  570. {
  571. LONG err = 0;
  572. FILETIME ftDummy ;
  573. DWORD dwNameSize = m_cb_buffer ;
  574. err = ::RegEnumKeyEx( m_rk_iter, m_dw_index, m_p_buffer,& dwNameSize, NULL,NULL,NULL,& ftDummy ) ;
  575. if ( err == 0 )
  576. {
  577. m_dw_index++ ;
  578. if ( pTime )
  579. {
  580. *pTime = ftDummy ;
  581. }
  582. TRY
  583. {
  584. *pstrName = m_p_buffer ;
  585. }
  586. CATCH_ALL(e)
  587. {
  588. err = ERROR_NOT_ENOUGH_MEMORY ;
  589. }
  590. END_CATCH_ALL
  591. }
  592. if (err)
  593. {
  594. if (ERROR_NO_MORE_ITEMS != err)
  595. {
  596. iisDebugOut((LOG_TYPE_ERROR, _T("CRegKeyIter::Next(): FAILED. err=0x%x.\n"), err));
  597. }
  598. }
  599. return err ;
  600. }
  601. CRegValueIter :: CRegValueIter ( CRegKey & regKey )
  602. : m_rk_iter( regKey ),
  603. m_p_buffer( NULL ),
  604. m_cb_buffer( 0 )
  605. {
  606. LONG err = 0 ;
  607. CRegKey::CREGKEY_KEY_INFO regKeyInfo ;
  608. Reset() ;
  609. err = regKey.QueryKeyInfo( & regKeyInfo ) ;
  610. if ( err == 0 )
  611. {
  612. TRY
  613. {
  614. m_cb_buffer = regKeyInfo.dwMaxValueName + sizeof (DWORD) ;
  615. m_p_buffer = new TCHAR [ m_cb_buffer ] ;
  616. }
  617. CATCH_ALL(e)
  618. {
  619. err = ERROR_NOT_ENOUGH_MEMORY ;
  620. }
  621. END_CATCH_ALL
  622. }
  623. if (err)
  624. {
  625. if (ERROR_NO_MORE_ITEMS != err)
  626. {
  627. iisDebugOut((LOG_TYPE_ERROR, _T("CRegValueIter::CRegValueIter(): FAILED. err=0x%x.\n"), err));
  628. }
  629. }
  630. }
  631. CRegValueIter :: ~ CRegValueIter ()
  632. {
  633. delete [] m_p_buffer ;
  634. }
  635. LONG CRegValueIter :: Next ( CString * pstrName, DWORD * pdwType )
  636. {
  637. LONG err = 0 ;
  638. DWORD dwNameLength = m_cb_buffer ;
  639. err = ::RegEnumValue( m_rk_iter,m_dw_index,m_p_buffer,& dwNameLength,NULL,pdwType,NULL,NULL ) ;
  640. if ( err == 0 )
  641. {
  642. m_dw_index++ ;
  643. TRY
  644. {
  645. *pstrName = m_p_buffer ;
  646. }
  647. CATCH_ALL(e)
  648. {
  649. err = ERROR_NOT_ENOUGH_MEMORY ;
  650. }
  651. END_CATCH_ALL
  652. }
  653. if (err)
  654. {
  655. if (ERROR_NO_MORE_ITEMS != err)
  656. {
  657. iisDebugOut((LOG_TYPE_ERROR, _T("CRegValueIter::Next(): FAILED. err=0x%x.\n"), err));
  658. }
  659. }
  660. return err ;
  661. }
  662. LONG CRegValueIter :: Next ( CString * pstrName, CString * pstrValue )
  663. {
  664. LONG err = 0 ;
  665. DWORD dwNameLength = m_cb_buffer ;
  666. TCHAR szValue[_MAX_PATH];
  667. DWORD dwValue = _MAX_PATH * sizeof(TCHAR);
  668. err = ::RegEnumValue( m_rk_iter,m_dw_index,m_p_buffer,& dwNameLength,NULL,NULL,(LPBYTE)szValue,&dwValue ) ;
  669. if ( err == 0 )
  670. {
  671. m_dw_index++ ;
  672. TRY
  673. {
  674. *pstrName = m_p_buffer ;
  675. *pstrValue = szValue;
  676. }
  677. CATCH_ALL(e)
  678. {
  679. err = ERROR_NOT_ENOUGH_MEMORY ;
  680. }
  681. END_CATCH_ALL
  682. }
  683. if (err)
  684. {
  685. if (ERROR_NO_MORE_ITEMS != err)
  686. {
  687. iisDebugOut((LOG_TYPE_ERROR, _T("CRegValueIter::Next(): FAILED. err=0x%x.\n"), err));
  688. }
  689. }
  690. return err ;
  691. }