]> git.sesse.net Git - vlc/blobdiff - activex/main.cpp
* destroy some mutex'es once in a while to prevent memleaks. Suggested by a forumuser...
[vlc] / activex / main.cpp
index bd4c0c3877f220e24796be67707a301a0e07be7e..f40854ad4cf1b2ad95c0a146aca8f048ca12cc9f 100644 (file)
@@ -29,6 +29,8 @@
 #include <windows.h>
 #include <shlwapi.h>
 
+#include <guiddef.h>
+
 using namespace std;
 
 #define COMPANY_STR "VideoLAN"
@@ -43,21 +45,28 @@ using namespace std;
 #define GUID_STRLEN 39
 
 /*
-** MingW headers do not declare those
+** MingW headers & libs do not declare those
 */
-extern const CATID CATID_SafeForInitializing;
-extern const CATID CATID_SafeForScripting;
+static DEFINE_GUID(_CATID_InternetAware,       0x0DE86A58, 0x2BAA, 0x11CF, 0xA2, 0x29, 0x00,0xAA,0x00,0x3D,0x73,0x52);
+static DEFINE_GUID(_CATID_SafeForInitializing, 0x7DD95802, 0x9882, 0x11CF, 0x9F, 0xA9, 0x00,0xAA,0x00,0x6C,0x42,0xC4);
+static DEFINE_GUID(_CATID_SafeForScripting,    0x7DD95801, 0x9882, 0x11CF, 0x9F, 0xA9, 0x00,0xAA,0x00,0x6C,0x42,0xC4);
 
 static LONG i_class_ref= 0;
 static HINSTANCE h_instance= 0;
 
+HMODULE DllGetModule()
+{
+    return h_instance;
+};
+
 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
 {
     HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
 
     *ppv = NULL;
 
-    if( CLSID_VLCPlugin2 == rclsid )
+    if( (CLSID_VLCPlugin == rclsid )
+     || ( CLSID_VLCPlugin2 == rclsid) )
     {
         VLCPluginClass *plugin = new VLCPluginClass(&i_class_ref, h_instance, rclsid);
         hr = plugin->QueryInterface(riid, ppv);
@@ -144,8 +153,9 @@ STDAPI DllUnregisterServer(VOID)
         CATID implCategories[] = {
             CATID_Control,
             CATID_PersistsToPropertyBag,
-            CATID_SafeForInitializing,
-            CATID_SafeForScripting,
+            _CATID_InternetAware,
+            _CATID_SafeForInitializing,
+            _CATID_SafeForScripting,
         };
 
         pcr->UnRegisterClassImplCategories(CLSID_VLCPlugin,
@@ -187,9 +197,9 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
             keyClose(keySetDef(keyCreate(hProgKey, "CLSID"),
                 psz_CLSID,
                 GUID_STRLEN));
-     
+
             //hSubKey = keyClose(keyCreate(hBaseKey, "Insertable"));
-     
             RegCloseKey(hProgKey);
         }
         if( isDefault )
@@ -203,7 +213,7 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
                 keyClose(keySetDef(keyCreate(hProgKey, "CLSID"),
                     psz_CLSID,
                     GUID_STRLEN));
-         
+
                 keyClose(keySetDef(keyCreate(hProgKey, "CurVer"),
                     progId));
             }
@@ -292,14 +302,14 @@ STDAPI DllRegisterServer(VOID)
 
     char DllPath[MAX_PATH];
     DWORD DllPathLen=GetModuleFileNameA(h_instance, DllPath, sizeof(DllPath)) ;
-       if( 0 == DllPathLen )
+    if( 0 == DllPathLen )
         return E_UNEXPECTED;
 
     HKEY hBaseKey;
 
     if( ERROR_SUCCESS != RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_CREATE_SUB_KEY, &hBaseKey) )
         return SELFREG_E_CLASS;
-    
+
     RegisterClassID(hBaseKey, CLSID_VLCPlugin, 1, FALSE, DllPath, DllPathLen);
     RegisterClassID(hBaseKey, CLSID_VLCPlugin2, 2, TRUE, DllPath, DllPathLen);
 
@@ -312,8 +322,9 @@ STDAPI DllRegisterServer(VOID)
         CATID implCategories[] = {
             CATID_Control,
             CATID_PersistsToPropertyBag,
-            CATID_SafeForInitializing,
-            CATID_SafeForScripting,
+            _CATID_InternetAware,
+            _CATID_SafeForInitializing,
+            _CATID_SafeForScripting,
         };
 
         pcr->RegisterClassImplCategories(CLSID_VLCPlugin,
@@ -330,7 +341,7 @@ STDAPI DllRegisterServer(VOID)
     // replace .exe by .tlb
     strcpy(DllPath+DllPathLen-4, ".tlb");
 #endif
-    
+
 #ifndef OLE2ANSI
     size_t typeLibPathLen = MultiByteToWideChar(CP_ACP, 0, DllPath, -1, NULL, 0);
     if( typeLibPathLen > 0 )
@@ -384,6 +395,7 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
         return 0;
  
     DWORD dwRegisterClassObject;
+    DWORD dwRegisterClassObject2;
 
     if( FAILED(CoRegisterClassObject(CLSID_VLCPlugin, classProc,
         CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwRegisterClassObject)) )
@@ -395,6 +407,10 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
                     ACTIVEOBJECT_WEAK, &dwRegisterActiveObject)) )
         return 0;
 
+    if( FAILED(RegisterActiveObject(classProc, CLSID_VLCPlugin2,
+                    ACTIVEOBJECT_WEAK, &dwRegisterActiveObject2)) )
+        return 0;
+
     classProc->Release();
 
     /*
@@ -405,7 +421,7 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
         while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
         {
             if( msg.message == WM_QUIT )
-                break;  // Leave the PeekMessage while() loop
+                break;  // break out PeekMessage loop
 
             /*if(TranslateAccelerator(ghwndApp, ghAccel, &msg))
                 continue;*/
@@ -415,7 +431,7 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
         }
 
         if(msg.message == WM_QUIT)
-            break;  // Leave the for() loop
+            break;  // break out main loop
 
         WaitMessage();
     }
@@ -423,8 +439,11 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
     if( SUCCEEDED(RevokeActiveObject(dwRegisterActiveObject, NULL)) )
         CoRevokeClassObject(dwRegisterClassObject);
 
+    if( SUCCEEDED(RevokeActiveObject(dwRegisterActiveObject2, NULL)) )
+        CoRevokeClassObject(dwRegisterClassObject2);
+
     // Reached on WM_QUIT message
-    CoUninitialize();
+    OleUninitialize();
     return ((int) msg.wParam);
 };