mshtml: Added createElement test.
[wine] / dlls / mshtml / main.c
index 052f703..1c52c5a 100644 (file)
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "config.h"
-
 #include <stdarg.h>
 #include <stdio.h>
 
 #include "windef.h"
 #include "winbase.h"
 #include "winuser.h"
-#include "winnls.h"
 #include "winreg.h"
 #include "ole2.h"
-#include "docobj.h"
 #include "advpub.h"
-
-#include "mshtml.h"
-#include "mshtmhst.h"
+#include "shlwapi.h"
+#include "optary.h"
+#include "shlguid.h"
 
 #include "wine/unicode.h"
 #include "wine/debug.h"
 
-#include "initguid.h"
+#define INIT_GUID
 #include "mshtml_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
 HINSTANCE hInst;
 LONG module_ref = 0;
+DWORD mshtml_tls = 0;
+
+static HINSTANCE shdoclc = NULL;
+
+static void thread_detach(void)
+{
+    thread_data_t *thread_data;
+
+    thread_data = get_thread_data(FALSE);
+    if(!thread_data)
+        return;
+
+    if(thread_data->thread_hwnd)
+        DestroyWindow(thread_data->thread_hwnd);
+
+    heap_free(thread_data);
+}
+
+static void process_detach(void)
+{
+    close_gecko();
+    release_typelib();
+
+    if(shdoclc)
+        FreeLibrary(shdoclc);
+    if(mshtml_tls)
+        TlsFree(mshtml_tls);
+}
+
+HINSTANCE get_shdoclc(void)
+{
+    static const WCHAR wszShdoclc[] =
+        {'s','h','d','o','c','l','c','.','d','l','l',0};
+
+    if(shdoclc)
+        return shdoclc;
+
+    return shdoclc = LoadLibraryExW(wszShdoclc, NULL, LOAD_LIBRARY_AS_DATAFILE);
+}
 
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
     switch(fdwReason) {
-        case DLL_PROCESS_ATTACH:
-            hInst = hInstDLL;
-           break;
-       case DLL_PROCESS_DETACH:
-            close_gecko();
-           break;
+    case DLL_PROCESS_ATTACH:
+        hInst = hInstDLL;
+        break;
+    case DLL_PROCESS_DETACH:
+        process_detach();
+        break;
+    case DLL_THREAD_DETACH:
+        thread_detach();
+        break;
     }
     return TRUE;
 }
@@ -90,7 +128,7 @@ static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
 {
     ClassFactory *This = (ClassFactory*)iface;
     ULONG ref = InterlockedIncrement(&This->ref);
-    TRACE("(%p) ref = %lu\n", This, ref);
+    TRACE("(%p) ref = %u\n", This, ref);
     return ref;
 }
 
@@ -99,10 +137,10 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
     ClassFactory *This = (ClassFactory*)iface;
     ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p) ref = %lu\n", This, ref);
+    TRACE("(%p) ref = %u\n", This, ref);
 
     if(!ref) {
-        HeapFree(GetProcessHeap(), 0, This);
+        heap_free(This);
         UNLOCK_MODULE();
     }
 
@@ -138,7 +176,7 @@ static const IClassFactoryVtbl HTMLClassFactoryVtbl = {
 
 static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc fnCreateInstance)
 {
-    ClassFactory *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory));
+    ClassFactory *ret = heap_alloc(sizeof(ClassFactory));
     HRESULT hres;
 
     ret->lpVtbl = &HTMLClassFactoryVtbl;
@@ -149,13 +187,16 @@ static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc f
     if(SUCCEEDED(hres)) {
         LOCK_MODULE();
     }else {
-        HeapFree(GetProcessHeap(), 0, ret);
+        heap_free(ret);
         *ppv = NULL;
     }
     return hres;
 }
 
-HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
+/******************************************************************
+ *             DllGetClassObject (MSHTML.@)
+ */
+HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
 {
     if(IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
         TRACE("(CLSID_HTMLDocument %s %p)\n", debugstr_guid(riid), ppv);
@@ -175,15 +216,21 @@ HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *pp
     }else if(IsEqualGUID(&CLSID_SysimageProtocol, rclsid)) {
         TRACE("(CLSID_SysimageProtocol %s %p)\n", debugstr_guid(riid), ppv);
         return ProtocolFactory_Create(rclsid, riid, ppv);
+    }else if(IsEqualGUID(&CLSID_HTMLLoadOptions, rclsid)) {
+        TRACE("(CLSID_HTMLLoadOptions %s %p)\n", debugstr_guid(riid), ppv);
+        return ClassFactory_Create(riid, ppv, HTMLLoadOptions_Create);
     }
 
     FIXME("Unknown class %s\n", debugstr_guid(rclsid));
     return CLASS_E_CLASSNOTAVAILABLE;
 }
 
-HRESULT WINAPI MSHTML_DllCanUnloadNow(void)
+/******************************************************************
+ *              DllCanUnloadNow (MSHTML.@)
+ */
+HRESULT WINAPI DllCanUnloadNow(void)
 {
-    TRACE("() ref=%ld\n", module_ref);
+    TRACE("() ref=%d\n", module_ref);
     return module_ref ? S_FALSE : S_OK;
 }
 
@@ -199,24 +246,40 @@ HRESULT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
     return 0;
 }
 
+/***********************************************************************
+ *          RNIGetCompatibleVersion (MSHTML.@)
+ */
+DWORD WINAPI RNIGetCompatibleVersion(void)
+{
+    TRACE("()\n");
+    return 0x20000;
+}
+
 /***********************************************************************
  *          DllInstall (MSHTML.@)
  */
-HRESULT WINAPI MSHTML_DllInstall(BOOL bInstall, LPCWSTR cmdline)
+HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
 {
     FIXME("stub %d %s: returning S_OK\n", bInstall, debugstr_w(cmdline));
     return S_OK;
 }
 
-DEFINE_GUID(CLSID_CAnchorBrowsePropertyPage, 0x3050F3BB, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
+/***********************************************************************
+ *          ShowHTMLDialog (MSHTML.@)
+ */
+HRESULT WINAPI ShowHTMLDialog(HWND hwndParent, IMoniker *pMk, VARIANT *pvarArgIn,
+        WCHAR *pchOptions, VARIANT *pvarArgOut)
+{
+    FIXME("(%p %p %p %s %p)\n", hwndParent, pMk, pvarArgIn, debugstr_w(pchOptions), pvarArgOut);
+    return E_NOTIMPL;
+}
+
 DEFINE_GUID(CLSID_CBackgroundPropertyPage, 0x3050F232, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CCDAnchorPropertyPage, 0x3050F1FC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CCDGenericPropertyPage, 0x3050F17F, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
-DEFINE_GUID(CLSID_CDocBrowsePropertyPage, 0x3050F3B4, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CDwnBindInfo, 0x3050F3C2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CHiFiUses, 0x5AAF51B3, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
 DEFINE_GUID(CLSID_CHtmlComponentConstructor, 0x3050F4F8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
-DEFINE_GUID(CLSID_CImageBrowsePropertyPage, 0x3050F3B3, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CInlineStylePropertyPage, 0x3050F296, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_CPeerHandler, 0x5AAF51B2, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
 DEFINE_GUID(CLSID_CRecalcEngine, 0x3050F499, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
@@ -224,7 +287,6 @@ DEFINE_GUID(CLSID_CSvrOMUses, 0x3050F4F0, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0
 DEFINE_GUID(CLSID_CrSource, 0x65014010, 0x9F62, 0x11D1, 0xA6,0x51, 0x00,0x60,0x08,0x11,0xD5,0xCE);
 DEFINE_GUID(CLSID_ExternalFrameworkSite, 0x3050F163, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_HTADocument, 0x3050F5C8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
-DEFINE_GUID(CLSID_HTMLLoadOptions, 0x18845040, 0x0FA5, 0x11D1, 0xBA,0x19, 0x00,0xC0,0x4F,0xD9,0x12,0xD0);
 DEFINE_GUID(CLSID_HTMLPluginDocument, 0x25336921, 0x03F9, 0x11CF, 0x8F,0xD0, 0x00,0xAA,0x00,0x68,0x6F,0x13);
 DEFINE_GUID(CLSID_HTMLPopup, 0x3050F667, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_HTMLPopupDoc, 0x3050F67D, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
@@ -237,9 +299,14 @@ DEFINE_GUID(CLSID_MHTMLDocument, 0x3050F3D9, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xA
 DEFINE_GUID(CLSID_Scriptlet, 0xAE24FDAE, 0x03C6, 0x11D1, 0x8B,0x76, 0x00,0x80,0xC7,0x44,0xF3,0x89);
 DEFINE_GUID(CLSID_TridentAPI, 0x429AF92C, 0xA51F, 0x11D2, 0x86,0x1E, 0x00,0xC0,0x4F,0xA3,0x5C,0x89);
 
-#define INF_SET_ID(id) \
-    pse[i].pszName = #id; \
-    clsids[i++] = &id;
+#define INF_SET_ID(id)            \
+    do                            \
+    {                             \
+        static CHAR name[] = #id; \
+                                  \
+        pse[i].pszName = name;    \
+        clsids[i++] = &id;        \
+    } while (0)
 
 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
 
@@ -247,16 +314,16 @@ static HRESULT register_server(BOOL do_register)
 {
     HRESULT hres;
     HMODULE hAdvpack;
-    typeof(RegInstall) *pRegInstall;
-    STRTABLE strtable;
-    STRENTRY pse[35];
+    HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
+    STRTABLEA strtable;
+    STRENTRYA pse[35];
     static CLSID const *clsids[35];
     int i = 0;
-    
+
     static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
 
     TRACE("(%x)\n", do_register);
-    
+
     INF_SET_CLSID(AboutProtocol);
     INF_SET_CLSID(CAnchorBrowsePropertyPage);
     INF_SET_CLSID(CBackgroundPropertyPage);
@@ -294,8 +361,8 @@ static HRESULT register_server(BOOL do_register)
     INF_SET_ID(LIBID_MSHTML);
 
     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) {
-        pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
-        sprintf(pse[i].pszValue, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+        pse[i].pszValue = heap_alloc(39);
+        sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
@@ -305,22 +372,46 @@ static HRESULT register_server(BOOL do_register)
     strtable.pse = pse;
 
     hAdvpack = LoadLibraryW(wszAdvpack);
-    pRegInstall = (typeof(RegInstall)*)GetProcAddress(hAdvpack, "RegInstall");
+    pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
 
     hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
 
     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
-        HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
+        heap_free(pse[i].pszValue);
+
+    if(FAILED(hres)) {
+        ERR("RegInstall failed: %08x\n", hres);
+        return hres;
+    }
+
+    if(do_register) {
+        ITypeLib *typelib;
+
+        static const WCHAR wszMSHTML[] = {'m','s','h','t','m','l','.','t','l','b',0};
+
+        hres = LoadTypeLibEx(wszMSHTML, REGKIND_REGISTER, &typelib);
+        if(SUCCEEDED(hres))
+            ITypeLib_Release(typelib);
+    }else {
+        hres = UnRegisterTypeLib(&LIBID_MSHTML, 4, 0, LOCALE_SYSTEM_DEFAULT, SYS_WIN32);
+    }
+
+    if(FAILED(hres))
+        ERR("typelib registration failed: %08x\n", hres);
+
+    if(do_register && SUCCEEDED(hres))
+        load_gecko(TRUE);
 
     return hres;
 }
 
 #undef INF_SET_CLSID
+#undef INF_SET_ID
 
 /***********************************************************************
  *          DllRegisterServer (MSHTML.@)
  */
-HRESULT WINAPI MSHTML_DllRegisterServer(void)
+HRESULT WINAPI DllRegisterServer(void)
 {
     return register_server(TRUE);
 }
@@ -328,7 +419,7 @@ HRESULT WINAPI MSHTML_DllRegisterServer(void)
 /***********************************************************************
  *          DllUnregisterServer (MSHTML.@)
  */
-HRESULT WINAPI MSHTML_DllUnregisterServer(void)
+HRESULT WINAPI DllUnregisterServer(void)
 {
     return register_server(FALSE);
 }