]> git.sesse.net Git - vlc/blobdiff - activex/main.cpp
Port new URL tests to test/
[vlc] / activex / main.cpp
index 48ada9be5d0f7b40f0b0e0d6875ea9c472e9e65c..98ad903d5da87d6d8e0cb3426e0f1c602d004959 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * main.cpp: ActiveX control for VLC
  *****************************************************************************
- * Copyright (C) 2005 VideoLAN
+ * Copyright (C) 2005 the VideoLAN team
  *
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
  *
@@ -17,7 +17,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "plugin.h"
@@ -72,7 +72,8 @@ STDAPI DllCanUnloadNow(VOID)
     return (0 == i_class_ref) ? S_OK: S_FALSE;
 };
 
-static LPCTSTR TStrFromGUID(REFGUID clsid) {
+static LPCTSTR TStrFromGUID(REFGUID clsid)
+{
     LPOLESTR oleStr;
 
     if( FAILED(StringFromIID(clsid, &oleStr)) )
@@ -95,7 +96,7 @@ static LPCTSTR TStrFromGUID(REFGUID clsid) {
     if( len > 0 )
     {
         clsidStr = (wchar_t *)CoTaskMemAlloc(len*sizeof(wchar_t));
-        WideCharToMultiByte(CP_ACP, 0, oleStr, -1, pct_CLSID, len);
+        MultiByteToWideChar(CP_ACP, 0, oleStr, -1, pct_CLSID, len);
     }
 #endif
     CoTaskMemFree(oleStr);
@@ -160,7 +161,7 @@ STDAPI DllRegisterServer(VOID)
     char DllPath[MAX_PATH];
     DWORD DllPathLen= GetModuleFileName(h_instance, DllPath, sizeof(DllPath)) ;
        if( 0 == DllPathLen )
-        return E_FAIL;
+        return E_UNEXPECTED;
 
     LPCTSTR psz_CLSID = TStrFromGUID(CLSID_VLCPlugin);
 
@@ -170,7 +171,7 @@ STDAPI DllRegisterServer(VOID)
     HKEY hBaseKey;
 
     if( ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("CLSID"), 0, KEY_CREATE_SUB_KEY, &hBaseKey) )
-        return E_FAIL;
+        return SELFREG_E_CLASS;
 
     HKEY hClassKey = keyCreate(hBaseKey, psz_CLSID);
     if( NULL != hClassKey )
@@ -185,6 +186,25 @@ STDAPI DllRegisterServer(VOID)
         hSubKey = keyCreate(hClassKey, TEXT("Control"));
         RegCloseKey(hSubKey);
 
+        // Insertable key value
+        //hSubKey = keyCreate(hClassKey, TEXT("Insertable"));
+        //RegCloseKey(hSubKey);
+
+        // ToolboxBitmap32 key value
+        hSubKey = keyCreate(hClassKey, TEXT("ToolboxBitmap32"));
+        strcpy(DllPath+DllPathLen, ",1");
+        RegSetValueEx(hSubKey, NULL, 0, REG_SZ,
+                (const BYTE*)DllPath, DllPathLen+2);
+        DllPath[DllPathLen] = '\0';
+        RegCloseKey(hSubKey);
+
+#ifdef BUILD_LOCALSERVER
+        // LocalServer32 key value
+        hSubKey = keyCreate(hClassKey, TEXT("LocalServer32"));
+        RegSetValueEx(hSubKey, NULL, 0, REG_SZ,
+                (const BYTE*)DllPath, DllPathLen);
+        RegCloseKey(hSubKey);
+#else
         // InprocServer32 key value
         hSubKey = keyCreate(hClassKey, TEXT("InprocServer32"));
         RegSetValueEx(hSubKey, NULL, 0, REG_SZ,
@@ -192,6 +212,7 @@ STDAPI DllRegisterServer(VOID)
         RegSetValueEx(hSubKey, TEXT("ThreadingModel"), 0, REG_SZ,
                 (const BYTE*)THREADING_MODEL, sizeof(THREADING_MODEL));
         RegCloseKey(hSubKey);
+#endif
 
         // MiscStatus key value
         hSubKey = keyCreate(hClassKey, TEXT("MiscStatus\\1"));
@@ -277,6 +298,9 @@ STDAPI DllRegisterServer(VOID)
 
             RegCloseKey(hSubKey);
         }
+        //hSubKey = keyCreate(hBaseKey, TEXT("Insertable"));
+        //RegCloseKey(hSubKey);
         RegCloseKey(hBaseKey);
     }
 
@@ -298,19 +322,29 @@ STDAPI DllRegisterServer(VOID)
 
     // register type lib into the registry
     ITypeLib *typeLib;
+
+#ifdef BUILD_LOCALSERVER
+    // replace .exe by .tlb
+    strcpy(DllPath+DllPathLen-4, ".tlb");
+#endif
+    
 #ifndef OLE2ANSI
-    size_t typeLibPathLen = MultiByteToWideChar(CP_ACP, 0, DllPath, DllPathLen, NULL, 0);
+    size_t typeLibPathLen = MultiByteToWideChar(CP_ACP, 0, DllPath, -1, NULL, 0);
     if( typeLibPathLen > 0 )
     {
         LPOLESTR typeLibPath = (LPOLESTR)CoTaskMemAlloc(typeLibPathLen*sizeof(wchar_t));
         MultiByteToWideChar(CP_ACP, 0, DllPath, DllPathLen, typeLibPath, typeLibPathLen);
-        if( SUCCEEDED(LoadTypeLibEx(typeLibPath, REGKIND_REGISTER, &typeLib)) )
-            typeLib->Release();
+        if( FAILED(LoadTypeLibEx(typeLibPath, REGKIND_REGISTER, &typeLib)) )
+#ifndef BUILD_LOCALSERVER
+            return SELFREG_E_TYPELIB;
+        typeLib->Release();
+#endif
         CoTaskMemFree((void *)typeLibPath);
     }
 #else
-    if( SUCCEEDED(LoadTypeLibEx((LPOLESTR)DllPath, REGKIND_REGISTER, &typeLib)) )
-        typeLib->Release();
+    if( FAILED(LoadTypeLibEx((LPOLESTR)DllPath, REGKIND_REGISTER, &typeLib)) )
+        return SELFREG_E_TYPELIB;
+    typeLib->Release();
 #endif
 
     CoTaskMemFree((void *)psz_CLSID);
@@ -335,6 +369,14 @@ STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
         return 1;
     }
 
+    h_instance = hInst;
+
+    if( FAILED(DllRegisterServer()) )
+    {
+        cerr << "cannot register Local Server" << endl;
+        return 1;
+    }
+
     IUnknown *classProc = NULL;
 
     if( FAILED(DllGetClassObject(CLSID_VLCPlugin, IID_IUnknown, (LPVOID *)&classProc)) )