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.

141 lines
3.5 KiB

  1. /*--------------------------------------------------------------------
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. --------------------------------------------------------------------*/
  4. #include "windows.h"
  5. #include "locresman.h"
  6. HRESULT WINAPI HrLoadLocalizedLibrarySFU(const HINSTANCE hInstExe, const WCHAR *pwchDllName, HINSTANCE *phInstLocDll, WCHAR *pwchLoadedDllName)
  7. {
  8. HINSTANCE hInst;
  9. WCHAR wzDllFullPath[MAX_PATH];
  10. WCHAR wzInstallPath[MAX_PATH];
  11. WCHAR wzUILanguage[MAX_PATH];
  12. WCHAR *pwchKey = (WCHAR *)L"SOFTWARE\\Microsoft\\Services For Unix\0";
  13. WCHAR *pwchInstallPath = (WCHAR *)L"InstallPath\0";
  14. WCHAR *pwchUILanguage = (WCHAR *)L"UILanguage\0";
  15. HKEY hKey = NULL;
  16. DWORD dwSizeI, dwSizeU;
  17. DWORD dwType;
  18. HRESULT hr = S_OK;
  19. LANGID lidUI = 0;
  20. int i;
  21. *phInstLocDll = hInstExe;
  22. if(NULL == pwchDllName)
  23. {
  24. hr = E_UNEXPECTED;
  25. goto L_Return;
  26. }
  27. if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, pwchKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
  28. {
  29. hr = E_UNEXPECTED;
  30. goto L_Return;
  31. }
  32. dwSizeI = sizeof(wzInstallPath);
  33. if (RegQueryValueExW(hKey, pwchInstallPath, NULL, &dwType, (LPBYTE) wzInstallPath, &dwSizeI) != ERROR_SUCCESS)
  34. {
  35. hr = E_UNEXPECTED;
  36. goto L_Return;
  37. }
  38. if(dwType != REG_SZ)
  39. {
  40. hr = E_UNEXPECTED;
  41. goto L_Return;
  42. }
  43. dwSizeU = sizeof(wzUILanguage);
  44. if (RegQueryValueExW(hKey, pwchUILanguage, NULL, &dwType, (LPBYTE) wzUILanguage, &dwSizeU) != ERROR_SUCCESS)
  45. {
  46. hr = E_UNEXPECTED;
  47. goto L_Return;
  48. }
  49. if(dwType != REG_SZ)
  50. {
  51. hr = E_UNEXPECTED;
  52. goto L_Return;
  53. }
  54. if ((wcslen(pwchDllName) + dwSizeU + dwSizeI + 2 /* for the backslash and null*/) >= MAX_PATH)
  55. {
  56. hr = E_OUTOFMEMORY;
  57. goto L_Return;
  58. }
  59. // At this point we assume that the string wzUILanguage will be a lid
  60. // expressed in decimal, i.e. for lid 0x409, we would have a string "1033"
  61. for (i = 0; 0 != wzUILanguage[i]; i++)
  62. {
  63. lidUI = (unsigned short) (lidUI * 10 + (wzUILanguage[i] - '0'));
  64. }
  65. // If we are 0x409, there is nothing to do!
  66. if (MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT) == lidUI)
  67. {
  68. goto L_Return;
  69. }
  70. wsprintfW(wzDllFullPath, (const WCHAR *)L"%s\\common\\%s", wzInstallPath, pwchDllName);
  71. if (NULL == (hInst = LoadLibraryExW(wzDllFullPath, 0, DONT_RESOLVE_DLL_REFERENCES)))
  72. {
  73. hr = E_HANDLE;
  74. goto L_Return;
  75. }
  76. *phInstLocDll = hInst;
  77. if (pwchLoadedDllName)
  78. wcscpy(pwchLoadedDllName, wzDllFullPath);
  79. L_Return:;
  80. if (hKey)
  81. {
  82. RegCloseKey(hKey);
  83. }
  84. return (hr);
  85. }
  86. // 8bit chars. wrapper for the unicode API.
  87. HRESULT WINAPI HrLoadLocalizedLibrarySFU_A(const HINSTANCE hInstExe, const char *pchDllName, HINSTANCE *phInstLocDll, char *pchLoadedDllName)
  88. {
  89. WCHAR wzDllName[MAX_PATH];
  90. WCHAR *pwchDllName;
  91. WCHAR wzLoadedDllName[MAX_PATH];
  92. int cch;
  93. HRESULT hr = E_FAIL;
  94. if (NULL != pchDllName)
  95. {
  96. wzDllName[0] = 0;
  97. cch = MultiByteToWideChar(CP_ACP, 0, pchDllName, -1, wzDllName, sizeof(wzDllName)/sizeof(WCHAR)-1);
  98. wzDllName[(sizeof(wzDllName)/sizeof(WCHAR))-1] = 0;
  99. pwchDllName = wzDllName;
  100. }
  101. else
  102. {
  103. goto end;
  104. }
  105. hr = HrLoadLocalizedLibrarySFU(hInstExe, pwchDllName, phInstLocDll, wzLoadedDllName);
  106. if (SUCCEEDED(hr))
  107. {
  108. if (NULL != pchLoadedDllName)
  109. {
  110. pchLoadedDllName[0] = 0;
  111. cch = WideCharToMultiByte(CP_ACP, 0, wzLoadedDllName, -1, pchLoadedDllName, MAX_PATH, NULL, NULL);
  112. pchLoadedDllName[cch] = 0;
  113. }
  114. }
  115. end :
  116. return (hr);
  117. }
  118. #ifdef TGT_DLL
  119. #pragma warning( disable : 4100 )
  120. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
  121. {
  122. return TRUE;
  123. }
  124. #endif