为什么入口函数wWinMain会被多次调用?

zyr322 2013-05-18 09:39:30
按我的理解入口函数在整个程序运行期间应该只会被调用一次(find没发现有其他函数调用wWinMain函数),但这个程序(cef里面的一个例子)只要我打开一个新的页面,wWinMain就会运行一次,控制台就会打印出“the process begin to run”的信息。



// Program entry point function. 入口函数
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
// using namespace zsummer::log4z;
// ILog4zManager::GetInstance()->Start();

UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

cout << "==========================================" << endl;
cout << " the process begin to run" << endl;
cout << "==========================================" << endl;

...全文
309 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
有新工作否 2013-05-21
  • 打赏
  • 举报
回复
这个有什么奇怪么,你运行2个程序,就运行2次这个函数呀。就像你打开了一个 txt文件,再打开一个txt文件,当然运行2次程序呀。
赵4老师 2013-05-20
  • 打赏
  • 举报
回复
调试时按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。 对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
赵4老师 2013-05-20
  • 打赏
  • 举报
回复
引用 4 楼 zyr322 的回复:
[quote=引用 2 楼 qingcairousi 的回复:] 用windbg看看调用堆栈吧。
谢谢 我去看看WinDbg的使用教程。[/quote] k, kb, kc, kd, kp, kP, kv (Display Stack Backtrace) The k* commands display the stack frame of the given thread, together with related information.. Syntax User-Mode [~Thread] k[b|p|P|v] [c] [n] [f] [L] [FrameCount] [~Thread] k[b|p|P|v] [c] [n] [f] [L] = BasePtr [FrameCount] [~Thread] k[b|p|P|v] [c] [n] [f] [L] = BasePtr StackPtr InstructionPtr [~Thread] kd [WordCount] Kernel-Mode [Processor] k[b|p|P|v] [c] [n] [f] [L] [FrameCount] [Processor] k[b|p|P|v] [c] [n] [f] [L] = BasePtr [FrameCount] [Processor] k[b|p|P|v] [c] [n] [f] [L] = BasePtr StackPtr InstructionPtr [Processor] kd [WordCount] Parameters Thread Specifies the thread whose stack is to be displayed. If you omit this parameter, the stack of the current thread is displayed. For more information about thread syntax, see Thread Syntax. You can specify threads only in user mode. Processor Specifies the processor whose stack is to be displayed. For more information about processor syntax, see Multiprocessor Syntax. You can specify processors only in kernel mode. b Displays the first three parameters that are passed to each function in the stack trace. c Displays a clean stack trace. Each display line includes only the module name and the function name. p Displays all of the parameters for each function that is called in the stack trace. The parameter list includes each parameter's data type, name, and value. The p option is case sensitive. This parameter requires full symbol information. P Displays all of the parameters for each function that is called in the stack trace, like the p parameter. However, for P, the function parameters are printed on a second line of the display, instead of on the same line as the rest of the data. v Displays frame pointer omission (FPO) information. On x86-based processors, the display also includes calling convention information. n Displays frame numbers. f Displays the distance between adjacent frames. This distance is the number of bytes that separate the frames on the actual stack. L Hides source lines in the display. L is case sensitive. FrameCount Specifies the number of stack frames to display. You should specify this number in hexadecimal format, unless you have changed the radix by using the n (Set Number Base) command. The default value is 20 (0x14), unless you have changed the default value by using the .kframes (Set Stack Length) command. BasePtr Specifies the base pointer for the stack trace. The BasePtr parameter is available only if there is an equal sign (=) after the command. On an x86-based processor, you can add one more parameter after BasePtr (which is interpreted as the FrameCount parameter) or two more parameters after BasePtr (which are interpreted as the StackPtr and InstructionPtr parameters). StackPtr (x86-based processor only) Specifies the stack pointer for the stack trace. If you omit StackPtr and InstructionPtr, the command uses the stack pointer that the esp register specifies and the instruction pointer that the eip register specifies. InstructionPtr (x86-based processor only) Specifies the instruction pointer for the stack trace. If you omit StackPtr and InstructionPtr, the command uses the stack pointer that the esp register specifies and the instruction pointer that the eip register specifies. WordCount Specifies the number of DWORD_PTR values in the stack to dump. The default value is
zyr322 2013-05-20
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
调试时按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。 对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
谢谢赵老师。
zyr322 2013-05-20
  • 打赏
  • 举报
回复
引用 6 楼 mujiok2003 的回复:
是不是有启动进程的代码?比如popen,system(..)等。
这个不清楚,我用了别人的东西。
zyr322 2013-05-20
  • 打赏
  • 举报
回复
引用 5 楼 houliang120 的回复:
winMain函数只是供启动代码调用的入口点函数,而且可以通过/ENTRY开关来设置入口点,在运行期间被调用也不是特别奇怪。。。拙见,呵呵
谢谢,我是从java转来的,java里面的main做为入口点只会执行一次,这样就可以将一些初始化工作放在里面执行。 但我在winMain里面初始化了一个日志记录系统后。发现在程序运行的过程中winMain还一直在被调用。日志管理系统也会不断初始化。
zyr322 2013-05-19
  • 打赏
  • 举报
回复
引用 2 楼 qingcairousi 的回复:
用windbg看看调用堆栈吧。
谢谢 我去看看WinDbg的使用教程。
zyr322 2013-05-19
  • 打赏
  • 举报
回复
引用 1 楼 cgqzly123 的回复:
菜鸟请问,这用的是哪个编程软件啊????恕不能帮你忙了。。
vs2010
mujiok2003 2013-05-19
  • 打赏
  • 举报
回复
是不是有启动进程的代码?比如popen,system(..)等。
houliang120 2013-05-19
  • 打赏
  • 举报
回复
winMain函数只是供启动代码调用的入口点函数,而且可以通过/ENTRY开关来设置入口点,在运行期间被调用也不是特别奇怪。。。拙见,呵呵
qingcairousi 2013-05-18
  • 打赏
  • 举报
回复
用windbg看看调用堆栈吧。
愤怒的呆鱼 2013-05-18
  • 打赏
  • 举报
回复
菜鸟请问,这用的是哪个编程软件啊????恕不能帮你忙了。。

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧