Issue with VS2008 and general MFC embed advice

Built a cool app using CEF that you'd like to share with the community? Talk about it here.

Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Tue Sep 18, 2012 5:45 pm

Background: I have a large MDI MFC application that dynamically loads modules at runtime. Some of these modules currently embed local web browsers using the OLE web browser interface (IE embeds). I have several issues and questions:

1. I see both CEF1 and CEF3 are available. A lot of the examples I'm able to find seem to be designed (based on their #includes) for CEF1. Is this better for such a project? I may have one or more embedded web controls on different CViews that the user will switch between. I'm sure how many processes CEF uses will affect which is better.

2. All the examples I've seen require making the CWinApp initialize CEF. My application itself isn't really cognizant of the web browsers, individual dlls may be though. Is the API re-entrant? By this, I mean, if I have 2 DLLs, DLL1 and DLL2 and each initializes CEF and embeds a CEF window, will they step on each other's toes? Will I need to make sure that the exe initializes CEF just once in order to ensure loading/unloading happens correctly?

3. When I try to include "include/cef.h" (CEF1) or "include/cef_client.h"/"include/cef_app.h" (CEF3) I get a lot of errors in the CEF code 'syntax error : 'string'' which keep me from compiling. In my experience, this comes from using STL strings without explicitly using the std namespace. Is my application expected to fix this somehow? I've tried:
a: #include<string>
b: using namespace std;
c: using std::string;
before including the cef headers, and none of them seem to work.


In summary, I would really appreciate a full CEF example (most of the other examples have good code snippets but leave out #includes, etc, which I'm obviously doing wrong somehow). Also, I've noticed the example that comes with CEF (as well as the examples in this forum) are just for MFC dialog apps which are much simpler than what I'm trying to do. Most of these examples are essentially just recreating a browser window. I actually want to EMBED a browser on a CView/CPropertyPage. I'd like to go with chromium instead of IE (since the IE embed uses an old version of IE), but so far its been quite tough. Any help or direction would be appreciated.
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Re: Issue with VS2008 and general MFC embed advice

Postby magreenblatt » Wed Sep 19, 2012 10:52 am

DillonSadofsky wrote:1. I see both CEF1 and CEF3 are available. A lot of the examples I'm able to find seem to be designed (based on their #includes) for CEF1. Is this better for such a project? I may have one or more embedded web controls on different CViews that the user will switch between. I'm sure how many processes CEF uses will affect which is better.

Use CEF3 unless you need a feature that it doesn't support. Patches are also welcome for implementing such features.

DillonSadofsky wrote:2. All the examples I've seen require making the CWinApp initialize CEF. My application itself isn't really cognizant of the web browsers, individual dlls may be though. Is the API re-entrant? By this, I mean, if I have 2 DLLs, DLL1 and DLL2 and each initializes CEF and embeds a CEF window, will they step on each other's toes? Will I need to make sure that the exe initializes CEF just once in order to ensure loading/unloading happens correctly?

Arguments are passed to CefInitialize which are relevant to the global state of your application. You will need to design a centralized approach for initializing CEF.

DillonSadofsky wrote:3. When I try to include "include/cef.h" (CEF1) or "include/cef_client.h"/"include/cef_app.h" (CEF3) I get a lot of errors in the CEF code 'syntax error : 'string'' which keep me from compiling.

What is the exact error message with line numbers, etc?
magreenblatt
Site Admin
 
Posts: 9848
Joined: Fri May 29, 2009 6:57 pm

Re: Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Wed Sep 19, 2012 11:12 am

1. Thank you, I will pursue CEF3. I was just curious because a lot of the MFC examples I've seen include cef.h, which seems to only exist in CEF1. I've been pouring over the headers to try to figure out exactly what to do, but some CEF3 MFC examples would be nice.

2. Thank you, this answers my question, I must initialize CEF only once per process. I suppose I'll either make my exe do it, or I'll find a way to coordinate any extensions that may need it through some kind of reference counting.

3. I spent awhile on this and I apologize for bringing it up, it was my code's fault. There were #defines in unrelated headers that were affecting the parsing of the .h file. In my case, it was the token Execute.


Looking at the structure of CEF, I see it has its own manual message pump and handlers. I'm curious if anyone has made something similar to the easily embeddable IE activeX control that is available in visual c? IE a window that can be initialized, moved, destroyed, etc that will pass such messages onto CEF. I think it would go a long way for MFC developers to have more of a 'drop-in' solution. Also, I understand the logic of having a process be heavily entwined with CEF, but I feel that design is more suited to writing a full browser (which is a lot of the examples I've seen) rather than simply embedding one or more HTML windows in an application.
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Re: Issue with VS2008 and general MFC embed advice

Postby magreenblatt » Wed Sep 19, 2012 12:22 pm

You can use the CefSettings.multi_threaded_message_loop setting on Windows if you don't want to integrate the message loop processing with your application. If you feel that an ActiveX wrapper helps your use case then you're of course welcome to create one.
magreenblatt
Site Admin
 
Posts: 9848
Joined: Fri May 29, 2009 6:57 pm

Re: Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Wed Sep 19, 2012 1:07 pm

Fair enough. If I knew how to do such things, I wouldn't be asking for example code here ;)

I am having a more specific issue though which maybe you can help with. Linking against libcef.lib is supposed to enable dynamic linking against libcef.dll, right? I'm having trouble reproducing the example (cefclient) in my application. Whenever I reference a cef function (lets say CefShutdown), even though I'm including the dependency of libcef.lib, I get linker errors as though the cef functions aren't exposed. Here is an example:

XXXXXX.obj : error LNK2001: unresolved external symbol "void __cdecl CefShutdown(void)" (?CefShutdown@@YAXXZ)

Any ideas? Normally I don't have any issue with linking 3rd party libraries this way.
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Re: Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Wed Sep 19, 2012 1:23 pm

I see there is a compile flag "USING_CEF_SHARED", which seems to attempt to turn on __declspec(dllimport), but when I look at the definition of CefShutdown (for example) it isn't marked as exported anyway. Am I missing something? Should I not be using include/cef_app.h as the source headers for my application?

Using this as a clue, I see that the headers in \include\capi seem to have CEF_EXPORT specified. I assume this is a c-style api for older applications, or is it what I should be using? When I look at CefClient test app, it seems to include \include\cef_app.h and uses CefShutdown (vs the capi version of cef_shutdown). I can't seem to figure out what I'm doing differently. the CefClient app has a lot of preprocessor defines, most of which I don't understand. I'm not totally sure which of them (if any) I should be including in my application. In my experience, I generally don't need to define too many such things to dynamically link 3rd party libraries.
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Re: Issue with VS2008 and general MFC embed advice

Postby magreenblatt » Wed Sep 19, 2012 1:48 pm

magreenblatt
Site Admin
 
Posts: 9848
Joined: Fri May 29, 2009 6:57 pm

Re: Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Wed Sep 19, 2012 2:01 pm

Yeah, I was just commenting when you posted that. Thanks for that link, that helps. I did need to switch to /MDd and /MD and recompile, which works at least once /WX is off (seems like you guys should turn that off in the sample).

I've now attempted to link against the libcef_dll_wrapper.lib recompiled for /MDd, but I still get a lot of linker errors. When I look closer, almost all the linker errors I get are related to the cef strings. This got me thinking since I noticed there are flags that switch the internal character set of cef. Currently my app doesn't support unicode, therefore TCHAR is just char. I was curious what would happen if I turned off unicode in cefclient. When I switch it to multibyte character set instead of unicode, cefclient gets compile errors complaining:
1>.\cefclient\client_handler_win.cpp(22) : error C2664: 'SetWindowTextA' : cannot convert parameter 2 from 'const wchar_t *' to 'LPCSTR'

SetWindowTextA is the ascii version, which expects LPCSTR which is just a const char*, but the cef code is explicitly passing in the contents of a std::wstring, which are wide characters. I don't see any compile flags in client_handler_win.cpp or any defines that would switch this behavior. This makes me suspect that cef simply doesn't support compiling without unicode turned on? Or maybe I'm still missing something.

The kind of linker errors my application gets are:
1>libcef_dll_wrapper.lib(response_ctocpp.obj) : error LNK2001: unresolved external symbol __imp__cef_string_utf16_clear
Most of them have utf16 in the name somewhere. I tried switching the flags to UTF8, but that didn't seem to help, but maybe I did it wrong. I feel like I'm getting closer. However, since I can't seem to get cefclient to compile without unicode turned on, I'm guessing that this library doesn't support embedding in ascii applications?
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Re: Issue with VS2008 and general MFC embed advice

Postby magreenblatt » Wed Sep 19, 2012 2:22 pm

If you change the CefString type you need to rebuild all of CEF, not just libcef_dll_wrapper.

CEF should work with non-Unicode applications but I'm not sure anyone has tried it recently.
magreenblatt
Site Admin
 
Posts: 9848
Joined: Fri May 29, 2009 6:57 pm

Re: Issue with VS2008 and general MFC embed advice

Postby DillonSadofsky » Wed Sep 19, 2012 2:27 pm

Thank you for all your time and quick responses. I'm guessing rebuilding all of CEF is a bit deeper of a rabbit hole. I will try to look into it.
DillonSadofsky
Newbie
 
Posts: 6
Joined: Tue Sep 18, 2012 5:31 pm

Next

Return to Apps Discussion

Who is online

Users browsing this forum: No registered users and 2 guests