Changeset 2754 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- May 22, 2007 2:19:37 AM (18 years ago)
- Location:
- trunk/src/VBox/Main/glue
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/com.cpp
r2672 r2754 1 1 /** @file 2 *3 2 * MS COM / XPCOM Abstraction Layer 4 3 */ … … 49 48 namespace com 50 49 { 51 52 HRESULT Initialize()53 {54 HRESULT rc = E_FAIL;55 56 #if !defined (VBOX_WITH_XPCOM)57 58 rc = CoInitializeEx (NULL, COINIT_MULTITHREADED |59 COINIT_DISABLE_OLE1DDE |60 COINIT_SPEED_OVER_MEMORY);61 62 #else63 64 /* Set VBOX_XPCOM_HOME if not present */65 if (!getenv("VBOX_XPCOM_HOME"))66 {67 /* get the executable path */68 char szPathProgram[1024];69 int rcVBox = RTPathProgram(szPathProgram, sizeof(szPathProgram));70 if (VBOX_SUCCESS(rcVBox))71 {72 setenv("VBOX_XPCOM_HOME", szPathProgram, 1);73 }74 }75 76 nsCOMPtr <nsIEventQueue> eventQ;77 rc = NS_GetMainEventQ (getter_AddRefs (eventQ));78 if (rc == NS_ERROR_NOT_INITIALIZED)79 {80 XPCOMGlueStartup (nsnull);81 nsCOMPtr <nsIServiceManager> serviceManager;82 rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager), nsnull, nsnull);83 if (NS_SUCCEEDED (rc))84 {85 nsCOMPtr <nsIComponentRegistrar> registrar =86 do_QueryInterface (serviceManager, &rc);87 if (NS_SUCCEEDED (rc))88 registrar->AutoRegister (nsnull);89 }90 }91 92 #endif93 94 AssertComRC (rc);95 96 return rc;97 }98 99 void Shutdown()100 {101 #if !defined (VBOX_WITH_XPCOM)102 103 CoUninitialize();104 105 #else106 107 nsCOMPtr <nsIEventQueue> eventQ;108 nsresult rc = NS_GetMainEventQ (getter_AddRefs (eventQ));109 if (NS_SUCCEEDED (rc))110 {111 BOOL isOnMainThread = FALSE;112 eventQ->IsOnCurrentThread (&isOnMainThread);113 eventQ = nsnull; /* early release */114 if (isOnMainThread)115 {116 /* only the main thread needs to uninitialize XPCOM */117 NS_ShutdownXPCOM (nsnull);118 XPCOMGlueShutdown();119 }120 }121 122 #endif123 }124 50 125 51 void GetInterfaceNameByIID (const GUID &aIID, BSTR *aName) -
trunk/src/VBox/Main/glue/initterm.cpp
r2751 r2754 1 1 /** @file 2 * 3 * MS COM / XPCOM Abstraction Layer 2 * MS COM / XPCOM Abstraction Layer - Initialization and Termination. 4 3 */ 5 4 … … 123 122 } 124 123 125 void GetInterfaceNameByIID (const GUID &aIID, BSTR *aName)126 {127 Assert (aName);128 if (!aName)129 return;130 131 *aName = NULL;132 133 #if !defined (VBOX_WITH_XPCOM)134 135 LONG rc;136 LPOLESTR iidStr = NULL;137 if (StringFromIID (aIID, &iidStr) == S_OK)138 {139 HKEY ifaceKey;140 rc = RegOpenKeyExW (HKEY_CLASSES_ROOT, L"Interface",141 0, KEY_QUERY_VALUE, &ifaceKey);142 if (rc == ERROR_SUCCESS)143 {144 HKEY iidKey;145 rc = RegOpenKeyExW (ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);146 if (rc == ERROR_SUCCESS)147 {148 /* determine the size and type */149 DWORD sz, type;150 rc = RegQueryValueExW (iidKey, NULL, NULL, &type, NULL, &sz);151 if (rc == ERROR_SUCCESS && type == REG_SZ)152 {153 /* query the value to BSTR */154 *aName = SysAllocStringLen (NULL, (sz + 1) /155 sizeof (TCHAR) + 1);156 rc = RegQueryValueExW (iidKey, NULL, NULL, NULL,157 (LPBYTE) *aName, &sz);158 if (rc != ERROR_SUCCESS)159 {160 SysFreeString (*aName);161 aName = NULL;162 }163 }164 RegCloseKey (iidKey);165 }166 RegCloseKey (ifaceKey);167 }168 CoTaskMemFree (iidStr);169 }170 171 #else172 173 nsresult rv;174 nsCOMPtr <nsIInterfaceInfoManager> iim =175 do_GetService (NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);176 if (NS_SUCCEEDED (rv))177 {178 nsCOMPtr <nsIInterfaceInfo> iinfo;179 rv = iim->GetInfoForIID (&aIID, getter_AddRefs (iinfo));180 if (NS_SUCCEEDED (rv))181 {182 const char *iname = NULL;183 iinfo->GetNameShared (&iname);184 char *utf8IName = NULL;185 if (VBOX_SUCCESS (RTStrCurrentCPToUtf8 (&utf8IName, iname)))186 {187 PRTUCS2 ucs2IName = NULL;188 if (VBOX_SUCCESS (RTStrUtf8ToUcs2 (&ucs2IName, utf8IName)))189 {190 *aName = SysAllocString ((OLECHAR *) ucs2IName);191 RTStrUcs2Free (ucs2IName);192 }193 RTStrFree (utf8IName);194 }195 }196 }197 198 #endif199 }200 201 124 }; // namespace com
Note:
See TracChangeset
for help on using the changeset viewer.