CEF4 在 C++ Builder 10.2.1下,编译报错。。。

draculamx 2020-08-27 07:18:05
CEF4 下载地址:https://github.com/salvadordf/CEF4Delphi
在delphi 10.2.1中,编译正常,安装正常。

打开 C++ Builder 10.2.1,窗体上丢几个相关控件:
TChromium *chrm1;
TCEFWindowParent *cfwndwprnt1;

编译,提示“uCEFConstants.hpp”中有错误:

static const System::Word WM_POINTERUPDATE = System::Word(0x245);
static const System::Word WM_POINTERDOWN = System::Word(0x246);
static const System::Word WM_POINTERUP = System::Word(0x247);

static const System::Int8 USER_DEFAULT_SCREEN_DPI = System::Int8(0x60);

错误内容:[bcc32 Error] uCEFConstants.hpp(519): E2040 Declaration terminated incorrectly

经查,错误原因是,这些静态变量的名称,已经在“winuser.h”中被定义。。。
以下是“winuser.h”中的定义:

#define WM_POINTERUPDATE 0x0245
#define WM_POINTERDOWN 0x0246
#define WM_POINTERUP 0x0247
#define USER_DEFAULT_SCREEN_DPI 96

这就很尴尬了。。。。
...全文
209 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我感觉
Ucefapplication::GlobalCEFApp =new TCefApplication();
Ucefapplication::GlobalCEFApp->LogFile = "debug.log";
Ucefapplication::GlobalCEFApp->LogSeverity = LOGSEVERITY_INFO;
Ucefapplication::GlobalCEFApp->Cache = "cache";
Ucefapplication::GlobalCEFApp->EnablePrintPreview = true;
应该放在TFormMain::FormCreate中
delete Ucefapplication::GlobalCEFApp;放在TFormMain::FormDestroy中
draculamx 2020-08-27
  • 打赏
  • 举报
回复
这是论坛里有人贴出的代码: https://bbs.csdn.net/topics/392343611
draculamx 2020-08-27
  • 打赏
  • 举报
回复
我也不懂啊。。我照着Delphi的Demo来的啊。。现在可以运行了,也可以浏览网页,但是退出程序的时候,直接报个AV错误。。
ooolinux 2020-08-27
  • 打赏
  • 举报
回复
不懂。你那几行代码为什么放在winmain里,不放窗体构造函数里。
draculamx 2020-08-27
  • 打赏
  • 举报
回复
工程文件代码如下:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include "uCEFApplication.hpp"
#include "uCEFChromium.hpp"
//---------------------------------------------------------------------------
USEFORM("FormMainUnit.cpp", FormMain);
//---------------------------------------------------------------------------
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
	Ucefapplication::GlobalCEFApp =new TCefApplication();
	Ucefapplication::GlobalCEFApp->LogFile             = "debug.log";
	Ucefapplication::GlobalCEFApp->LogSeverity         = LOGSEVERITY_INFO;
	Ucefapplication::GlobalCEFApp->Cache               = "cache";
	Ucefapplication::GlobalCEFApp->EnablePrintPreview  = true;

	try
	{
		Application->Initialize();
		Application->MainFormOnTaskBar = true;
		Application->CreateForm(__classid(TFormMain), &FormMain);
		Application->Run();
	}
	catch (Exception &exception)
	{
		Application->ShowException(&exception);
	}
	catch (...)
	{
		try
		{
			throw Exception("");
		}
		catch (Exception &exception)
		{
			Application->ShowException(&exception);
		}
	}

	delete Ucefapplication::GlobalCEFApp;

	return 0;
}
//---------------------------------------------------------------------------
窗体文件代码如下:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FormMainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cefvcl"
#pragma link "uCEFChromiumWindow"
#pragma link "uCEFWinControl"
#pragma link "uCEFChromiumWindow"
#pragma link "uCEFWinControl"
#pragma link "uCEFChromium"
#pragma link "uCEFChromiumCore"
#pragma link "uCEFWindowParent"
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
	: TForm(Owner)
{

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::btnGOClick(TObject *Sender)
{

	chrm1->LoadURL(txtURL->Text);
}
//---------------------------------------------------------------------------


void __fastcall TFormMain::tmr1Timer(TObject *Sender)
{
	tmr1->Enabled = false;

	bool r=chrm1->CreateBrowser(cfwndwprnt1,"");
	if( !r && !chrm1->Initialized )
	{
		tmr1->Enabled = true;
	}
	else
	{
		ShowMessage("Ready!");
	}
}
//---------------------------------------------------------------------------

运行结果: ShowMessage永远不会弹出,也就是说,初始化始终完成不了 点了按钮,打开一个页面,始终打不开。。 debug文件夹下,已经放入了控件运行所需要的库文件:
draculamx 2020-08-27
  • 打赏
  • 举报
回复
解决方案,直接注释掉出错的代码即可。。。 还有就是,CEF4在CB下咋用的。。。我就简单显示个页面都出不来。。。
发帖
茶馆

542

社区成员

C++ Builder 茶馆
社区管理员
  • 茶馆
加入社区
帖子事件
创建了帖子
2020-08-27 07:18
社区公告
暂无公告