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.

200 lines
4.5 KiB

  1. #include <wininetp.h>
  2. #include "utils.h"
  3. //----------------------------------------------------------------------------
  4. // HELPER FUNCTIONS
  5. //----------------------------------------------------------------------------
  6. // Function to get the coclass ClassId of a script engine given its name
  7. HRESULT GetScriptEngineClassIDFromName(
  8. LPCSTR pszLanguage,
  9. LPSTR pszBuff,
  10. UINT cBuffSize)
  11. {
  12. HKEY hKey = NULL;
  13. HKEY hKeySub;
  14. LONG result;
  15. HRESULT hr;
  16. LONG cClassIdLen;
  17. // Open \HKEY_CLASSES_ROOT\[pszLanguage]
  18. // LONG RegOpenKeyEx(
  19. // HKEY hKey, // handle of open key
  20. // LPCTSTR lpSubKey, // address of name of subkey to open
  21. // DWORD ulOptions, // reserved
  22. // REGSAM samDesired, // security access mask
  23. // PHKEY phkResult // address of handle of open key
  24. // );
  25. result = RegOpenKeyEx(HKEY_CLASSES_ROOT, pszLanguage, 0, KEY_READ, &hKey);
  26. if (result != ERROR_SUCCESS) {
  27. hr = E_FAIL;
  28. goto exit;
  29. }
  30. // Make sure this object supports OLE Scripting
  31. result = RegOpenKeyEx(hKey, "OLEScript", 0, KEY_READ, &hKeySub);
  32. if (result != ERROR_SUCCESS) {
  33. hr = E_FAIL;
  34. goto exit;
  35. }
  36. RegCloseKey(hKeySub);
  37. // Get the class ID
  38. // LONG RegQueryValueEx(
  39. // HKEY hKey, // handle of key to query
  40. // LPTSTR lpValueName, // address of name of value to query
  41. // LPDWORD lpReserved, // reserved
  42. // LPDWORD lpType, // address of buffer for value type
  43. // LPBYTE lpData, // address of data buffer
  44. // LPDWORD lpcbData // address of data buffer size
  45. // );
  46. result = RegOpenKeyEx(hKey, "CLSID", 0, KEY_READ, &hKeySub);
  47. if (result != ERROR_SUCCESS) {
  48. hr = E_FAIL;
  49. goto exit;
  50. }
  51. cClassIdLen = cBuffSize;
  52. result = RegQueryValue(hKeySub, NULL, pszBuff, &cClassIdLen);
  53. RegCloseKey(hKeySub);
  54. if (result != ERROR_SUCCESS) {
  55. hr = E_FAIL;
  56. goto exit;
  57. }
  58. pszBuff[cBuffSize-1] = '\0';
  59. hr = S_OK;
  60. exit:
  61. if (hKey) {
  62. RegCloseKey(hKey);
  63. }
  64. return hr;
  65. }
  66. //=--------------------------------------------------------------------------=
  67. // MakeWideFromAnsi
  68. //=--------------------------------------------------------------------------=
  69. // given a string, make a BSTR out of it.
  70. //
  71. // Parameters:
  72. // LPSTR - [in]
  73. // BYTE - [in]
  74. //
  75. // Output:
  76. // LPWSTR - needs to be cast to final desired result
  77. //
  78. // Notes:
  79. //
  80. LPWSTR MakeWideStrFromAnsi
  81. (
  82. LPCSTR psz,
  83. BYTE bType
  84. )
  85. {
  86. LPWSTR pwsz;
  87. int i;
  88. // Because delayloaded(DL) functions are being used, need to check
  89. //that they are loaded. MakeWideStrFromAnsi() is now currently
  90. //called only through JSProxy::Invoke, so a check not done in
  91. //debug mode has already been done. This check is more to make sure
  92. //people don't add calls to MakeWideStrFromAnsi without having called
  93. //DelayLoad( &g_moduleOleAut32)
  94. INET_ASSERT( g_moduleOleAut32._hDllHandle != NULL);
  95. // arg checking.
  96. //
  97. if (!psz)
  98. return NULL;
  99. // compute the length of the required BSTR
  100. //
  101. i = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
  102. if (i <= 0) return NULL;
  103. // allocate the widestr, +1 for terminating null
  104. //
  105. switch (bType) {
  106. case STR_BSTR:
  107. // -1 since it'll add it's own space for a NULL terminator
  108. //
  109. pwsz = (LPWSTR) DL(SysAllocStringLen)(NULL, i - 1);
  110. break;
  111. case STR_OLESTR:
  112. pwsz = (LPWSTR) DL(CoTaskMemAlloc)(i * sizeof(WCHAR));
  113. break;
  114. default:
  115. return NULL;
  116. ;
  117. }
  118. if (!pwsz) return NULL;
  119. MultiByteToWideChar(CP_ACP, 0, psz, -1, pwsz, i);
  120. pwsz[i - 1] = 0;
  121. return pwsz;
  122. }
  123. int ConvertAnsiDayToInt(LPSTR szday)
  124. {
  125. int today = -1;
  126. if (szday) // GetDateFormat always returns mixed caps and since this comes from a Win32 API I will
  127. { // assume a properly formatted string! :)
  128. switch (szday[0])
  129. {
  130. case 'S' :
  131. if (lstrcmp(szday,"SUN") == 0)
  132. today = 0;
  133. else
  134. {
  135. if (lstrcmp(szday,"SAT") == 0)
  136. today = 6;
  137. }
  138. break;
  139. case 'M' :
  140. if (lstrcmp(szday,"MON") == 0)
  141. today = 1;
  142. break;
  143. case 'T' :
  144. if (lstrcmp(szday,"TUE") == 0)
  145. today = 2;
  146. else
  147. {
  148. if (lstrcmp(szday,"THU") == 0)
  149. today = 4;
  150. }
  151. break;
  152. case 'W' :
  153. if (lstrcmp(szday,"WED") == 0)
  154. today = 3;
  155. break;
  156. case 'F' :
  157. if (lstrcmp(szday,"FRI") == 0)
  158. today = 5;
  159. break;
  160. }
  161. }
  162. return today;
  163. }