简体   繁体   中英

C++ PHP Desktop and CEF crash LoadUrl()

I added a menu bar to PHP desktop that has links in my script like this

菜单

In c++ code I use WindowProc

case IDM_ACCOUNT:
        CefWindowInfo windowInfo;
        CefBrowserSettings browser_settings;

        CefRefPtr<CefBrowser> cefBrowser;
        CefRefPtr<CefFrame> frame = cefBrowser->GetMainFrame();

        std::string startupURL = "http://127.0.0.1:9990/account/";

        frame->LoadURL(startupURL);

        break;

My code crashes when I select anything from menu mainBrowser in app to go to this URL.

cefBrowser variable contains an empty CefBrowser object. Use such code instead:

// browser variable already defined in main.cpp in WindowProc
browser = GetBrowserWindow(hwnd);
if (browser && browser->GetCefBrowser()) {
    CefRefPtr<CefFrame> frame = browser->GetCefBrowser()->GetMainFrame();
    std::string startupURL = "http://127.0.0.1:9990/account/";
    frame->LoadURL(startupURL);
}           

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM