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.

82 lines
2.0 KiB

  1. //
  2. // MODULE: OcxGlobals.cpp
  3. //
  4. // PURPOSE: Global functions that are handy to have.
  5. //
  6. // PROJECT: Local Troubleshooter Launcher for the Device Manager
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-633-4743 [email protected]
  9. //
  10. // AUTHOR: Richard Meadows
  11. //
  12. // ORIGINAL DATE: 2-26-98
  13. //
  14. //
  15. // Version Date By Comments
  16. //--------------------------------------------------------------------
  17. // V0.1 - RM Original
  18. // V0.3 04/09/98 JM/OK+ Local Version for NT5
  19. ///////////////////////
  20. #include "stdafx.h"
  21. #include "..\launcher\server\ComGlobals.h"
  22. bool BSTRToTCHAR(LPTSTR szChar, BSTR bstr, int CharBufSize)
  23. {
  24. int x = 0;
  25. while(x < CharBufSize)
  26. {
  27. szChar[x] = (TCHAR) bstr[x];
  28. if (NULL == szChar[x])
  29. break;
  30. x++;
  31. }
  32. return x < CharBufSize;
  33. }
  34. bool ReadRegSZ(HKEY hRootKey, LPCTSTR szKey, LPCTSTR szValue, LPTSTR szBuffer, DWORD *pdwBufSize)
  35. {
  36. HKEY hKey;
  37. DWORD dwType = REG_SZ;
  38. DWORD dwBufSize = *pdwBufSize;
  39. LPTSTR szUnExpanded = new TCHAR[dwBufSize];
  40. if (NULL == szUnExpanded)
  41. return false;
  42. __try
  43. {
  44. if(ERROR_SUCCESS != RegOpenKeyEx(hRootKey, szKey, NULL, KEY_READ, &hKey))
  45. {
  46. ////Delete before you return.
  47. if (NULL != szUnExpanded)
  48. delete [] szUnExpanded;
  49. return false;
  50. }
  51. if (ERROR_SUCCESS != RegQueryValueEx(hKey, szValue, NULL, &dwType,
  52. (PBYTE) szUnExpanded, pdwBufSize))
  53. {
  54. RegCloseKey(hKey);
  55. return false;
  56. }
  57. RegCloseKey(hKey);
  58. if (REG_EXPAND_SZ == dwType || dwType == REG_SZ) // NT 5.0 beta bug requires all strings to be expanded.
  59. {
  60. DWORD dwBytesUsed;
  61. dwBytesUsed = ExpandEnvironmentStrings(szUnExpanded, szBuffer, dwBufSize); // The value returned by ExpandEnviromentStrings is larger than the required size.
  62. if (0 == dwBytesUsed)
  63. return false;
  64. *pdwBufSize = dwBytesUsed;
  65. if (dwBytesUsed > dwBufSize)
  66. return false;
  67. }
  68. else
  69. {
  70. _tcsncpy(szBuffer, szUnExpanded, dwBufSize);
  71. }
  72. }
  73. __finally
  74. {
  75. if (NULL != szUnExpanded)
  76. delete [] szUnExpanded;
  77. }
  78. return true;
  79. }