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

1449 lines
46 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: ciniW.cpp
  4. //
  5. // Module: CMUTIL.DLL
  6. //
  7. // Synopsis: Unicode CIni implementation
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. // Author: henryt - relocated to CMUTIL 03/15/98
  12. // quintinb - created A and W versions 05/12/99
  13. //
  14. //+----------------------------------------------------------------------------
  15. #include "cmmaster.h"
  16. //+----------------------------------------------------------------------------
  17. //
  18. // Function: CIniW_Set
  19. //
  20. // Synopsis: This function takes a pointer to a string and a string as arguments. It
  21. // frees the string currently in the destination pointer, allocates the correct
  22. // amount of memory and then copies the source string to the string pointed
  23. // to by the destination string pointer. The allocated memory is the
  24. // responsibility of the caller.
  25. //
  26. // Arguments: LPWSTR *ppszDest - pointer to the destination string
  27. // LPCWSTR pszSrc - source string for the set
  28. //
  29. // Returns: Nothing
  30. //
  31. // History: quintinb Created Header 01/05/2000
  32. //
  33. //+----------------------------------------------------------------------------
  34. static void CIniW_Set(LPWSTR *ppszDest, LPCWSTR pszSrc)
  35. {
  36. MYDBGASSERT(ppszDest);
  37. if (ppszDest)
  38. {
  39. CmFree(*ppszDest);
  40. *ppszDest = ((pszSrc && *pszSrc) ? CmStrCpyAllocW(pszSrc) : NULL);
  41. }
  42. }
  43. //+----------------------------------------------------------------------------
  44. //
  45. // Function: CIniW_LoadCat
  46. //
  47. // Synopsis: This function concatenates the suffix argument onto the string
  48. // argument and returns the resulting string through the return
  49. // value. Note that the function allocates the correct amount of
  50. // memory which must be freed by the caller. Also not passing in
  51. // an empty string returns NULL while passing just an empty suffix
  52. // returns just a copy of the string.
  53. //
  54. // Arguments: LPCWSTR pszStr - source string to duplicate
  55. // LPCWSTR pszSuffix - suffix to add onto the duplicated string
  56. //
  57. // Returns: LPWSTR - a duplicate of the concatenated string
  58. //
  59. // History: quintinb Created Header 01/05/2000
  60. //
  61. //+----------------------------------------------------------------------------
  62. static LPWSTR CIniW_LoadCat(LPCWSTR pszStr, LPCWSTR pszSuffix)
  63. {
  64. LPWSTR pszTmp;
  65. if (!pszStr || !*pszStr)
  66. {
  67. return (NULL);
  68. }
  69. if (!pszSuffix || !*pszSuffix)
  70. {
  71. pszTmp = CmStrCpyAllocW(pszStr);
  72. }
  73. else
  74. {
  75. pszTmp = CmStrCpyAllocW(pszStr);
  76. if (pszTmp)
  77. {
  78. CmStrCatAllocW(&pszTmp, pszSuffix);
  79. }
  80. }
  81. MYDBGASSERT(pszTmp);
  82. return (pszTmp);
  83. }
  84. //+----------------------------------------------------------------------------
  85. //
  86. // Function: CIniW_GPPS
  87. //
  88. // Synopsis: Wrapper for the Windows API GetPrivateProfileString. The return
  89. // value is the requested value, allocated on behalf of the caller.
  90. // Note that the function assumes a reasonable default size and then
  91. // loops and reallocates until it can fit the whole string.
  92. //
  93. // Arguments: LPCWSTR pszSection - Ini file section to retrieve data from
  94. // LPCWSTR pszEntry - key name to retrieve data from
  95. // LPCWSTR pszDefault - the default string value to return, defaults
  96. // to the empty string ("") if not specified
  97. // LPCWSTR pszFile - full path to the ini file to get the data from
  98. //
  99. // Returns: LPWSTR - the requested data from the ini file, must be freed
  100. // by the caller
  101. //
  102. // History: quintinb Created Header 01/05/2000
  103. //
  104. //+----------------------------------------------------------------------------
  105. static LPWSTR CIniW_GPPS(LPCWSTR pszSection, LPCWSTR pszEntry, LPCWSTR pszDefault, LPCWSTR pszFile)
  106. {
  107. LPWSTR pszBuffer;
  108. LPCWSTR pszLocalDefault = pszDefault ? pszDefault : L"";
  109. if ((NULL == pszFile) || (L'\0' == *pszFile))
  110. {
  111. CMASSERTMSG(FALSE, "CIniW_GPPS -- NULL or Empty file path passed.");
  112. return CmStrCpyAllocW(pszLocalDefault);
  113. }
  114. size_t nLen = __max((pszDefault ? lstrlenU(pszDefault) : 0) +4,48);
  115. while (1)
  116. {
  117. size_t nNewLen;
  118. pszBuffer = (LPWSTR) CmMalloc(nLen*sizeof(WCHAR));
  119. MYDBGASSERT(pszBuffer);
  120. if (pszBuffer)
  121. {
  122. nNewLen = GetPrivateProfileStringU(pszSection, pszEntry, pszLocalDefault,
  123. pszBuffer, nLen, pszFile);
  124. if (nNewLen+2 < nLen)
  125. {
  126. return (pszBuffer);
  127. }
  128. CmFree(pszBuffer);
  129. nLen *= 2;
  130. }
  131. else
  132. {
  133. CMASSERTMSG(FALSE, "CIniW_GPPS -- CmMalloc Failed.");
  134. return CmStrCpyAllocW(pszLocalDefault);
  135. }
  136. }
  137. }
  138. //+----------------------------------------------------------------------------
  139. //
  140. // Function: CIni_SetFile
  141. //
  142. // Synopsis: This function is very similar to CIniA_Set in that it takes
  143. // a source string and duplicates it into the string pointed to
  144. // by the destination pointer. However, the difference is that
  145. // this function assumes the pszSrc argument to be a full path to
  146. // a file and thus calls CreateFile on the pszSrc string
  147. // before duplicating the string.
  148. //
  149. // Arguments: LPWSTR* ppszDest - pointer to a string to accept the duplicated buffer
  150. // LPCWSTR pszSrc - full path to a file, text to be duplicated
  151. //
  152. // Returns: Nothing
  153. //
  154. // History: quintinb Created Header 01/05/2000
  155. //
  156. //+----------------------------------------------------------------------------
  157. void CIniW::CIni_SetFile(LPWSTR *ppszDest, LPCWSTR pszSrc)
  158. {
  159. MYDBGASSERT(ppszDest);
  160. if (ppszDest)
  161. {
  162. CmFree(*ppszDest);
  163. *ppszDest = NULL;
  164. if (pszSrc && *pszSrc) // pszSrc could be NULL
  165. {
  166. //
  167. // A full path to an existing file is expected
  168. //
  169. HANDLE hFile = CreateFileU(pszSrc, 0,
  170. FILE_SHARE_READ | FILE_SHARE_WRITE,
  171. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  172. MYDBGASSERT(hFile != INVALID_HANDLE_VALUE);
  173. if (hFile != INVALID_HANDLE_VALUE)
  174. {
  175. CloseHandle(hFile);
  176. //
  177. // Update internal file
  178. //
  179. *ppszDest = CmStrCpyAllocW(pszSrc);
  180. }
  181. }
  182. }
  183. }
  184. //+----------------------------------------------------------------------------
  185. //
  186. // Function: CIniW::CIniW
  187. //
  188. // Synopsis: CIniW constructor
  189. //
  190. // Arguments: HINSTANCE hInst - Instance handle used to load resources
  191. // LPCWSTR pszFile - Ini file the object describes
  192. // LPCWSTR pszSection - a section suffix that will be appended to
  193. // all section references
  194. // LPCWSTR pszEntry - an entry suffix that will be appended to all
  195. // entry references
  196. //
  197. // Returns: Nothing
  198. //
  199. // History: quintinb Created Header 01/05/2000
  200. //
  201. // t-urama modified 07/19/2000
  202. //+----------------------------------------------------------------------------
  203. CIniW::CIniW(HINSTANCE hInst, LPCWSTR pszFile, LPCWSTR pszRegPath, LPCWSTR pszSection, LPCWSTR pszEntry)
  204. {
  205. //
  206. // Input pointers default to NULL and in fact the constructor is rarely called
  207. // with parameters. Thus we will skip checking the input pointers and just
  208. // pass them on to the functions below, which are designed to except NULL inputs.
  209. //
  210. m_hInst = hInst;
  211. //
  212. // Make sure to NULL the string params before setting them below. This
  213. // is because we call free on the inputted params and we don't want to try
  214. // to free garbage.
  215. //
  216. m_pszFile = NULL;
  217. m_pszSection = NULL;
  218. m_pszEntry = NULL;
  219. m_pszPrimaryFile = NULL;
  220. m_pszRegPath = NULL;
  221. m_pszPrimaryRegPath = NULL;
  222. //m_fIgnoreRegOnRead = FALSE;
  223. //m_fWriteToBoth = FALSE;
  224. //m_fReadOnlyAccess = FALSE;
  225. m_pszICSDataPath = NULL;
  226. m_fReadICSData = FALSE;
  227. m_fWriteICSData = FALSE;
  228. SetFile(pszFile);
  229. SetSection(pszSection);
  230. SetEntry(pszEntry);
  231. SetRegPath(pszRegPath);
  232. }
  233. //+----------------------------------------------------------------------------
  234. //
  235. // Function: CIniW::~CIniW
  236. //
  237. // Synopsis: CIniW destructor, frees dynamically allocated strings held onto
  238. // by the CIniW object.
  239. //
  240. // Arguments: None
  241. //
  242. // Returns: Nothing
  243. //
  244. // History: quintinb Created Header 01/05/2000
  245. //
  246. //+----------------------------------------------------------------------------
  247. CIniW::~CIniW()
  248. {
  249. CmFree(m_pszFile);
  250. CmFree(m_pszSection);
  251. CmFree(m_pszEntry);
  252. CmFree(m_pszPrimaryFile);
  253. CmFree(m_pszRegPath);
  254. CmFree(m_pszPrimaryRegPath);
  255. CmFree(m_pszICSDataPath);
  256. }
  257. //+----------------------------------------------------------------------------
  258. //
  259. // Function: CIniW::Clear
  260. //
  261. // Synopsis: Clears all of the member variables of the CIniW class. Used
  262. // so that a single CIniW object can be re-used without having to
  263. // destruct the old object and construct a new one.
  264. //
  265. // Arguments: None
  266. //
  267. // Returns: Nothing
  268. //
  269. // History: quintinb Created Header 01/05/2000
  270. //
  271. // t-urama modified 07/19/2000
  272. //+----------------------------------------------------------------------------
  273. void CIniW::Clear()
  274. {
  275. SetHInst(NULL);
  276. SetFile(NULL);
  277. SetSection(NULL);
  278. SetEntry(NULL);
  279. SetPrimaryFile(NULL);
  280. SetRegPath(NULL);
  281. SetPrimaryRegPath(NULL);
  282. SetICSDataPath(NULL);
  283. }
  284. //+----------------------------------------------------------------------------
  285. //
  286. // Function: CIniW::SetSection
  287. //
  288. // Synopsis: Sets the internal section suffix using the CIniW_Set
  289. // helper function.
  290. //
  291. // Arguments: LPCWSTR pszSection - section suffix to remember
  292. //
  293. // Returns: Nothing
  294. //
  295. // History: quintinb Created Header 01/05/2000
  296. //
  297. //+----------------------------------------------------------------------------
  298. void CIniW::SetSection(LPCWSTR pszSection)
  299. {
  300. CIniW_Set(&m_pszSection, pszSection);
  301. }
  302. //+----------------------------------------------------------------------------
  303. //
  304. // Function: CIniW::SetEntry
  305. //
  306. // Synopsis: Sets the internal entry suffix using the CIniW_Set
  307. // helper function.
  308. //
  309. // Arguments: LPCWSTR pszSection - entry suffix to remember
  310. //
  311. // Returns: Nothing
  312. //
  313. // History: quintinb Created Header 01/05/2000
  314. //
  315. //+----------------------------------------------------------------------------
  316. void CIniW::SetEntry(LPCWSTR pszEntry)
  317. {
  318. CIniW_Set(&m_pszEntry, pszEntry);
  319. }
  320. //+----------------------------------------------------------------------------
  321. //
  322. // Function: CIniW::SetEntryFromIdx
  323. //
  324. // Synopsis: Sets the internal entry suffix just as SetEntry does. However,
  325. // the input parameter is a DWORD value that must be converted to
  326. // a string before it is stored as the index
  327. //
  328. // Arguments: DWORD dwEntry - index number to append to entries
  329. //
  330. // Returns: Nothing
  331. //
  332. // History: quintinb Created Header 01/05/2000
  333. //
  334. //+----------------------------------------------------------------------------
  335. void CIniW::SetEntryFromIdx(DWORD dwEntry)
  336. {
  337. WCHAR szEntry[sizeof(dwEntry)*6+1];
  338. wsprintfU(szEntry, L"%u", dwEntry);
  339. SetEntry(szEntry);
  340. }
  341. //+----------------------------------------------------------------------------
  342. //
  343. // Function: CIniW::LoadSection
  344. //
  345. // Synopsis: This function concatenates the given section parameter and the
  346. // section suffix and returns the result via the return value. Note
  347. // that the memory must be freed by the calller.
  348. //
  349. // Arguments: LPCWSTR pszSection - base section to concatenate the suffix to
  350. //
  351. // Returns: LPWSTR - a newly allocated string containing the pszSection value
  352. // with the section suffix appended
  353. //
  354. // History: quintinb Created Header 01/05/2000
  355. //
  356. //+----------------------------------------------------------------------------
  357. LPWSTR CIniW::LoadSection(LPCWSTR pszSection) const
  358. {
  359. return (CIniW_LoadCat(pszSection, m_pszSection));
  360. }
  361. //+----------------------------------------------------------------------------
  362. //
  363. // Function: CIniW::LoadEntry
  364. //
  365. // Synopsis: This function concatenates the given entry parameter and the
  366. // entry suffix and returns the result via the return value. Note
  367. // that the memory must be freed by the calller.
  368. //
  369. // Arguments: LPCWSTR pszEntry - base entry to concatenate the suffix to
  370. //
  371. // Returns: LPWSTR - a newly allocated string containing the pszEntry value
  372. // with the entry suffix appended
  373. //
  374. // History: quintinb Created Header 01/05/2000
  375. //
  376. //+----------------------------------------------------------------------------
  377. LPWSTR CIniW::LoadEntry(LPCWSTR pszEntry) const
  378. {
  379. return (CIniW_LoadCat(pszEntry ,m_pszEntry));
  380. }
  381. //+----------------------------------------------------------------------------
  382. //
  383. // Function: CIniW::GPPS
  384. //
  385. // Synopsis: CIni's version of GetPrivateProfileString. Duplicates the Win32
  386. // API functionality except that it will append the Section and Entry
  387. // suffixes (if any) before calling the Win32 API. The function all
  388. // allocates the string it returns in the return value which must be
  389. // freed by the caller.
  390. //
  391. // Arguments: LPCWSTR pszSection - Ini section to look for the data in
  392. // LPCWSTR pszEntry - Ini key name that contains the requested data
  393. // LPCWSTR pszDefault - default value to return if the key
  394. // cannot be found
  395. //
  396. // Returns: LPWSTR - the requested string value
  397. //
  398. // History: quintinb Created Header 01/05/2000
  399. // t-urama modified 07/15/2000
  400. //
  401. //+----------------------------------------------------------------------------
  402. LPWSTR CIniW::GPPS(LPCWSTR pszSection, LPCWSTR pszEntry, LPCWSTR pszDefault) const
  403. {
  404. LPWSTR pszSectionTmp = LoadSection(pszSection);
  405. LPWSTR pszEntryTmp = LoadEntry(pszEntry);
  406. LPWSTR pszBuffer = NULL;
  407. if (m_fReadICSData)
  408. {
  409. //
  410. // We need first read the data from ICSData reg key, if it's not present then try to
  411. // get it from the file and then see if we have a primary file and read it from there.
  412. //
  413. pszBuffer = (LPWSTR)CIniW_GetEntryFromReg(HKEY_LOCAL_MACHINE, m_pszICSDataPath, pszEntryTmp, REG_SZ, ((MAX_PATH + 1) * sizeof(TCHAR)));
  414. if (NULL == pszBuffer)
  415. {
  416. LPWSTR pszICSTmp = NULL;
  417. pszBuffer = CIniW_GPPS(pszSectionTmp, pszEntryTmp, pszDefault, GetFile());
  418. if (m_pszPrimaryFile)
  419. {
  420. pszICSTmp = pszBuffer;
  421. pszBuffer = CIniW_GPPS(pszSectionTmp, pszEntryTmp, pszICSTmp, GetPrimaryFile());
  422. }
  423. if (NULL == pszBuffer)
  424. {
  425. if (pszDefault)
  426. {
  427. pszBuffer = CmStrCpyAllocW(pszDefault);
  428. }
  429. else
  430. {
  431. //
  432. // We should not return a null from this wrapper, but an empty string instead
  433. //
  434. pszBuffer = CmStrCpyAllocW(L"");
  435. }
  436. }
  437. CmFree(pszICSTmp);
  438. }
  439. }
  440. else
  441. {
  442. //
  443. // If there is a reg path present. Registry access for m_pszFile
  444. // unless we want to read it from the file
  445. //
  446. if (m_pszRegPath)
  447. {
  448. MYDBGASSERT(pszEntryTmp && *pszEntryTmp);
  449. if (pszEntryTmp && *pszEntryTmp)
  450. {
  451. pszBuffer = (LPWSTR) CIniW_GetEntryFromReg(HKEY_CURRENT_USER, m_pszRegPath, pszEntryTmp, REG_SZ, ((MAX_PATH + 1) * sizeof(TCHAR)));
  452. }
  453. }
  454. if (NULL == pszBuffer)
  455. {
  456. // This could mean that there is no reg path, or that the reg access failed. Either way, we
  457. // try to get the entry from pszFile
  458. //
  459. // Skip input pointer check since pszSection could be NULL to get all of
  460. // the Section Names in the file, pszEntry could be NULL to get all of the
  461. // key names in a section, and pszDefault is NULL by default.
  462. // GetPrivateProfileString cannot take a NULL default but this is taken care of
  463. // by CIniW_GPPS.
  464. //
  465. pszBuffer = CIniW_GPPS(pszSectionTmp, pszEntryTmp, pszDefault, GetFile());
  466. }
  467. MYDBGASSERT(pszBuffer);
  468. // Now we try to get the entry from the primary file
  469. //
  470. LPWSTR pszTmp = NULL;
  471. if (m_pszPrimaryRegPath)
  472. {
  473. MYDBGASSERT(pszEntryTmp && *pszEntryTmp);
  474. if (pszEntryTmp && *pszEntryTmp)
  475. {
  476. pszTmp = pszBuffer;
  477. pszBuffer = (LPWSTR) CIniW_GetEntryFromReg(HKEY_CURRENT_USER, m_pszPrimaryRegPath, pszEntryTmp, REG_SZ, ((MAX_PATH + 1) * sizeof(TCHAR)));
  478. }
  479. }
  480. if (NULL == pszBuffer)
  481. {
  482. // Skip input pointer check since pszSection could be NULL to get all of
  483. // the Section Names in the file, pszEntry could be NULL to get all of the
  484. // key names in a section, and pszDefault is NULL by default.
  485. // GetPrivateProfileString cannot take a NULL default but this is taken care of
  486. // by CIniW_GPPS.
  487. //
  488. pszBuffer = CIniW_GPPS(pszSectionTmp, pszEntryTmp, pszTmp, GetPrimaryFile());
  489. }
  490. CmFree(pszTmp);
  491. }
  492. CmFree(pszEntryTmp);
  493. CmFree(pszSectionTmp);
  494. MYDBGASSERT(pszBuffer);
  495. return (pszBuffer);
  496. }
  497. //+----------------------------------------------------------------------------
  498. //
  499. // Function: CIniW::GPPI
  500. //
  501. // Synopsis: CIni's version of GetPrivateProfileInt. Duplicates the Win32
  502. // API functionality except that it will append the Section and Entry
  503. // suffixes (if any) before calling the Win32 API. The function all
  504. // allocates the string it returns in the return value which must be
  505. // freed by the caller.
  506. //
  507. // Arguments: LPCWSTR pszSection - Ini section to look for the data in
  508. // LPCWSTR pszEntry - Ini key name that contains the requested data
  509. // DWORD dwDefault - default value to return if the key
  510. // cannot be found
  511. //
  512. // Returns: DWORD - the requested numerical value
  513. //
  514. // History: quintinb Created Header 01/05/2000
  515. //
  516. // t-urama modified 07/19/2000
  517. //+----------------------------------------------------------------------------
  518. DWORD CIniW::GPPI(LPCWSTR pszSection, LPCWSTR pszEntry, DWORD dwDefault) const
  519. {
  520. //
  521. // GetPrivateProfileInt doesn't take NULL's for the section and entry
  522. // parameters as GetPrivateProfileString will. Thus check the values returned
  523. // from LoadSection and LoadEntry, which will return NULL if the input parameter
  524. // is either NULL or empty. Since we don't really know what to do in this
  525. // situation lets just assert and return the default value.
  526. //
  527. DWORD dwRet = dwDefault;
  528. LPWSTR pszSectionTmp = LoadSection(pszSection);
  529. LPWSTR pszEntryTmp = LoadEntry(pszEntry);
  530. LPCWSTR pszFileTmp = GetFile();
  531. DWORD* pdwData = NULL;
  532. if (m_fReadICSData)
  533. {
  534. //
  535. // We need first read the data from ICSData reg key, if it's not present then try to
  536. // get it from the file and then see if we have a primary file and read it from there.
  537. //
  538. pdwData = (DWORD*)CIniW_GetEntryFromReg(HKEY_LOCAL_MACHINE, m_pszICSDataPath, pszEntryTmp, REG_DWORD, sizeof(DWORD));
  539. //
  540. // If we got something, assign it to the return value, otherwise try reading from the files
  541. // and using the default.
  542. //
  543. if (NULL == pdwData)
  544. {
  545. //
  546. // The registry access failed, or there is no reg. path. try to get the
  547. // entry from pszFile
  548. //
  549. MYDBGASSERT(pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp);
  550. if (pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp)
  551. {
  552. dwRet = GetPrivateProfileIntU(pszSectionTmp, pszEntryTmp, dwDefault, pszFileTmp);
  553. }
  554. if (m_pszPrimaryFile)
  555. {
  556. //
  557. // The registry access failed, or there is no reg. path. try to get the
  558. // entry from pszPrimaryFile
  559. //
  560. pszFileTmp = GetPrimaryFile();
  561. if (pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp)
  562. {
  563. dwRet = GetPrivateProfileIntU(pszSectionTmp, pszEntryTmp, dwRet, pszFileTmp);
  564. }
  565. }
  566. }
  567. else
  568. {
  569. dwRet = *pdwData;
  570. }
  571. }
  572. else
  573. {
  574. //
  575. // Follow the normal rules
  576. //
  577. if (m_pszRegPath)
  578. {
  579. MYDBGASSERT(pszEntryTmp && *pszEntryTmp);
  580. if (pszEntryTmp && *pszEntryTmp)
  581. {
  582. pdwData = (DWORD*)CIniW_GetEntryFromReg(HKEY_CURRENT_USER, m_pszRegPath, pszEntryTmp, REG_DWORD, sizeof(DWORD));
  583. }
  584. }
  585. if (NULL == pdwData)
  586. {
  587. //
  588. // The registry access failed, or there is no reg. path. try to get the
  589. // entry from pszFile
  590. //
  591. MYDBGASSERT(pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp);
  592. if (pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp)
  593. {
  594. dwRet = GetPrivateProfileIntU(pszSectionTmp, pszEntryTmp, dwDefault, pszFileTmp);
  595. }
  596. }
  597. else
  598. {
  599. dwRet = *pdwData;
  600. }
  601. if (m_pszPrimaryRegPath)
  602. {
  603. MYDBGASSERT(pszEntryTmp && *pszEntryTmp);
  604. if (pszEntryTmp && *pszEntryTmp)
  605. {
  606. CmFree(pdwData);
  607. pdwData = (DWORD*)CIniW_GetEntryFromReg(HKEY_CURRENT_USER, m_pszPrimaryRegPath, pszEntryTmp, REG_DWORD, sizeof(DWORD));
  608. if (pdwData)
  609. {
  610. dwRet = *pdwData;
  611. }
  612. }
  613. }
  614. if (NULL == pdwData && m_pszPrimaryFile)
  615. {
  616. //
  617. // The registry access failed, or there is no reg. path. try to get the
  618. // entry from pszPrimaryFile
  619. //
  620. pszFileTmp = GetPrimaryFile();
  621. if (pszSectionTmp && pszEntryTmp && pszFileTmp && *pszFileTmp)
  622. {
  623. dwRet = GetPrivateProfileIntU(pszSectionTmp, pszEntryTmp, dwRet, pszFileTmp);
  624. }
  625. }
  626. }
  627. CmFree(pdwData);
  628. CmFree(pszEntryTmp);
  629. CmFree(pszSectionTmp);
  630. return dwRet;
  631. }
  632. //+----------------------------------------------------------------------------
  633. //
  634. // Function: CIniW::GPPB
  635. //
  636. // Synopsis: CIni's version of GetPrivateProfileBool (which doesn't exactly
  637. // exist). Basically this function is the same as GPPI except that
  638. // the return value is cast to a BOOL value (1 or 0).
  639. //
  640. // Arguments: LPCWSTR pszSection - Ini section to look for the data in
  641. // LPCWSTR pszEntry - Ini key name that contains the requested data
  642. // DWORD dwDefault - default value to return if the key
  643. // cannot be found
  644. //
  645. // Returns: DWORD - the requested BOOL value
  646. //
  647. // History: quintinb Created Header 01/05/2000
  648. //
  649. //+----------------------------------------------------------------------------
  650. BOOL CIniW::GPPB(LPCWSTR pszSection, LPCWSTR pszEntry, BOOL bDefault) const
  651. {
  652. return (GPPI(pszSection, pszEntry, (DWORD)bDefault) != 0);
  653. }
  654. //+----------------------------------------------------------------------------
  655. //
  656. // Function: CIniW::WPPI
  657. //
  658. // Synopsis: CIni's version of WritePrivateProfileInt (which doesn't exist as
  659. // a Win32 function). Basically takes the inputted DWORD and prints
  660. // it into a string and then calls WPPS.
  661. //
  662. // Arguments: LPCWSTR pszSection - Ini section to write the data to
  663. // LPCWSTR pszEntry - Ini key name to store the data at
  664. // DWORD dwBuffer - Numeric value to write
  665. //
  666. // Returns: Nothing
  667. //
  668. // History: quintinb Created Header 01/05/2000
  669. //
  670. // t-urama modified 07/19/2000
  671. //
  672. //+----------------------------------------------------------------------------
  673. void CIniW::WPPI(LPCWSTR pszSection, LPCWSTR pszEntry, DWORD dwBuffer)
  674. {
  675. // Technically pszEntry could be NULL, which would erase all of the keys in
  676. // the section pointed to by pszSection. However, this doesn't seem to be
  677. // in the spirit of this wrapper so we will check both string pointers to make
  678. // sure they are valid.
  679. BOOL bRes = FALSE;
  680. //
  681. // Check is we are allowed to save info
  682. //
  683. if ((NULL != pszSection) && (L'\0' != pszSection[0]) &&
  684. (NULL != pszEntry) && (L'\0' != pszEntry[0]))
  685. {
  686. LPWSTR pszEntryTmp = LoadEntry(pszEntry);
  687. MYDBGASSERT(pszEntryTmp || (NULL == pszEntry) || (L'\0' == pszEntry[0]));
  688. if (m_pszRegPath)
  689. {
  690. if (NULL != pszEntryTmp && *pszEntryTmp)
  691. {
  692. bRes = CIniW_WriteEntryToReg(HKEY_CURRENT_USER, m_pszRegPath, pszEntryTmp, (BYTE *) &dwBuffer, REG_DWORD, sizeof(DWORD));
  693. }
  694. }
  695. if (!bRes)
  696. {
  697. // This loop is only entered if we are trying to write to the cmp and the registry
  698. // write failed, or we are writing to the cms, in which case we will not even
  699. // try to write to the reg.
  700. LPWSTR pszSectionTmp = LoadSection(pszSection);
  701. LPCWSTR pszFileTmp = GetFile();
  702. MYDBGASSERT(pszFileTmp && *pszFileTmp);
  703. MYDBGASSERT(pszSectionTmp && *pszSectionTmp);
  704. WCHAR szBuffer[sizeof(dwBuffer)*6+1];
  705. wsprintfU(szBuffer, L"%u", dwBuffer);
  706. if (pszFileTmp && *pszFileTmp && pszSectionTmp && *pszSectionTmp && pszEntryTmp && *pszEntryTmp)
  707. {
  708. bRes = WritePrivateProfileStringU(pszSectionTmp, pszEntryTmp, szBuffer, pszFileTmp);
  709. }
  710. if (!bRes)
  711. {
  712. DWORD dwError = GetLastError();
  713. CMTRACE3W(L"CIniW::WPPI() WritePrivateProfileString[*pszSection=%s,*pszEntry=%s,*pszBuffer=%s", pszSectionTmp, MYDBGSTRW(pszEntryTmp), MYDBGSTRW(szBuffer));
  714. CMTRACE2W(L"*pszFile=%s] failed, GLE=%u", pszFileTmp, dwError);
  715. }
  716. CmFree(pszSectionTmp);
  717. }
  718. if (m_fWriteICSData)
  719. {
  720. if (NULL != pszEntryTmp && *pszEntryTmp)
  721. {
  722. bRes = CIniW_WriteEntryToReg(HKEY_LOCAL_MACHINE, m_pszICSDataPath, pszEntryTmp, (BYTE *) &dwBuffer, REG_DWORD, sizeof(DWORD));
  723. }
  724. }
  725. CmFree(pszEntryTmp);
  726. }
  727. else
  728. {
  729. CMASSERTMSG(FALSE, "Invalid input paramaters to CIniW::WPPI");
  730. }
  731. }
  732. //+----------------------------------------------------------------------------
  733. //
  734. // Function: CIniA::WPPB
  735. //
  736. // Synopsis: CIni's version of WritePrivateProfileBool (which doesn't exist as
  737. // a Win32 function). Basically takes the inputted BOOL and prints
  738. // either 1 or 0 into a string and then calls WPPI.
  739. //
  740. // Arguments: LPCWSTR pszSection - Ini section to write the data to
  741. // LPCWSTR pszEntry - Ini key name to store the data at
  742. // DWORD dwBuffer - Numeric value to write
  743. //
  744. // Returns: Nothing
  745. //
  746. // History: quintinb Created Header 01/05/2000
  747. //
  748. //+----------------------------------------------------------------------------
  749. void CIniW::WPPB(LPCWSTR pszSection, LPCWSTR pszEntry, BOOL bBuffer)
  750. {
  751. WPPI(pszSection, pszEntry, bBuffer ? 1 : 0);
  752. }
  753. //+----------------------------------------------------------------------------
  754. //
  755. // Function: CIniW::WPPS
  756. //
  757. // Synopsis: CIni's version of WritePrivateProfileString
  758. //
  759. // Arguments: LPCWSTR pszSection - Ini section to write the data to
  760. // LPCWSTR pszEntry - Ini key name to store the data at
  761. // LPCWSTR pszBuffer - data buffer to write to the ini file
  762. //
  763. // Returns: Nothing
  764. //
  765. // History: quintinb Created Header 01/05/2000
  766. //
  767. // t-urama modified 07/19/2000
  768. //
  769. //+----------------------------------------------------------------------------
  770. void CIniW::WPPS(LPCWSTR pszSection, LPCWSTR pszEntry, LPCWSTR pszBuffer)
  771. {
  772. LPWSTR pszEntryTmp = LoadEntry(pszEntry);
  773. LPWSTR pszSectionTmp = LoadSection(pszSection);
  774. LPCWSTR pszFileTmp = GetFile();
  775. MYDBGASSERT(pszFileTmp && *pszFileTmp);
  776. MYDBGASSERT(pszSectionTmp && *pszSectionTmp);
  777. // Both pszEntry and pszBuffer could be NULL or Empty. However, pszSection and
  778. // the file path must not be NULL or empty. We also don't want to have a non-NULL
  779. // or non-Empty value for pszEntry and then get a NULL value back from LoadEntry
  780. // (indicating that LoadEntry had text to duplicate but failed for some reason).
  781. // Writing with a NULL value accidently will delete the key value we were trying to set.
  782. // Make sure to assert and prevent data loss in this case.
  783. //
  784. MYDBGASSERT(pszEntryTmp || (NULL == pszEntry) || (L'\0' == pszEntry[0]));
  785. //
  786. // Check is we are allowed to save info
  787. //
  788. if(pszEntryTmp || (NULL == pszEntry) || (L'\0' == pszEntry[0]))
  789. {
  790. BOOL bRes = FALSE;
  791. // First try to write to registry if pszRegPath exists
  792. if (m_pszRegPath)
  793. {
  794. if (NULL == pszBuffer)
  795. {
  796. CIniW_DeleteEntryFromReg(HKEY_CURRENT_USER, m_pszRegPath, pszEntryTmp);
  797. bRes = TRUE; // never erase from the cmp or cms file if there is a regpath.
  798. }
  799. else
  800. {
  801. DWORD dwSize = (lstrlenU(pszBuffer) + 1) * sizeof(WCHAR);
  802. bRes = CIniW_WriteEntryToReg(HKEY_CURRENT_USER, m_pszRegPath, pszEntryTmp, (BYTE *) pszBuffer, REG_SZ, dwSize);
  803. }
  804. }
  805. if (!bRes)
  806. {
  807. // This loop is only entered if we are trying to write to the cmp and the registry
  808. // write failed, or we are writing to the cms, in which case we will not even
  809. // try to write to the reg.
  810. if (pszFileTmp && *pszFileTmp && pszSectionTmp && *pszSectionTmp )
  811. {
  812. bRes = WritePrivateProfileStringU(pszSectionTmp, pszEntryTmp, pszBuffer, pszFileTmp);
  813. }
  814. }
  815. if (!bRes)
  816. {
  817. DWORD dwError = GetLastError();
  818. CMTRACE3W(L"CIniW::WPPS() WritePrivateProfileString[*pszSection=%s,*pszEntry=%s,*pszBuffer=%s", pszSectionTmp, MYDBGSTRW(pszEntryTmp), MYDBGSTRW(pszBuffer));
  819. CMTRACE2W(L"*pszFile=%s] failed, GLE=%u", pszFileTmp, dwError);
  820. }
  821. if (m_fWriteICSData)
  822. {
  823. if (NULL == pszBuffer)
  824. {
  825. CIniW_DeleteEntryFromReg(HKEY_LOCAL_MACHINE, m_pszICSDataPath, pszEntryTmp);
  826. bRes = TRUE; // never erase from the cmp or cms file if there is a regpath.
  827. }
  828. else
  829. {
  830. DWORD dwSize = (lstrlenU(pszBuffer) + 1) * sizeof(WCHAR);
  831. bRes = CIniW_WriteEntryToReg(HKEY_LOCAL_MACHINE, m_pszICSDataPath, pszEntryTmp, (BYTE *) pszBuffer, REG_SZ, dwSize);
  832. }
  833. }
  834. }
  835. CmFree(pszEntryTmp);
  836. CmFree(pszSectionTmp);
  837. }
  838. //+----------------------------------------------------------------------------
  839. //
  840. // Function: CIniW::GetSection
  841. //
  842. // Synopsis: Accessor function for the Section suffix member variable. Will
  843. // return the empty string if m_pszSection is NULL.
  844. //
  845. // Arguments: None
  846. //
  847. // Returns: LPCWSTR - Value of the section suffix member variable or ""
  848. // if it is NULL
  849. //
  850. // History: quintinb Created Header 01/05/2000
  851. //
  852. //+----------------------------------------------------------------------------
  853. LPCWSTR CIniW::GetSection() const
  854. {
  855. return (m_pszSection ? m_pszSection : L"");
  856. }
  857. //+----------------------------------------------------------------------------
  858. //
  859. // Function: CIniW::GetPrimaryFile
  860. //
  861. // Synopsis: Accessor function for the Primary File member variable. Will
  862. // return the empty string if m_pszPrimaryFile is NULL.
  863. //
  864. // Arguments: None
  865. //
  866. // Returns: LPCWSTR - Value of the primary file member variable or ""
  867. // if it is NULL
  868. //
  869. // History: quintinb Created Header 01/05/2000
  870. //
  871. //+----------------------------------------------------------------------------
  872. LPCWSTR CIniW::GetPrimaryFile() const
  873. {
  874. return (m_pszPrimaryFile ? m_pszPrimaryFile : L"");
  875. }
  876. //+----------------------------------------------------------------------------
  877. //
  878. // Function: CIniW::GetHInst
  879. //
  880. // Synopsis: Accessor function for the m_hInst member variable.
  881. //
  882. // Arguments: None
  883. //
  884. // Returns: HINSTANCE - Value of the m_hInst
  885. //
  886. // History: quintinb Created Header 01/05/2000
  887. //
  888. //+----------------------------------------------------------------------------
  889. HINSTANCE CIniW::GetHInst() const
  890. {
  891. return (m_hInst);
  892. }
  893. //+----------------------------------------------------------------------------
  894. //
  895. // Function: CIniW::SetFile
  896. //
  897. // Synopsis: Function to set the m_pszFile member variable. Uses CIni_SetFile.
  898. // Note that if the input parameter is NULL or the empty string then
  899. // m_pszFile will be set to NULL.
  900. //
  901. // Arguments: LPCWSTR pszFile - full path to set the m_pszFile member var to
  902. //
  903. // Returns: Nothing
  904. //
  905. // History: quintinb Created Header 01/05/2000
  906. //
  907. //+----------------------------------------------------------------------------
  908. void CIniW::SetFile(LPCWSTR pszFile)
  909. {
  910. CIni_SetFile(&m_pszFile, pszFile);
  911. }
  912. //+----------------------------------------------------------------------------
  913. //
  914. // Function: CIniW::SetPrimaryFile
  915. //
  916. // Synopsis: Function to set the m_pszPrimaryFile member variable. Uses CIni_SetFile.
  917. // Note that if the input parameter is NULL or the empty string then
  918. // m_pszPrimaryFile will be set to NULL.
  919. //
  920. // Arguments: LPCWSTR pszFile - full path to set the m_pszPrimaryFile member var to
  921. //
  922. // Returns: Nothing
  923. //
  924. // History: quintinb Created Header 01/05/2000
  925. //
  926. //+----------------------------------------------------------------------------
  927. void CIniW::SetPrimaryFile(LPCWSTR pszFile)
  928. {
  929. CIni_SetFile(&m_pszPrimaryFile, pszFile);
  930. }
  931. //+----------------------------------------------------------------------------
  932. //
  933. // Function: CIniW::GetFile
  934. //
  935. // Synopsis: Accessor function for the File member variable. Will
  936. // return the empty string if m_pszFile is NULL.
  937. //
  938. // Arguments: None
  939. //
  940. // Returns: LPCWSTR - the contents of m_pszFile or "" if it is NULL
  941. //
  942. // History: quintinb Created Header 01/05/2000
  943. //
  944. //+----------------------------------------------------------------------------
  945. LPCWSTR CIniW::GetFile() const
  946. {
  947. return (m_pszFile ? m_pszFile : L"");
  948. }
  949. //+----------------------------------------------------------------------------
  950. //
  951. // Function: CIniW::SetHInst
  952. //
  953. // Synopsis: Function to set the m_hInst member variable.
  954. //
  955. // Arguments: HINSTANCE hInst - instance handle to set m_hInst to
  956. //
  957. // Returns: Nothing
  958. //
  959. // History: quintinb Created Header 01/05/2000
  960. //
  961. //+----------------------------------------------------------------------------
  962. void CIniW::SetHInst(HINSTANCE hInst)
  963. {
  964. m_hInst = hInst;
  965. }
  966. //
  967. // Loading sections by string resource isn't used anymore
  968. //
  969. #if 0
  970. LPWSTR CIniW::LoadSection(UINT nSection) const
  971. {
  972. LPWSTR pszTmp;
  973. pszTmp = CmLoadStringW(GetHInst(), nSection);
  974. CmStrCatAllocW(&pszTmp, GetSection());
  975. return (pszTmp);
  976. }
  977. #endif
  978. //+----------------------------------------------------------------------------
  979. //
  980. // Function: CIniW::SetRegPath
  981. //
  982. // Synopsis: Sets the registry path for registry access
  983. //
  984. // Arguments: LPCSTR pszRegPath - entry suffix to remember
  985. //
  986. // Returns: Nothing
  987. //
  988. // History: t-urama Created Header 07/13/2000
  989. //
  990. //+----------------------------------------------------------------------------
  991. void CIniW::SetRegPath(LPCWSTR pszRegPath)
  992. {
  993. CIniW_Set(&m_pszRegPath, pszRegPath);
  994. }
  995. //+----------------------------------------------------------------------------
  996. //
  997. // Function: CIniW::SetPrimaryRegPath
  998. //
  999. // Synopsis: Sets the registry path for primary file registry access
  1000. //
  1001. // Arguments: LPCSTR pszPrimaryRegPath - Primary reg path
  1002. //
  1003. // Returns: Nothing
  1004. //
  1005. // History: t-urama Created Header 07/13/2000
  1006. //
  1007. //+----------------------------------------------------------------------------
  1008. void CIniW::SetPrimaryRegPath(LPCWSTR pszPrimaryRegPath)
  1009. {
  1010. CIniW_Set(&m_pszPrimaryRegPath, pszPrimaryRegPath);
  1011. }
  1012. //+----------------------------------------------------------------------------
  1013. //
  1014. // Function: CIniW::SetICSDataPath
  1015. //
  1016. // Synopsis: Sets the internal registry key to store data for ICS.
  1017. // Need to make sure the string isn't empty since we don't want
  1018. // to write in HKLM
  1019. //
  1020. // Arguments: None
  1021. //
  1022. // Returns: Nothing
  1023. //
  1024. // History: 03/30/2001 tomkel Created
  1025. //
  1026. //+----------------------------------------------------------------------------
  1027. void CIniW::SetICSDataPath(LPCWSTR pszICSPath)
  1028. {
  1029. CIniW_Set(&m_pszICSDataPath, pszICSPath);
  1030. }
  1031. //+----------------------------------------------------------------------------
  1032. //
  1033. // Function: CIniW::SetReadICSData
  1034. //
  1035. // Synopsis: Sets the read flag, to read data from the ICS registry key.
  1036. //
  1037. // Arguments: fValue
  1038. //
  1039. // Returns: Nothing
  1040. //
  1041. // History: 03/30/2001 tomkel Created
  1042. //
  1043. //+----------------------------------------------------------------------------
  1044. void CIniW::SetReadICSData(BOOL fValue)
  1045. {
  1046. m_fReadICSData = fValue;
  1047. }
  1048. //+----------------------------------------------------------------------------
  1049. //
  1050. // Function: CIniW::SetWriteICSData
  1051. //
  1052. // Synopsis: Sets the write flag, to write data to the ICS registry key.
  1053. //
  1054. // Arguments: None
  1055. //
  1056. // Returns: Nothing
  1057. //
  1058. // History: 03/30/2001 tomkel Created
  1059. //
  1060. //+----------------------------------------------------------------------------
  1061. void CIniW::SetWriteICSData(BOOL fValue)
  1062. {
  1063. m_fWriteICSData = fValue;
  1064. }
  1065. //+----------------------------------------------------------------------------
  1066. //
  1067. // Function: CIniW::CiniW_WriteEntryToReg
  1068. //
  1069. // Synopsis: Function to write and entry to the registry.
  1070. //
  1071. // Arguments: HKEY hKey
  1072. // LPCWSTR pszRegPathTmp - reg key name
  1073. // LPCWSTR pszEntry - Registry value name to which data is to be written
  1074. // CONST BYTE *lpData - Data to be written
  1075. // DWORD dwType - The type of value to be entered
  1076. // DWORD dwSize - The size of the value entered
  1077. //
  1078. // Returns: BOOL - Success or failure
  1079. //
  1080. // History: t-urama Created Header 07/15/2000
  1081. //
  1082. //+----------------------------------------------------------------------------
  1083. BOOL CIniW::CIniW_WriteEntryToReg(HKEY hKey, LPCWSTR pszRegPathTmp, LPCWSTR pszEntry, CONST BYTE *lpData, DWORD dwType, DWORD dwSize) const
  1084. {
  1085. MYDBGASSERT(pszEntry && *pszEntry);
  1086. MYDBGASSERT(lpData);
  1087. MYDBGASSERT(pszRegPathTmp && *pszRegPathTmp);
  1088. if (NULL == pszEntry || !*pszEntry || NULL == lpData || NULL == pszRegPathTmp || !*pszRegPathTmp || NULL == hKey)
  1089. {
  1090. return FALSE;
  1091. }
  1092. HKEY hKeyCm;
  1093. DWORD dwDisposition;
  1094. DWORD dwRes = RegCreateKeyExU(hKey,
  1095. pszRegPathTmp,
  1096. 0,
  1097. NULL,
  1098. REG_OPTION_NON_VOLATILE,
  1099. KEY_ALL_ACCESS,
  1100. NULL,
  1101. &hKeyCm,
  1102. &dwDisposition);
  1103. //
  1104. // If we opened the key successfully, write the value
  1105. //
  1106. if (ERROR_SUCCESS == dwRes)
  1107. {
  1108. dwRes = RegSetValueExU(hKeyCm,
  1109. pszEntry,
  1110. 0,
  1111. dwType,
  1112. lpData,
  1113. dwSize);
  1114. RegCloseKey(hKeyCm);
  1115. }
  1116. #ifdef DEBUG
  1117. if (ERROR_SUCCESS != dwRes)
  1118. {
  1119. CMTRACE1(TEXT("CIniW_WriteEntryToReg() - %s failed"), (LPWSTR)pszEntry);
  1120. }
  1121. #endif
  1122. return (ERROR_SUCCESS == dwRes);
  1123. }
  1124. //+----------------------------------------------------------------------------
  1125. //
  1126. // Function: CIniW::CiniW_GetEntryFromReg
  1127. //
  1128. // Synopsis: Function to get the value from the registry. The function
  1129. // allocates the string it returns in the return value which must be
  1130. // freed by the caller.
  1131. //
  1132. // Arguments: HKEY hKey - reg hkey
  1133. // LPCWSTR pszRegPathTmp - reg key
  1134. // LPCWSTR pszEntry - Registry value name that contains the requested data
  1135. // DORD dwType - Type of value
  1136. // DWORD dwSize - Size of value
  1137. //
  1138. // Returns: LPBYTE - the requested value
  1139. //
  1140. // History: 07/15/2000 t-urama Created Header
  1141. // 04/03/2001 tomkel Added hkey and reg key path name to parameters
  1142. //
  1143. //+----------------------------------------------------------------------------
  1144. LPBYTE CIniW::CIniW_GetEntryFromReg(HKEY hKey, LPCWSTR pszRegPathTmp, LPCWSTR pszEntry, DWORD dwType, DWORD dwSize) const
  1145. {
  1146. MYDBGASSERT(pszEntry);
  1147. if (NULL == pszEntry || !*pszEntry || NULL == pszRegPathTmp || !*pszRegPathTmp || NULL == hKey)
  1148. {
  1149. return NULL;
  1150. }
  1151. //
  1152. // Everything is ok. We have a reg path and a entry name.
  1153. //
  1154. LPBYTE lpData = NULL;
  1155. DWORD dwTypeTmp = dwType;
  1156. DWORD dwSizeTmp = dwSize;
  1157. HKEY hKeyCm;
  1158. //
  1159. // Open the sub key under hKey
  1160. //
  1161. DWORD dwRes = RegOpenKeyExU(hKey,
  1162. pszRegPathTmp,
  1163. 0,
  1164. KEY_QUERY_VALUE,
  1165. &hKeyCm);
  1166. //
  1167. // If we opened the key successfully, retrieve the value
  1168. //
  1169. if (ERROR_SUCCESS == dwRes)
  1170. {
  1171. do
  1172. {
  1173. //
  1174. // Allocate a buffer
  1175. //
  1176. CmFree(lpData);
  1177. lpData = (BYTE *) CmMalloc(dwSizeTmp);
  1178. if (NULL == lpData)
  1179. {
  1180. RegCloseKey(hKeyCm);
  1181. return FALSE;
  1182. }
  1183. dwRes = RegQueryValueExU(hKeyCm,
  1184. pszEntry,
  1185. NULL,
  1186. &dwTypeTmp,
  1187. lpData,
  1188. &dwSizeTmp);
  1189. } while (ERROR_MORE_DATA == dwRes);
  1190. RegCloseKey(hKeyCm);
  1191. }
  1192. if (ERROR_SUCCESS == dwRes && dwTypeTmp == dwType)
  1193. {
  1194. return lpData;
  1195. }
  1196. else
  1197. {
  1198. CmFree(lpData);
  1199. return NULL;
  1200. }
  1201. }
  1202. //+----------------------------------------------------------------------------
  1203. //
  1204. // Function: CIniW::CiniW_GetRegPath
  1205. //
  1206. // Synopsis: Function to get the value ofm_pszRegPath
  1207. //
  1208. // Arguments: none
  1209. //
  1210. // Returns: LPWCSTR - Value of m_pszRegPath
  1211. //
  1212. // History: t-urama Created Header 07/15/2000
  1213. //
  1214. //+----------------------------------------------------------------------------
  1215. LPCWSTR CIniW::GetRegPath() const
  1216. {
  1217. return (m_pszRegPath ? m_pszRegPath : L"");
  1218. }
  1219. //+----------------------------------------------------------------------------
  1220. //
  1221. // Function: CIniW::CiniW_GetPrimaryRegPath
  1222. //
  1223. // Synopsis: Function to get the value ofm_pszPrimaryRegPath
  1224. //
  1225. // Arguments: none
  1226. //
  1227. // Returns: LPWCSTR - Value of m_pszPrimaryRegPath
  1228. //
  1229. // History: t-urama Created 07/15/2000
  1230. //
  1231. //+----------------------------------------------------------------------------
  1232. LPCWSTR CIniW::GetPrimaryRegPath() const
  1233. {
  1234. return (m_pszPrimaryRegPath ? m_pszPrimaryRegPath : L"");
  1235. }
  1236. //+----------------------------------------------------------------------------
  1237. //
  1238. // Function: CIniW::CiniW_DeleteEntryFromReg
  1239. //
  1240. // Synopsis: Function to delete an entry from the registry.
  1241. //
  1242. // Arguments: HKEY hKey
  1243. // LPCWSTR pszRegPathTmp - reg key name
  1244. // LPCWSTR pszEntry - Registry value name to be deleted
  1245. //
  1246. // Returns: BOOL - Success or failure
  1247. //
  1248. // History: 07/15/2000 t-urama Created
  1249. // 04/03/2001 tomkel Added Hkey and reg key name to parameters
  1250. //
  1251. //+----------------------------------------------------------------------------
  1252. BOOL CIniW::CIniW_DeleteEntryFromReg(HKEY hKey, LPCWSTR pszRegPathTmp, LPCWSTR pszEntry) const
  1253. {
  1254. MYDBGASSERT(pszEntry);
  1255. if (NULL == pszEntry || !*pszEntry || NULL == pszRegPathTmp || !*pszRegPathTmp || NULL == hKey)
  1256. {
  1257. return FALSE;
  1258. }
  1259. //
  1260. // Everything is ok. We have a reg path and a entry name.
  1261. //
  1262. HKEY hKeyCm;
  1263. BOOL dwRes = RegOpenKeyExU(hKey,
  1264. pszRegPathTmp,
  1265. 0,
  1266. KEY_SET_VALUE,
  1267. &hKeyCm);
  1268. //
  1269. // If we opened the key successfully, retrieve the value
  1270. //
  1271. if (ERROR_SUCCESS == dwRes)
  1272. {
  1273. dwRes = RegDeleteValueU(hKeyCm, pszEntry);
  1274. RegCloseKey(hKeyCm);
  1275. }
  1276. return (ERROR_SUCCESS == dwRes);
  1277. }