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.

98 lines
2.6 KiB

  1. #ifndef RES_STRING_H
  2. #define RES_STRING_H
  3. #ifdef USE_STDAFX
  4. #include "stdafx.h"
  5. #else
  6. #include <windows.h>
  7. #endif
  8. #include "TSync.hpp"
  9. #define MAX_STRING_SIZE (5000)
  10. #include "Mcs.h"
  11. #include "McsRes.h"
  12. #include "UString.hpp"
  13. class StringLoader
  14. {
  15. HINSTANCE m_hInstance; // handle to resources to load from
  16. TCriticalSection m_cs;
  17. WCHAR m_buffer[MAX_STRING_SIZE];
  18. DWORD rc;
  19. public:
  20. StringLoader()
  21. {
  22. WCHAR fullpath[400];
  23. DWORD lenValue = sizeof(fullpath);
  24. DWORD type;
  25. // first, try to load from our install directory
  26. HKEY hKey;
  27. #ifdef OFA
  28. rc = RegOpenKey(HKEY_LOCAL_MACHINE,L"Software\\Mission Critical Software\\OnePointFileAdmin",&hKey);
  29. #else
  30. rc = RegOpenKey(HKEY_LOCAL_MACHINE,L"Software\\Mission Critical Software\\DomainAdmin",&hKey);
  31. #endif
  32. if ( ! rc )
  33. {
  34. rc = RegQueryValueEx(hKey,L"Directory",0,&type,(LPBYTE)fullpath,&lenValue);
  35. if (! rc )
  36. {
  37. UStrCpy(fullpath+UStrLen(fullpath),L"McsDmRes.DLL");
  38. }
  39. RegCloseKey(hKey);
  40. }
  41. m_hInstance = LoadLibrary(fullpath);
  42. // If that fails, see if there's one anywhere in the path
  43. if ( ! m_hInstance )
  44. {
  45. m_hInstance = LoadLibrary(L"McsDmRes.DLL");
  46. }
  47. if (! m_hInstance )
  48. {
  49. MCSASSERTSZ(FALSE,"Failed to load McsDmRes.DLL");
  50. rc = GetLastError();
  51. }
  52. }
  53. WCHAR * GetString(UINT nID)
  54. {
  55. int len;
  56. WCHAR * result = NULL;
  57. m_cs.Enter();
  58. m_buffer[0] = 0;
  59. len = LoadString(m_hInstance,nID,m_buffer,MAX_STRING_SIZE);
  60. if (! len )
  61. {
  62. DWORD rc = GetLastError();
  63. }
  64. result = new WCHAR[len+1];
  65. wcscpy(result,m_buffer);
  66. m_cs.Leave();
  67. return result;
  68. }
  69. };
  70. extern StringLoader gString;
  71. class TempString
  72. {
  73. WCHAR * m_data;
  74. public:
  75. TempString(WCHAR * data) { m_data = data; }
  76. ~TempString() { if ( m_data ) delete [] m_data; }
  77. operator WCHAR * () { return m_data; }
  78. operator WCHAR const * () { return (WCHAR const*)m_data; }
  79. };
  80. //#define GET_BSTR(nID) _bstr_t(SysAllocString(GET_STRING(nID)),false)
  81. #define GET_BSTR(nID) _bstr_t((WCHAR*)TempString(gString.GetString(nID)))
  82. #define GET_STRING(nID) GET_STRING2(gString,nID)
  83. #define GET_STRING2(strObj,nID) TempString(strObj.GetString(nID))
  84. #define GET_WSTR(nID) ((WCHAR*)TempString(gString.GetString(nID)))
  85. #endif RES_STRING_H