]> git.sesse.net Git - vlc/blob - activex/main.cpp
954b7611707ef8c2627cb2eab83839c27b27bc9a
[vlc] / activex / main.cpp
1 /*****************************************************************************\r
2  * main.cpp: ActiveX control for VLC\r
3  *****************************************************************************\r
4  * Copyright (C) 2005 VideoLAN\r
5  *\r
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
21  *****************************************************************************/\r
22 \r
23 #include "plugin.h"\r
24 \r
25 #include <comcat.h>\r
26 \r
27 using namespace std;\r
28 \r
29 static LONG i_class_ref= 0;\r
30 static HINSTANCE h_instance= 0;\r
31 \r
32 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)\r
33 {\r
34     HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;\r
35 \r
36     *ppv = NULL;\r
37 \r
38     if( CLSID_VLCPlugin == rclsid )\r
39     {\r
40         VLCPluginClass *plugin = new VLCPluginClass(&i_class_ref, h_instance);\r
41         hr = plugin->QueryInterface(riid, ppv);\r
42         plugin->Release();\r
43     }\r
44     return hr;\r
45 };\r
46 \r
47 STDAPI DllCanUnloadNow(VOID)\r
48 {\r
49     return (0 == i_class_ref) ? S_OK: S_FALSE;\r
50 };\r
51 \r
52 STDAPI DllRegisterServer(VOID)\r
53 {\r
54     return S_OK;\r
55 };\r
56 \r
57 STDAPI DllUnregisterServer(VOID)\r
58 {\r
59     return S_OK;\r
60 };\r
61 \r
62 #ifdef BUILD_LOCALSERVER\r
63 \r
64 /*\r
65 ** easier to debug an application than a DLL on cygwin GDB :)\r
66 */\r
67 \r
68 #include <iostream>\r
69 \r
70 STDAPI_(int) WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)\r
71 {\r
72     MSG msg;\r
73 \r
74     if( FAILED(OleInitialize(NULL)) )\r
75     {\r
76         cerr << "cannot initialize OLE" << endl;\r
77         return 1;\r
78     }\r
79 \r
80     IUnknown *classProc = NULL;\r
81 \r
82     if( FAILED(DllGetClassObject(CLSID_VLCPlugin, IID_IUnknown, (LPVOID *)&classProc)) )\r
83         return 0;\r
84  \r
85     DWORD dwRegisterClassObject;\r
86 \r
87     if( FAILED(CoRegisterClassObject(CLSID_VLCPlugin, classProc,\r
88         CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwRegisterClassObject)) )\r
89         return 0;\r
90 \r
91     DWORD dwRegisterActiveObject;\r
92 \r
93     if( FAILED(RegisterActiveObject(classProc, CLSID_VLCPlugin,\r
94                     ACTIVEOBJECT_WEAK, &dwRegisterActiveObject)) )\r
95         return 0;\r
96 \r
97     classProc->Release();\r
98 \r
99     /*\r
100     * Polling messages from event queue\r
101     */\r
102     while( S_FALSE == DllCanUnloadNow() )\r
103     {\r
104         while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )\r
105         {\r
106             if( msg.message == WM_QUIT )\r
107                 break;  // Leave the PeekMessage while() loop\r
108 \r
109             /*if(TranslateAccelerator(ghwndApp, ghAccel, &msg))\r
110                 continue;*/\r
111 \r
112             TranslateMessage(&msg);\r
113             DispatchMessage(&msg);\r
114         }\r
115 \r
116         if(msg.message == WM_QUIT)\r
117             break;  // Leave the for() loop\r
118 \r
119         WaitMessage();\r
120     }\r
121 \r
122     if( SUCCEEDED(RevokeActiveObject(dwRegisterActiveObject, NULL)) )\r
123         CoRevokeClassObject(dwRegisterClassObject);\r
124 \r
125     // Reached on WM_QUIT message\r
126     CoUninitialize();\r
127     return ((int) msg.wParam);\r
128 };\r
129 \r
130 #else\r
131 \r
132 STDAPI_(BOOL) DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )\r
133 {\r
134     switch( fdwReason )\r
135     {\r
136         case DLL_PROCESS_ATTACH:\r
137             h_instance = (HINSTANCE)hModule;\r
138             break;\r
139 \r
140         default:\r
141             break;\r
142     }\r
143     return TRUE;\r
144 };\r
145 \r
146 #endif\r
147 \r