[vlc-devel] [PATCH] activex: Register the plugin as handler for certain mime types
Martin Storsjö
martin at martin.st
Sun Apr 10 20:18:35 CEST 2011
This registers the plugin as a handler for the given mime types.
When unregistering the plugin, the mime types that still point
to the CLSID of this plugin are removed, other ones are left.
Register as handler for audio/amr only, at the moment.
---
Written against vlc-1.1 at the moment, I can rewrite it against
the separate activex repo if that's preferred.
projects/activex/main.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/projects/activex/main.cpp b/projects/activex/main.cpp
index 8db6bdf..9fe2af9 100644
--- a/projects/activex/main.cpp
+++ b/projects/activex/main.cpp
@@ -58,6 +58,11 @@ static DEFINE_GUID(_CATID_SafeForScripting, \
static LONG i_class_ref= 0;
static HINSTANCE h_instance= 0;
+static LPCTSTR fileTypes[] = {
+ TEXT("audio/amr"), TEXT(".amr"),
+ NULL, NULL
+};
+
HMODULE DllGetModule()
{
return h_instance;
@@ -144,6 +149,58 @@ static void UnregisterProgID(REFCLSID rclsid, unsigned int version)
}
};
+static void UnregisterMIMEType(HKEY hBaseKey, LPCTSTR szRemoveCLSID,
+ LPCTSTR szMime)
+{
+ HKEY hSubKey;
+ if( ERROR_SUCCESS != RegOpenKeyEx(hBaseKey, szMime, 0, KEY_READ, &hSubKey) )
+ return;
+
+ DWORD index = 0;
+ while (1) {
+ TCHAR name[20];
+ DWORD nameSize = sizeof(name);
+ OLECHAR szCLSID[GUID_STRLEN];
+ DWORD size = sizeof(szCLSID);
+ DWORD type;
+ LONG ret = RegEnumValue(hSubKey, index, name, &nameSize, NULL, &type,
+ (BYTE*) szCLSID, &size);
+ if (ret == ERROR_NO_MORE_ITEMS)
+ break;
+ if (ret == ERROR_SUCCESS) {
+ if (type == REG_SZ && !_tcscmp(name, TEXT("CLSID"))) {
+ if (!_tcscmp(szCLSID, szRemoveCLSID)) {
+ RegCloseKey(hSubKey);
+ SHDeleteKey(hBaseKey, szMime);
+ return;
+ }
+ break;
+ }
+ }
+ index++;
+ }
+
+ RegCloseKey(hSubKey);
+}
+
+static void UnregisterMIMETypes(REFCLSID rclsid)
+{
+ OLECHAR szCLSID[GUID_STRLEN];
+
+ StringFromGUID2(rclsid, szCLSID, GUID_STRLEN);
+
+ HKEY hBaseKey;
+ if( ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT,
+ TEXT("MIME\\Database\\Content Type"),
+ 0, KEY_WRITE, &hBaseKey) )
+ return;
+
+ for (LPCTSTR *types = fileTypes; *types; types += 2)
+ UnregisterMIMEType(hBaseKey, szCLSID, types[0]);
+
+ RegCloseKey(hBaseKey);
+}
+
STDAPI DllUnregisterServer(VOID)
{
// unregister type lib from the registry
@@ -173,6 +230,8 @@ STDAPI DllUnregisterServer(VOID)
UnregisterProgID(CLSID_VLCPlugin, 2);
UnregisterProgID(CLSID_VLCPlugin2, 1);
+ UnregisterMIMETypes(CLSID_VLCPlugin2);
+
return S_OK;
};
@@ -283,12 +342,54 @@ static HRESULT RegisterClassID(HKEY hParent, REFCLSID rclsid, unsigned int versi
keyClose(keySetDef(keyCreate(hClassKey,TEXT("TypeLib")),
szLIBID, sizeof(szLIBID)));
+
+ // EnableFullPage key
+ {
+ HKEY hSubKey = keyCreate(hClassKey, TEXT("EnableFullPage"));
+ for (LPCTSTR *types = fileTypes; *types; types += 2)
+ keyClose(keyCreate(hSubKey, types[1]));
+ keyClose(hSubKey);
+ }
RegCloseKey(hClassKey);
}
return S_OK;
}
+static void RegisterMIMEType(HKEY hBaseKey, LPCTSTR szCLSID, LPCTSTR szMime,
+ LPCTSTR szExtension)
+{
+ HKEY hSubKey;
+ if ( ERROR_SUCCESS == RegOpenKeyEx(hBaseKey, szMime, 0, KEY_READ,
+ &hSubKey) ) {
+ RegCloseKey(hSubKey);
+ return;
+ }
+ hSubKey = keyCreate(hBaseKey, szMime);
+ keySet(hSubKey, TEXT("CLSID"), szCLSID, sizeof(TCHAR)*(_tcslen(szCLSID)+1));
+ keySet(hSubKey, TEXT("Extension"), szExtension,
+ sizeof(TCHAR)*(_tcslen(szExtension)+1));
+ keyClose(hSubKey);
+}
+
+static HRESULT RegisterMIMETypes(HKEY hParent, REFCLSID rclsid)
+{
+ OLECHAR szCLSID[GUID_STRLEN];
+
+ StringFromGUID2(rclsid, szCLSID, GUID_STRLEN);
+ HKEY hBaseKey;
+ if( ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT,
+ TEXT("MIME\\Database\\Content Type"),
+ 0, KEY_CREATE_SUB_KEY, &hBaseKey) )
+ return SELFREG_E_CLASS;
+
+ for (LPCTSTR *types = fileTypes; *types; types += 2)
+ RegisterMIMEType(hBaseKey, szCLSID, types[0], types[1]);
+
+ RegCloseKey(hBaseKey);
+ return S_OK;
+}
+
STDAPI DllRegisterServer(VOID)
{
DllUnregisterServer();
@@ -308,6 +409,8 @@ STDAPI DllRegisterServer(VOID)
RegisterClassID(hBaseKey, CLSID_VLCPlugin, 1, FALSE, DllPath, DllPathLen);
RegisterClassID(hBaseKey, CLSID_VLCPlugin2, 2, TRUE, DllPath, DllPathLen);
+ RegisterMIMETypes(hBaseKey, CLSID_VLCPlugin2);
+
RegCloseKey(hBaseKey);
// indicate which component categories we support
--
1.7.3.1
More information about the vlc-devel
mailing list