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.

191 lines
4.0 KiB

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