In my standalone application written on gecko engine LoadURI function
of nsIWebNavigation interface returns NS_ERROR_OUT_OF_MEMORY error.

For assembling I use Visual Studio 7.1 and xulrunner 1.9 options of
its compiler. Enabled support of:

mfc,charaster set = Use Unicode Character Set,
Command line(C\C++):
/Od /I "C:\CL\cl4\\" /I "C:\CL\cl4\\XulRunner-sdk\include\xpcom" /I "C:
\CL\cl4\\XulRunner-sdk\include\string" /I "C:\CL\cl4\\XulRunner-sdk
\include\embed_base" /I "C:\CL\cl4\\XulRunner-sdk\include\webbrwsr" /I
"C:\CL\cl4\\XulRunner-sdk\include\webshell" /I "C:\CL\cl4\\XulRunner-
sdk\include\windowwatcher" /I "C:\CL\cl4\\XulRunner-sdk\include
\profile" /I "C:\CL\cl4\\XulRunner-sdk\include\necko" /I "C:\CL\cl4\
\XulRunner-sdk\include\docshell" /I "C:\CL\cl4\\XulRunner-sdk\include
\dom" /I "C:\CL\cl4\\XulRunner-sdk\include\widget" /I "C:\CL\cl4\
\XulRunner-sdk\include\uriloader" /I "C:\CL\cl4\\XulRunner-sdk\include
\shistory" /I "C:\CL\cl4\\XulRunner-sdk\include\webbrowserpersist" /I
"C:\CL\cl4\\XulRunner-sdk\include\profdirserviceprovider" /I "C:\CL
\cl4\\XulRunner-sdk\include\xulapp" /I "C:\CL\cl4\\XulRunner-sdk
\include\nspr" /I "C:\CL\cl4\\XulRunner-sdk\include" /D "WIN32" /D
"_WINDOWS" /D "_DEBUG" /D "_AFXEXT" /D "_EXPORTS" /D "XPCOM_GLUE" /D
"MOZ_DEBUG" /D "_WINDLL" /D "_AFXDLL" /D "_UNICODE" /D "UNICODE" /Gm /
EHsc /RTC1 /MDd /GR /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /
Wp64 /ZI /TP

Command line(Linker):
/OUT:"..\_Debug/WebBrowserPreview.dll" /INCREMENTAL /NOLOGO /
LIBPATH:"C:\CL\cl4\\xulrunner-sdk\lib" /LIBPATH:"C:\CL\cl4\\profile
\dirserviceprovider\standalone" /DLL /DEF:".\WebBrowserPreview.def" /
DEBUG /PDB:"..\_Debug/WebBrowserPreview.pdb" /SUBSYSTEM:WINDOWS /
IMPLIB:"..\_Debug/WebBrowserPreview.lib" /MACHINE:X86 string_s.lib
xpcomglue.lib nspr4.lib  profdirserviceprovidersa_s.lib "\Cl
\cl4\xulrunner-sdk\lib\string_s.lib" "\Cl\cl4\xulrunner-sdk\lib
\xpcomglue.lib" "\Cl\cl4\xulrunner-sdk\lib\nspr4.lib"



int InitGecko(CL::SDK::IApplication* pApp)
{
        //
        nsresult rv = 0;
        CL::SDK::IMainFrame* pIFrm = pApp->GetMainFrame();
        CFrameWnd* pFrm = dynamic_cast<CFrameWnd*>(pIFrm);
        m_hInstanceApp = GetModuleHandle(NULL);

        static const GREVersionRange vr = {
                "1.8a1",
                        PR_TRUE,
                        "2.0",
                        PR_FALSE
        };

        char* MozillaPath;
        MozillaPath = MOZILLA_DLLS_PATH;

        char xpcomDll[_MAX_PATH];

        _snprintf(xpcomDll, sizeof(xpcomDll), "%sxpcom.dll", MozillaPath);


        rv = XPCOMGlueStartup(xpcomDll);
        if (NS_FAILED(rv))
                return 3;
    //rv = NS_InitEmbedding(nsnull, nsnull);
        WCHAR *xulPath;
        char xulDll[_MAX_PATH];
        _snprintf(xulDll, sizeof(xulDll), "%sxul.dll", MozillaPath);
        CCommonString::ToWideString(xulDll,xulPath);
        HINSTANCE xulModule = LoadLibraryEx(xulPath, NULL, 0);
        if (!xulModule)
                return 4;


        WCHAR temp[_MAX_PATH];
        GetModuleFileName(xulModule, temp, sizeof(temp));

        XRE_InitEmbedding =
                (XRE_InitEmbeddingType) GetProcAddress(xulModule,
"XRE_InitEmbedding");
        if (!XRE_InitEmbedding)
        return 5;


        XRE_TermEmbedding =
                (XRE_TermEmbeddingType) GetProcAddress(xulModule,
"XRE_TermEmbedding");
        if (!XRE_TermEmbedding)
                return 5;

        nsCOMPtr<nsILocalFile> xuldir;
        rv = NS_NewNativeLocalFile(nsCString(xpcomDll), PR_FALSE,
                getter_AddRefs(xuldir));
        if (NS_FAILED(rv))
                return 6;

        WCHAR* self = new WCHAR[_MAX_PATH];
        GetModuleFileName(m_hInstanceApp, self, _MAX_PATH);


        nsCOMPtr<nsILocalFile> appdir;
        char* selfch;
        CCommonString::ToMBString(self, selfch);

        rv = NS_NewNativeLocalFile(nsCString(selfch), PR_FALSE,
                getter_AddRefs(appdir));

        if (NS_FAILED(rv))
                return 8;

        rv = XRE_InitEmbedding(xuldir, appdir, nsnull, nsnull, 0);
        if (NS_FAILED(rv))
                return 9;

        if (NS_FAILED(StartupProfile()))
                return 10;
        delete xulPath;
        delete selfch;
        delete self;



        nsCOMPtr<nsIWebBrowser>
                gecko(do_CreateInstance(NS_WEBBROWSER_CONTRACTID));
        nsCOMPtr<nsIBaseWindow>
                baseWindow(do_QueryInterface(gecko, &rv));
        NS_ENSURE_SUCCESS(rv, rv);
        RECT rcLocation;
        ::GetClientRect(pFrm->m_hWnd, &rcLocation);

        if (::IsRectEmpty(&rcLocation)) {
                rcLocation.bottom++;
                rcLocation.top++;
        }

        rv = baseWindow->InitWindow(pFrm->m_hWnd, nsnull, 0, 0,
                rcLocation.right - rcLocation.left,
                rcLocation.bottom - rcLocation.top);

        NS_ENSURE_SUCCESS(rv, rv);

        rv = baseWindow->Create();
        NS_ENSURE_SUCCESS(rv, rv);

        rv = baseWindow->SetVisibility(PR_TRUE);
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIWebNavigation>
                webNavigation(do_QueryInterface(gecko, &rv));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsISupports> pISupports = NULL;
        rv = webNavigation->LoadURI(NS_LITERAL_STRING("http://
www.google.com").get(),
                nsIWebNavigation::LOAD_FLAGS_NONE,
                nsnull, nsnull, nsnull);

        return rv;

}



_______________________________________________
dev-embedding mailing list
dev-embedding@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to