ChaosFilter.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:12k
源码类别:
P2P编程
开发平台:
Visual C++
- // chaosfilter.cpp : 定义 DLL 应用程序的入口点。
- //
- #include "stdafx.h"
- #include "chaosfilter.h"
- extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
- HANDLE g_hModule = NULL;
- BOOL APIENTRY DllMain( HANDLE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- g_hModule = hModule;
- return DllEntryPoint((HINSTANCE)hModule, ul_reason_for_call, lpReserved);;
- }
- //
- ////////////////////////////////////////////////////////////////////////
- //
- // Exported entry points for registration and unregistration
- // (in this case they only call through to default implementations).
- //
- ////////////////////////////////////////////////////////////////////////
- namespace {
- BOOL GetRegString(HKEY hkey, LPCTSTR regToBeGet, LPCTSTR valueName, LPTSTR pdata)
- {
- HKEY hkSub;
- DWORD dis;
- if(RegCreateKeyEx(hkey, regToBeGet, 0, _T(""), 0,
- KEY_READ, NULL, &hkSub, &dis) != ERROR_SUCCESS)
- return FALSE;
- DWORD len = 0;
- if(RegQueryValueEx(hkSub, valueName, 0, NULL, NULL, &len) != ERROR_SUCCESS)
- return FALSE;
- if(RegQueryValueEx(hkSub, valueName, 0, NULL, (BYTE*)pdata, &len) != ERROR_SUCCESS)
- return FALSE;
- RegCloseKey(hkSub);
- return TRUE;
- }
- BOOL SetRegEx(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, BYTE* pdata, DWORD type, UINT size)
- {
- HKEY hkSub;
- DWORD dis;
- if(RegCreateKeyEx(hkey, regToBeSet, 0, _T(""), 0,
- KEY_WRITE, NULL, &hkSub, &dis) != ERROR_SUCCESS)
- return FALSE;
- if(RegSetValueEx(hkSub, valueName, 0, type, pdata, size) != ERROR_SUCCESS)
- return FALSE;
- RegCloseKey(hkSub);
- return TRUE;
- }
- BOOL SetRegString(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, LPCTSTR data)
- {
- return SetRegEx(hkey, regToBeSet, valueName, (BYTE*) data, REG_SZ, (UINT) _tcslen(data));
- }
- BOOL SetRegDWord(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, DWORD word)
- {
- return SetRegEx(hkey, regToBeSet, valueName, (BYTE*) &word, REG_DWORD, sizeof(DWORD));
- }
- BOOL SetRegBin(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, BYTE* data, UINT size)
- {
- return SetRegEx(hkey, regToBeSet, valueName, data, REG_BINARY, size);
- }
- BOOL CopyRegString(HKEY hkey, LPCTSTR regToBeCopy, LPCTSTR regCopyTo, LPCTSTR valueName) {
- LPTSTR temp = new TCHAR[512];
- memset(temp, 0, 512*sizeof(TCHAR));
- if(!GetRegString(hkey, regToBeCopy, valueName, temp))
- {
- delete[] temp;
- return FALSE;
- }
- if(!SetRegString(hkey, regCopyTo, valueName, temp))
- {
- delete[] temp;
- return FALSE;
- }
- delete[] temp;
- return TRUE;
- }
- }
- STDAPI DllRegisterServer()
- {
- SetRegString(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.gtv"), _T("Source Filter"), Chaos_GUID);
- SetRegString(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), _T(".gtv"), Chaos_GUID);
- SetRegString(HKEY_CLASSES_ROOT, _T(".gtv"), NULL, _T("gtv_auto_file"));
- // SetRegString(HKEY_CLASSES_ROOT, _T(".gtv"), _T("PerceivedType"), _T("video")); //和WMP8.0冲突。去掉
- DWORD nUrlListCount = 65536;
- SetRegBin(HKEY_CLASSES_ROOT, _T("gtv_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
- SetRegBin(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Classes\gtv_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
- LPTSTR playeropencommand = new TCHAR[MAX_PATH + 100];
- LPTSTR playerplaycommand = new TCHAR[MAX_PATH + 100];
- memset(playeropencommand, 0, (MAX_PATH+100)*sizeof(TCHAR));
- memset(playerplaycommand, 0, (MAX_PATH+100)*sizeof(TCHAR));
- playeropencommand[0] = _T('"');
- LPTSTR bufHead = playeropencommand + 1;
- BOOL wmplayerOK = FALSE;
- //使用WMP8.0/9.0
- if(GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Player.Path"), bufHead))
- wmplayerOK = TRUE;
- //使用MPlayer2
- else if(GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Player.Path"), bufHead))
- wmplayerOK = FALSE;
- else
- ;
- playeropencommand[_tcslen(playeropencommand)] = _T('"');
- _tcscpy(playerplaycommand, playeropencommand);
- //组合出open和play命令行
- TCHAR tmp[100];
- memset(tmp, 0, 100*sizeof(TCHAR));
- if(wmplayerOK)
- GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Shell.Open"), tmp);
- else
- GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Shell.Open"), tmp);
- size_t len = strlen(playeropencommand);
- LPTSTR appendpos = playeropencommand + len;
- _tcscpy(appendpos, tmp);
- memset(tmp, 0, 100*sizeof(TCHAR));
- if(wmplayerOK)
- GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Shell.Play"), tmp);
- else
- GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Shell.Play"), tmp);
- appendpos = playerplaycommand + len;
- _tcscpy(appendpos, tmp);
- SetRegString(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open\command"), _T(""), playeropencommand);
- SetRegString(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play\command"), _T(""), playerplaycommand);
- //只尝试用WMP的图标,得不到就算了.
- CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\DefaultIcon"), _T("gtv_auto_file\DefaultIcon"), _T(""));
- CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\notepad.exe\shell\open\command"), _T("gtv_auto_file\shell\edit\command"), _T(""));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"),
- _T("18123"), _T("高维视讯直播文件 (*.gtv)"));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"),
- _T("18123"), _T("高维视讯直播文件"));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"),
- _T("18123"), _T("*.gtv"));
- DWORD value = 1;
- SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), _T("Permissions"), value);
- SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), _T("Runtime"), value);
- //以下同样地处理ZZL
- SetRegString(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.zzl"), _T("Source Filter"), Chaos_GUID);
- SetRegString(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), _T(".zzl"), Chaos_GUID);
- SetRegString(HKEY_CLASSES_ROOT, _T(".zzl"), NULL, _T("zzl_auto_file"));
- // SetRegString(HKEY_CLASSES_ROOT, _T(".zzl"), _T("PerceivedType"), _T("video"));
- nUrlListCount = 65536;
- SetRegBin(HKEY_CLASSES_ROOT, _T("zzl_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
- SetRegBin(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Classes\zzl_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
- SetRegString(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open\command"), _T(""), playeropencommand);
- SetRegString(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play\command"), _T(""), playerplaycommand);
- //只尝试用WMP的图标,得不到就算了.
- CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\DefaultIcon"), _T("gtv_auto_file\DefaultIcon"), _T(""));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"),
- _T("18124"), _T("高维视讯点播文件 (*.zzl)"));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"),
- _T("18124"), _T("高维视讯点播文件"));
- SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"),
- _T("18124"), _T("*.zzl"));
- value = 1;
- SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), _T("Permissions"), value);
- SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), _T("Runtime"), value);
- //注册GAOV协议
- SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), _T("Source Filter"), Chaos_GUID);
- SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), _T("URL Protocol"), _T(""));
- SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), NULL, _T("URL: Mysee Media Protocol"));
- SetRegString(HKEY_CLASSES_ROOT, _T("GAOV\shell\open\command"), _T(""), playeropencommand);
- //让WMP允许我们的GAOV和GVWRAP协议
- SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Schemes\GAOV"), _T("Runtime"), 1);
- //命令行的作用已经结束
- delete[] playeropencommand;
- delete[] playerplaycommand;
- return AMovieDllRegisterServer2(TRUE);
- }
- STDAPI DllUnregisterServer()
- {
- HKEY hkSub;
- DWORD dis;
- LONG lRes;
- lRes = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T(".gtv"));
- RegDeleteValue(hkSub, _T(".zzl"));
- RegCloseKey(hkSub);
- lRes = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\SupportedTypes"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T(".gtv"));
- RegDeleteValue(hkSub, _T(".zzl"));
- RegCloseKey(hkSub);
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.gtv"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T(".gtv"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\DefaultIcon"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\EditFlags"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\edit\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\edit"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.zzl"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T(".zzl"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\DefaultIcon"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\EditFlags"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\edit\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\edit"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file"));
- lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T("18123"));
- RegDeleteValue(hkSub, _T("18124"));
- RegCloseKey(hkSub);
- lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T("18123"));
- RegDeleteValue(hkSub, _T("18124"));
- RegCloseKey(hkSub);
- lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T("18123"));
- RegDeleteValue(hkSub, _T("18124"));
- RegCloseKey(hkSub);
- lRes = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T("Permissions"));
- RegDeleteValue(hkSub, _T("Runtime"));
- RegCloseKey(hkSub);
- lRes = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), 0, _T(""), 0,
- KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
- RegDeleteValue(hkSub, _T("Permissions"));
- RegDeleteValue(hkSub, _T("Runtime"));
- RegCloseKey(hkSub);
- //反注册GAOV协议
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell\open\command"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell\open"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell"));
- RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV"));
- RegDeleteKey(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Schemes\GAOV"));
- return AMovieDllRegisterServer2(FALSE);
- }