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.

102 lines
2.7 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. LONG lRet = 0;
  26. // first, try to load from our install directory
  27. HKEY hKey;
  28. #ifdef OFA
  29. lRet = RegOpenKey((HKEY)HKEY_LOCAL_MACHINE,L"Software\\Mission Critical Software\\OnePointFileAdmin",&hKey);
  30. #else
  31. lRet = RegOpenKey((HKEY)HKEY_LOCAL_MACHINE,L"Software\\Mission Critical Software\\DomainAdmin",&hKey);
  32. #endif
  33. if ( !lRet )
  34. {
  35. lRet = RegQueryValueEx(hKey,L"Directory",0,&type,(LPBYTE)fullpath,&lenValue);
  36. if (!lRet )
  37. {
  38. UStrCpy(fullpath+UStrLen(fullpath),L"McsDmRes.DLL");
  39. }
  40. RegCloseKey(hKey);
  41. }
  42. m_hInstance = LoadLibrary(fullpath);
  43. // If that fails, see if there's one anywhere in the path
  44. if ( ! m_hInstance )
  45. {
  46. m_hInstance = LoadLibrary(L"McsDmRes.DLL");
  47. }
  48. if (! m_hInstance )
  49. {
  50. MCSASSERTSZ(FALSE,"Failed to load McsDmRes.DLL");
  51. rc = GetLastError();
  52. }
  53. }
  54. WCHAR * GetString(UINT nID)
  55. {
  56. int len;
  57. WCHAR * result = NULL;
  58. m_cs.Enter();
  59. m_buffer[0] = 0;
  60. len = LoadString(m_hInstance,nID,m_buffer,MAX_STRING_SIZE);
  61. if (! len )
  62. {
  63. // DWORD rc = GetLastError();
  64. GetLastError();
  65. }
  66. result = new WCHAR[len+1];
  67. if (!result)
  68. return NULL;
  69. wcscpy(result,m_buffer);
  70. m_cs.Leave();
  71. return result;
  72. }
  73. };
  74. extern StringLoader gString;
  75. class TempString
  76. {
  77. WCHAR * m_data;
  78. public:
  79. TempString(WCHAR * data) { m_data = data; }
  80. ~TempString() { if ( m_data ) delete [] m_data; }
  81. operator WCHAR * () { return m_data; }
  82. operator WCHAR const * () { return (WCHAR const*)m_data; }
  83. };
  84. //#define GET_BSTR(nID) _bstr_t(SysAllocString(GET_STRING(nID)),false)
  85. #define GET_BSTR(nID) _bstr_t((WCHAR*)TempString(gString.GetString(nID)))
  86. #define GET_STRING(nID) GET_STRING2(gString,nID)
  87. #define GET_STRING2(strObj,nID) TempString(strObj.GetString(nID))
  88. #define GET_WSTR(nID) ((WCHAR*)TempString(gString.GetString(nID)))
  89. #endif RES_STRING_H