📄 plugin.cpp
字号:
/***************************************************************************** * plugin.cpp: ActiveX control for VLC ***************************************************************************** * Copyright (C) 2006 the VideoLAN team * * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#include "plugin.h"#include "oleobject.h"#include "olecontrol.h"#include "oleinplaceobject.h"#include "oleinplaceactiveobject.h"#include "persistpropbag.h"#include "persiststreaminit.h"#include "persiststorage.h"#include "provideclassinfo.h"#include "connectioncontainer.h"#include "objectsafety.h"#include "vlccontrol.h"#include "vlccontrol2.h"#include "viewobject.h"#include "dataobject.h"#include "supporterrorinfo.h"#include "utils.h"#include <string.h>#include <winreg.h>#include <winuser.h>#include <servprov.h>#include <shlwapi.h>#include <wininet.h>using namespace std;//////////////////////////////////////////////////////////////////////////class factorystatic LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA)); switch( uMsg ) { case WM_ERASEBKGND: return 1L; case WM_PAINT: PAINTSTRUCT ps; RECT pr; if( GetUpdateRect(hWnd, &pr, FALSE) ) { RECT bounds; GetClientRect(hWnd, &bounds); BeginPaint(hWnd, &ps); p_instance->onPaint(ps.hdc, bounds, pr); EndPaint(hWnd, &ps); } return 0L; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); }};VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) : _p_class_ref(p_class_ref), _hinstance(hInstance), _classid(rclsid), _inplace_picture(NULL){ WNDCLASS wClass; if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) ) { wClass.style = CS_NOCLOSE|CS_DBLCLKS; wClass.lpfnWndProc = VLCInPlaceClassWndProc; wClass.cbClsExtra = 0; wClass.cbWndExtra = 0; wClass.hInstance = hInstance; wClass.hIcon = NULL; wClass.hCursor = LoadCursor(NULL, IDC_ARROW); wClass.hbrBackground = NULL; wClass.lpszMenuName = NULL; wClass.lpszClassName = getInPlaceWndClassName(); _inplace_wndclass_atom = RegisterClass(&wClass); } else { _inplace_wndclass_atom = 0; } HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), MAKEINTRESOURCE(2), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); if( NULL != hbitmap ) { PICTDESC pictDesc; pictDesc.cbSizeofstruct = sizeof(PICTDESC); pictDesc.picType = PICTYPE_BITMAP; pictDesc.bmp.hbitmap = hbitmap; pictDesc.bmp.hpal = NULL; if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) ) _inplace_picture = NULL; } AddRef();};VLCPluginClass::~VLCPluginClass(){ if( 0 != _inplace_wndclass_atom ) UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance); if( NULL != _inplace_picture ) _inplace_picture->Release();};STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv){ if( NULL == ppv ) return E_INVALIDARG; if( (IID_IUnknown == riid) || (IID_IClassFactory == riid) ) { AddRef(); *ppv = reinterpret_cast<LPVOID>(this); return NOERROR; } *ppv = NULL; return E_NOINTERFACE;};STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void){ return InterlockedIncrement(_p_class_ref);};STDMETHODIMP_(ULONG) VLCPluginClass::Release(void){ ULONG refcount = InterlockedDecrement(_p_class_ref); if( 0 == refcount ) { delete this; return 0; } return refcount;};STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv){ if( NULL == ppv ) return E_POINTER; *ppv = NULL; if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) { return CLASS_E_NOAGGREGATION; } VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter); if( NULL != plugin ) { HRESULT hr = plugin->QueryInterface(riid, ppv); // the following will destroy the object if QueryInterface() failed plugin->Release(); return hr; } return E_OUTOFMEMORY;};STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock){ if( fLock ) AddRef(); else Release(); return S_OK;};////////////////////////////////////////////////////////////////////////VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) : _inplacewnd(NULL), _p_class(p_class), _i_ref(1UL), _p_libvlc(NULL), _i_codepage(CP_ACP), _b_usermode(TRUE){ p_class->AddRef(); vlcOleControl = new VLCOleControl(this); vlcOleInPlaceObject = new VLCOleInPlaceObject(this); vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this); vlcPersistStorage = new VLCPersistStorage(this); vlcPersistStreamInit = new VLCPersistStreamInit(this); vlcPersistPropertyBag = new VLCPersistPropertyBag(this); vlcProvideClassInfo = new VLCProvideClassInfo(this); vlcConnectionPointContainer = new VLCConnectionPointContainer(this); vlcObjectSafety = new VLCObjectSafety(this); vlcControl = new VLCControl(this); vlcControl2 = new VLCControl2(this); vlcViewObject = new VLCViewObject(this); vlcDataObject = new VLCDataObject(this); vlcOleObject = new VLCOleObject(this); vlcSupportErrorInfo = new VLCSupportErrorInfo(this); // configure controlling IUnknown interface for implemented interfaces this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this); // default picure _p_pict = p_class->getInPlacePict(); // make sure that persistable properties are initialized onInit();};VLCPlugin::~VLCPlugin(){ /* ** bump refcount to avoid recursive release from ** following interfaces when releasing this interface */ AddRef(); delete vlcSupportErrorInfo; delete vlcOleObject; delete vlcDataObject; delete vlcViewObject; delete vlcControl2; delete vlcControl; delete vlcConnectionPointContainer; delete vlcProvideClassInfo; delete vlcPersistPropertyBag; delete vlcPersistStreamInit; delete vlcPersistStorage; delete vlcOleInPlaceActiveObject; delete vlcOleInPlaceObject; delete vlcObjectSafety; delete vlcOleControl; if( _p_pict ) _p_pict->Release(); SysFreeString(_bstr_mrl); SysFreeString(_bstr_baseurl); _p_class->Release();};STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv){ if( NULL == ppv ) return E_INVALIDARG; if( IID_IUnknown == riid ) *ppv = reinterpret_cast<LPVOID>(this); else if( IID_IOleObject == riid ) *ppv = reinterpret_cast<LPVOID>(vlcOleObject); else if( IID_IOleControl == riid ) *ppv = reinterpret_cast<LPVOID>(vlcOleControl); else if( IID_IOleWindow == riid ) *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject); else if( IID_IOleInPlaceObject == riid ) *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject); else if( IID_IOleInPlaceActiveObject == riid ) *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject); else if( IID_IPersist == riid ) *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit); else if( IID_IPersistStreamInit == riid ) *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit); else if( IID_IPersistStorage == riid ) *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage); else if( IID_IPersistPropertyBag == riid ) *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag); else if( IID_IProvideClassInfo == riid ) *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo); else if( IID_IProvideClassInfo2 == riid ) *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo); else if( IID_IConnectionPointContainer == riid ) *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer); else if( IID_IObjectSafety == riid ) *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety); else if( IID_IDispatch == riid ) *ppv = (CLSID_VLCPlugin2 == getClassID()) ? reinterpret_cast<LPVOID>(vlcControl2) : reinterpret_cast<LPVOID>(vlcControl); else if( IID_IVLCControl == riid ) *ppv = reinterpret_cast<LPVOID>(vlcControl); else if( IID_IVLCControl2 == riid ) *ppv = reinterpret_cast<LPVOID>(vlcControl2); else if( IID_IViewObject == riid ) *ppv = reinterpret_cast<LPVOID>(vlcViewObject); else if( IID_IViewObject2 == riid ) *ppv = reinterpret_cast<LPVOID>(vlcViewObject); else if( IID_IDataObject == riid ) *ppv = reinterpret_cast<LPVOID>(vlcDataObject); else if( IID_ISupportErrorInfo == riid ) *ppv = reinterpret_cast<LPVOID>(vlcSupportErrorInfo); else { *ppv = NULL; return E_NOINTERFACE; } ((LPUNKNOWN)*ppv)->AddRef(); return NOERROR;};STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void){ return InterlockedIncrement((LONG *)&_i_ref);};STDMETHODIMP_(ULONG) VLCPlugin::Release(void){ if( ! InterlockedDecrement((LONG *)&_i_ref) ) { delete this; return 0; } return _i_ref;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -