ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.c
Go to the documentation of this file.
00001 /*
00002  *    MSHTML Class Factory
00003  *
00004  * Copyright 2002 Lionel Ulmer
00005  * Copyright 2003 Mike McCormack
00006  * Copyright 2005 Jacek Caban
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00021  */
00022 
00023 #include <stdarg.h>
00024 #include <stdio.h>
00025 
00026 #define COBJMACROS
00027 
00028 #include "windef.h"
00029 #include "winbase.h"
00030 #include "winuser.h"
00031 #include "winreg.h"
00032 #include "ole2.h"
00033 #include "advpub.h"
00034 #include "shlwapi.h"
00035 #include "optary.h"
00036 #include "shlguid.h"
00037 
00038 #include "wine/unicode.h"
00039 #include "wine/debug.h"
00040 
00041 #define INIT_GUID
00042 #include "mshtml_private.h"
00043 
00044 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
00045 
00046 HINSTANCE hInst;
00047 DWORD mshtml_tls = TLS_OUT_OF_INDEXES;
00048 
00049 static HINSTANCE shdoclc = NULL;
00050 static HDC display_dc;
00051 
00052 static void thread_detach(void)
00053 {
00054     thread_data_t *thread_data;
00055 
00056     thread_data = get_thread_data(FALSE);
00057     if(!thread_data)
00058         return;
00059 
00060     if(thread_data->thread_hwnd)
00061         DestroyWindow(thread_data->thread_hwnd);
00062 
00063     heap_free(thread_data);
00064 }
00065 
00066 static void process_detach(void)
00067 {
00068     close_gecko();
00069     release_typelib();
00070 
00071     if(shdoclc)
00072         FreeLibrary(shdoclc);
00073     if(mshtml_tls != TLS_OUT_OF_INDEXES)
00074         TlsFree(mshtml_tls);
00075     if(display_dc)
00076         DeleteObject(display_dc);
00077 }
00078 
00079 HINSTANCE get_shdoclc(void)
00080 {
00081     static const WCHAR wszShdoclc[] =
00082         {'s','h','d','o','c','l','c','.','d','l','l',0};
00083 
00084     if(shdoclc)
00085         return shdoclc;
00086 
00087     return shdoclc = LoadLibraryExW(wszShdoclc, NULL, LOAD_LIBRARY_AS_DATAFILE);
00088 }
00089 
00090 HDC get_display_dc(void)
00091 {
00092     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
00093 
00094     if(!display_dc) {
00095         HDC hdc;
00096 
00097         hdc = CreateICW(displayW, NULL, NULL, NULL);
00098         if(InterlockedCompareExchangePointer((void**)&display_dc, hdc, NULL))
00099             DeleteObject(hdc);
00100     }
00101 
00102     return display_dc;
00103 }
00104 
00105 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
00106 {
00107     switch(fdwReason) {
00108     case DLL_PROCESS_ATTACH:
00109         hInst = hInstDLL;
00110         break;
00111     case DLL_PROCESS_DETACH:
00112         process_detach();
00113         break;
00114     case DLL_THREAD_DETACH:
00115         thread_detach();
00116         break;
00117     }
00118     return TRUE;
00119 }
00120 
00121 /***********************************************************
00122  *    ClassFactory implementation
00123  */
00124 typedef HRESULT (*CreateInstanceFunc)(IUnknown*,REFIID,void**);
00125 typedef struct {
00126     const IClassFactoryVtbl *lpVtbl;
00127     LONG ref;
00128     CreateInstanceFunc fnCreateInstance;
00129 } ClassFactory;
00130 
00131 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFGUID riid, void **ppvObject)
00132 {
00133     if(IsEqualGUID(&IID_IClassFactory, riid) || IsEqualGUID(&IID_IUnknown, riid)) {
00134         IClassFactory_AddRef(iface);
00135         *ppvObject = iface;
00136         return S_OK;
00137     }
00138 
00139     WARN("not supported iid %s\n", debugstr_guid(riid));
00140     *ppvObject = NULL;
00141     return E_NOINTERFACE;
00142 }
00143 
00144 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
00145 {
00146     ClassFactory *This = (ClassFactory*)iface;
00147     ULONG ref = InterlockedIncrement(&This->ref);
00148     TRACE("(%p) ref = %u\n", This, ref);
00149     return ref;
00150 }
00151 
00152 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
00153 {
00154     ClassFactory *This = (ClassFactory*)iface;
00155     ULONG ref = InterlockedDecrement(&This->ref);
00156 
00157     TRACE("(%p) ref = %u\n", This, ref);
00158 
00159     if(!ref) {
00160         heap_free(This);
00161     }
00162 
00163     return ref;
00164 }
00165 
00166 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
00167         REFIID riid, void **ppvObject)
00168 {
00169     ClassFactory *This = (ClassFactory*)iface;
00170     return This->fnCreateInstance(pUnkOuter, riid, ppvObject);
00171 }
00172 
00173 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
00174 {
00175     TRACE("(%p)->(%x)\n", iface, dolock);
00176 
00177     /* We never unload the DLL. See DllCanUnloadNow(). */
00178     return S_OK;
00179 }
00180 
00181 static const IClassFactoryVtbl HTMLClassFactoryVtbl = {
00182     ClassFactory_QueryInterface,
00183     ClassFactory_AddRef,
00184     ClassFactory_Release,
00185     ClassFactory_CreateInstance,
00186     ClassFactory_LockServer
00187 };
00188 
00189 static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc fnCreateInstance)
00190 {
00191     ClassFactory *ret = heap_alloc(sizeof(ClassFactory));
00192     HRESULT hres;
00193 
00194     ret->lpVtbl = &HTMLClassFactoryVtbl;
00195     ret->ref = 0;
00196     ret->fnCreateInstance = fnCreateInstance;
00197 
00198     hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
00199     if(FAILED(hres)) {
00200         heap_free(ret);
00201         *ppv = NULL;
00202     }
00203     return hres;
00204 }
00205 
00206 /******************************************************************
00207  *      DllGetClassObject (MSHTML.@)
00208  */
00209 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
00210 {
00211     if(IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
00212         TRACE("(CLSID_HTMLDocument %s %p)\n", debugstr_guid(riid), ppv);
00213         return ClassFactory_Create(riid, ppv, HTMLDocument_Create);
00214     }else if(IsEqualGUID(&CLSID_AboutProtocol, rclsid)) {
00215         TRACE("(CLSID_AboutProtocol %s %p)\n", debugstr_guid(riid), ppv);
00216         return ProtocolFactory_Create(rclsid, riid, ppv);
00217     }else if(IsEqualGUID(&CLSID_JSProtocol, rclsid)) {
00218         TRACE("(CLSID_JSProtocol %s %p)\n", debugstr_guid(riid), ppv);
00219         return ProtocolFactory_Create(rclsid, riid, ppv);
00220     }else if(IsEqualGUID(&CLSID_MailtoProtocol, rclsid)) {
00221         TRACE("(CLSID_MailtoProtocol %s %p)\n", debugstr_guid(riid), ppv);
00222         return ProtocolFactory_Create(rclsid, riid, ppv);
00223     }else if(IsEqualGUID(&CLSID_ResProtocol, rclsid)) {
00224         TRACE("(CLSID_ResProtocol %s %p)\n", debugstr_guid(riid), ppv);
00225         return ProtocolFactory_Create(rclsid, riid, ppv);
00226     }else if(IsEqualGUID(&CLSID_SysimageProtocol, rclsid)) {
00227         TRACE("(CLSID_SysimageProtocol %s %p)\n", debugstr_guid(riid), ppv);
00228         return ProtocolFactory_Create(rclsid, riid, ppv);
00229     }else if(IsEqualGUID(&CLSID_HTMLLoadOptions, rclsid)) {
00230         TRACE("(CLSID_HTMLLoadOptions %s %p)\n", debugstr_guid(riid), ppv);
00231         return ClassFactory_Create(riid, ppv, HTMLLoadOptions_Create);
00232     }
00233 
00234     FIXME("Unknown class %s\n", debugstr_guid(rclsid));
00235     return CLASS_E_CLASSNOTAVAILABLE;
00236 }
00237 
00238 /******************************************************************
00239  *              DllCanUnloadNow (MSHTML.@)
00240  */
00241 HRESULT WINAPI DllCanUnloadNow(void)
00242 {
00243     TRACE("()\n");
00244     /* The cost of keeping this DLL in memory is small. */
00245     return S_FALSE;
00246 }
00247 
00248 /***********************************************************************
00249  *          RunHTMLApplication (MSHTML.@)
00250  *
00251  * Appears to have the same prototype as WinMain.
00252  */
00253 HRESULT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
00254                                LPSTR szCmdLine, INT nCmdShow )
00255 {
00256     FIXME("%p %p %s %d\n", hinst, hPrevInst, debugstr_a(szCmdLine), nCmdShow );
00257     return 0;
00258 }
00259 
00260 /***********************************************************************
00261  *          RNIGetCompatibleVersion (MSHTML.@)
00262  */
00263 DWORD WINAPI RNIGetCompatibleVersion(void)
00264 {
00265     TRACE("()\n");
00266     return 0x20000;
00267 }
00268 
00269 /***********************************************************************
00270  *          DllInstall (MSHTML.@)
00271  */
00272 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
00273 {
00274     FIXME("stub %d %s: returning S_OK\n", bInstall, debugstr_w(cmdline));
00275     return S_OK;
00276 }
00277 
00278 /***********************************************************************
00279  *          ShowHTMLDialog (MSHTML.@)
00280  */
00281 HRESULT WINAPI ShowHTMLDialog(HWND hwndParent, IMoniker *pMk, VARIANT *pvarArgIn,
00282         WCHAR *pchOptions, VARIANT *pvarArgOut)
00283 {
00284     FIXME("(%p %p %p %s %p)\n", hwndParent, pMk, pvarArgIn, debugstr_w(pchOptions), pvarArgOut);
00285     return E_NOTIMPL;
00286 }
00287 
00288 DEFINE_GUID(CLSID_CBackgroundPropertyPage, 0x3050F232, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00289 DEFINE_GUID(CLSID_CCDAnchorPropertyPage, 0x3050F1FC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00290 DEFINE_GUID(CLSID_CCDGenericPropertyPage, 0x3050F17F, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00291 DEFINE_GUID(CLSID_CDwnBindInfo, 0x3050F3C2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00292 DEFINE_GUID(CLSID_CHiFiUses, 0x5AAF51B3, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
00293 DEFINE_GUID(CLSID_CHtmlComponentConstructor, 0x3050F4F8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00294 DEFINE_GUID(CLSID_CInlineStylePropertyPage, 0x3050F296, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00295 DEFINE_GUID(CLSID_CPeerHandler, 0x5AAF51B2, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
00296 DEFINE_GUID(CLSID_CRecalcEngine, 0x3050F499, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00297 DEFINE_GUID(CLSID_CSvrOMUses, 0x3050F4F0, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00298 DEFINE_GUID(CLSID_CrSource, 0x65014010, 0x9F62, 0x11D1, 0xA6,0x51, 0x00,0x60,0x08,0x11,0xD5,0xCE);
00299 DEFINE_GUID(CLSID_ExternalFrameworkSite, 0x3050F163, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00300 DEFINE_GUID(CLSID_HTADocument, 0x3050F5C8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00301 DEFINE_GUID(CLSID_HTMLPluginDocument, 0x25336921, 0x03F9, 0x11CF, 0x8F,0xD0, 0x00,0xAA,0x00,0x68,0x6F,0x13);
00302 DEFINE_GUID(CLSID_HTMLPopup, 0x3050F667, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00303 DEFINE_GUID(CLSID_HTMLPopupDoc, 0x3050F67D, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00304 DEFINE_GUID(CLSID_HTMLServerDoc, 0x3050F4E7, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00305 DEFINE_GUID(CLSID_IImageDecodeFilter, 0x607FD4E8, 0x0A03, 0x11D1, 0xAB,0x1D, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
00306 DEFINE_GUID(CLSID_IImgCtx, 0x3050F3D6, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00307 DEFINE_GUID(CLSID_IntDitherer, 0x05F6FE1A, 0xECEF, 0x11D0, 0xAA,0xE7, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
00308 DEFINE_GUID(CLSID_MHTMLDocument, 0x3050F3D9, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
00309 DEFINE_GUID(CLSID_Scriptlet, 0xAE24FDAE, 0x03C6, 0x11D1, 0x8B,0x76, 0x00,0x80,0xC7,0x44,0xF3,0x89);
00310 DEFINE_GUID(CLSID_TridentAPI, 0x429AF92C, 0xA51F, 0x11D2, 0x86,0x1E, 0x00,0xC0,0x4F,0xA3,0x5C,0x89);
00311 
00312 #define INF_SET_ID(id)            \
00313     do                            \
00314     {                             \
00315         static CHAR name[] = #id; \
00316                                   \
00317         pse[i].pszName = name;    \
00318         clsids[i++] = &id;        \
00319     } while (0)
00320 
00321 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
00322 
00323 static HRESULT register_server(BOOL do_register)
00324 {
00325     HRESULT hres;
00326     HMODULE hAdvpack;
00327     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
00328     STRTABLEA strtable;
00329     STRENTRYA pse[35];
00330     static CLSID const *clsids[35];
00331     unsigned int i = 0;
00332 
00333     static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
00334 
00335     TRACE("(%x)\n", do_register);
00336 
00337     INF_SET_CLSID(AboutProtocol);
00338     INF_SET_CLSID(CAnchorBrowsePropertyPage);
00339     INF_SET_CLSID(CBackgroundPropertyPage);
00340     INF_SET_CLSID(CCDAnchorPropertyPage);
00341     INF_SET_CLSID(CCDGenericPropertyPage);
00342     INF_SET_CLSID(CDocBrowsePropertyPage);
00343     INF_SET_CLSID(CDwnBindInfo);
00344     INF_SET_CLSID(CHiFiUses);
00345     INF_SET_CLSID(CHtmlComponentConstructor);
00346     INF_SET_CLSID(CImageBrowsePropertyPage);
00347     INF_SET_CLSID(CInlineStylePropertyPage);
00348     INF_SET_CLSID(CPeerHandler);
00349     INF_SET_CLSID(CRecalcEngine);
00350     INF_SET_CLSID(CSvrOMUses);
00351     INF_SET_CLSID(CrSource);
00352     INF_SET_CLSID(ExternalFrameworkSite);
00353     INF_SET_CLSID(HTADocument);
00354     INF_SET_CLSID(HTMLDocument);
00355     INF_SET_CLSID(HTMLLoadOptions);
00356     INF_SET_CLSID(HTMLPluginDocument);
00357     INF_SET_CLSID(HTMLPopup);
00358     INF_SET_CLSID(HTMLPopupDoc);
00359     INF_SET_CLSID(HTMLServerDoc);
00360     INF_SET_CLSID(HTMLWindowProxy);
00361     INF_SET_CLSID(IImageDecodeFilter);
00362     INF_SET_CLSID(IImgCtx);
00363     INF_SET_CLSID(IntDitherer);
00364     INF_SET_CLSID(JSProtocol);
00365     INF_SET_CLSID(MHTMLDocument);
00366     INF_SET_CLSID(MailtoProtocol);
00367     INF_SET_CLSID(ResProtocol);
00368     INF_SET_CLSID(Scriptlet);
00369     INF_SET_CLSID(SysimageProtocol);
00370     INF_SET_CLSID(TridentAPI);
00371     INF_SET_ID(LIBID_MSHTML);
00372 
00373     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) {
00374         pse[i].pszValue = heap_alloc(39);
00375         sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
00376                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
00377                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
00378                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
00379     }
00380 
00381     strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
00382     strtable.pse = pse;
00383 
00384     hAdvpack = LoadLibraryW(wszAdvpack);
00385     pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
00386 
00387     hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
00388 
00389     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
00390         heap_free(pse[i].pszValue);
00391 
00392     if(FAILED(hres)) {
00393         ERR("RegInstall failed: %08x\n", hres);
00394         return hres;
00395     }
00396 
00397     if(do_register) {
00398         ITypeLib *typelib;
00399 
00400         static const WCHAR wszMSHTML[] = {'m','s','h','t','m','l','.','t','l','b',0};
00401 
00402         hres = LoadTypeLibEx(wszMSHTML, REGKIND_REGISTER, &typelib);
00403         if(SUCCEEDED(hres))
00404             ITypeLib_Release(typelib);
00405     }else {
00406         hres = UnRegisterTypeLib(&LIBID_MSHTML, 4, 0, LOCALE_SYSTEM_DEFAULT, SYS_WIN32);
00407     }
00408 
00409     if(FAILED(hres))
00410         ERR("typelib registration failed: %08x\n", hres);
00411 
00412     return hres;
00413 }
00414 
00415 #undef INF_SET_CLSID
00416 #undef INF_SET_ID
00417 
00418 /***********************************************************************
00419  *          DllRegisterServer (MSHTML.@)
00420  */
00421 HRESULT WINAPI DllRegisterServer(void)
00422 {
00423     HRESULT hres;
00424 
00425     hres = register_server(TRUE);
00426     if(SUCCEEDED(hres))
00427         load_gecko(FALSE);
00428 
00429     return hres;
00430 }
00431 
00432 /***********************************************************************
00433  *          DllUnregisterServer (MSHTML.@)
00434  */
00435 HRESULT WINAPI DllUnregisterServer(void)
00436 {
00437     return register_server(FALSE);
00438 }
00439 
00440 const char *debugstr_variant(const VARIANT *v)
00441 {
00442     if(!v)
00443         return "(null)";
00444 
00445     switch(V_VT(v)) {
00446     case VT_EMPTY:
00447         return "{VT_EMPTY}";
00448     case VT_NULL:
00449         return "{VT_NULL}";
00450     case VT_I4:
00451         return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
00452     case VT_R8:
00453         return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
00454     case VT_BSTR:
00455         return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
00456     case VT_DISPATCH:
00457         return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
00458     case VT_BOOL:
00459         return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
00460     case VT_UINT:
00461         return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v));
00462     default:
00463         return wine_dbg_sprintf("{vt %d}", V_VT(v));
00464     }
00465 }

Generated on Sat May 26 2012 04:15:44 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.