打开chromium项目,在解决方案管理其中找到chrome项目,展开如下图:
chrome的入口函数就在chrome_exe_main_win.cc中
打开chrome_exe_main_win.cc
int
APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev,
wchar_t
*,
int
) {
// Initialize the commandline singleton from the environment.
CommandLine::Init(0, NULL);
// The exit manager is in charge of calling the dtors of singletons.
base::AtExitManager exit_manager;
MetroDriver metro_driver;
if
(metro_driver.in_metro_mode())
return
metro_driver.RunInMetro(instance, &RunChrome);
// Not in metro mode, proceed as normal.
return
RunChrome(instance);
}
即是程序的入口函数
即是程序的入口函数
接下来调用RunChrome(instance)这个函数的调用将会加载chrome.dll
int
RunChrome(HINSTANCE instance) {
bool
exit_now =
true
;
// We restarted because of a previous crash. Ask user if we should relaunch.
if
(ShowRestartDialogIfCrashed(&exit_now)) {
if
(exit_now)
return
content::RESULT_CODE_NORMAL_EXIT;
}
// Initialize the sandbox services.
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
// Load and launch the chrome dll. *Everything* happens inside.
MainDllLoader* loader = MakeMainDllLoader(); //构造一个用于加重chrome.dll的对象
int
rc = loader->Launch(instance, &sandbox_info); //加重dll
loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
delete
loader;
return
rc;
}
Launch方法显示的加载chrome.dll,并取得导出dll中ChromeMain函数,函数如下
程序进入
ChromeMain函数
int
MainDllLoader::Launch(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sbox_info) {
std::wstring version;
std::wstring file;
dll_ = Load(&version, &file);
if
(!dll_)
return
chrome::RESULT_CODE_MISSING_DATA;
scoped_ptr<base::Environment> env(base::Environment::Create());
env->SetVar(chrome::kChromeVersionEnvVar, WideToUTF8(version));
InitCrashReporter();
OnBeforeLaunch(file);
DLL_MAIN entry_point =
reinterpret_cast
<DLL_MAIN>(::GetProcAddress(dll_,
"ChromeMain"
));
if
(!entry_point)
return
chrome::RESULT_CODE_BAD_PROCESS_TYPE;
int
rc = entry_point(instance, sbox_info);
return
OnBeforeExit(rc, file);
}
ChromeMain函数定义如下:
DLLEXPORT