But what's the lib?
Main Topics
Browse All TopicsAfter creating an MFC AppWizard application, I thought I'd find WinMain() in MFC42.dll. But using depends.exe I can't see WinMain() anywhere in the DLL. So where is WinMain()??
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
MFC calls _tWinMain in APPMODUL.cpp. This file in in MFC/SRC folder. And _tWinMAin is defined in TCHAR.h file as
#define _tWinMain WinMain
And this in turn calls AfxWinMain in WinMain.cpp file.
Look in AfxWin.h file in Include folder to get more info about headers involved in Thread initialization and overriding of WinMain, etc...
Yashik,
Thes functions are not exported in MSVCRT.lib. This lib is for C Runtime. For MFC's function, its in MFC42 libs.
tdubroff,
Gointo MFC/lib folder. And on command line use dumpbin utulity to see what all is exported from this lib. You will see all the MFC classes are there. And there you will find AfxWinMain etc..
dumpbin /exports MFC42.lib
Read the documentation for CWinApp. This will tell you how WinMain gets called...
WinMain is an entry point for all Windows applications. So your application has to provide this entry point. In MFc apps, this work is done by the CWinApp class. It implements this entry point on your behalf. Like in console apps, you have entry point as main. in GUI apps you have WinMain. So it is implemented by your application. So MFC42.lib has the export for AfxWinMain. And this AfxWinMain resides in AFXMODUL.cpp. So this function gets compiled into MFC42 lib.
I would strongly recommend that you read the documentation about this entry point and also CWinApp.
Okay, here is what I know so far:
1) It is AppModul.cpp which contains _tWinMain. This name is just a pseudonym for WinMain and all this function does is call AfxWinMain.
2) AfxWinMain is located in WinMain.cpp.
3) CWinApp is used by AfxWinMain. The programmer can override methods in CWinApp to effectively change the functionality of AfxWinMain. But CWinApp does not provide AfxWinMain, ie, CWinApp does not have a member function that is AfxWinMain.
4) Nowhere in my default MFC application does WinMain appear. This makes sense because it is compiled/linked in via AfxWinMain...and we know AfxWinMain is called by WinMain.
So, the question still remains. What lib file is WinMain located in?? Since we know WinMain is part of AppModul.cpp, the question becomes: What lib file did AppModul.cpp get compiled into?
It is right in your own MFC application. Win32 does not implement it for you. You have to implement it. Its the entry point that OS looks for in your executable. Its just like "main" in your console application. Like you have to provide the main funvtion. Similarly GUI application has to provide WinMAin. And it has already been done in MFC lib.
AppModul.cpp file gets compiled into MFC42 DLL&LIB. Dump the exports of MFC42.lib and see that it has all the functions that AppModul.cpp defines.
WinMain is not exported anywhere. This is the entry point that your application has to provide. Whenever you compile an application, compiler writes an entry point into the binary image. For Windows apps, this entry point is WinMain. So when you try to execute a Windows app, runtime checks with EXE file about the entry point that has been specified. So AfxWinMain has provided the entry point as _tWinMain. Which is nothing but typedefd as WinMain. SO in no lib you will find the export for this function because every application has to provide this function. I would suggest that you look at the good old way of writing Win32 apps. The first function you will find in those samples is WinMain. Then it will be more clear to you where this function is....
Obviously WinMain is provided for me in the file AppModul.cpp. In fact if I place a breakpoint on this function in this file, my skeletal MFC AppWizard application will break there. So there is WinMain. It is in AppModul.cpp. I didn't provide it. MFC did.
However, I do not think that Visual Studio compiles this file every time for every custom application created. Rather I think it is already precompiled and is in either a lib or dll file. Perhaps I am wrong here; I don't know.
Business Accounts
Answer for Membership
by: yashikPosted on 2001-02-20 at 11:02:02ID: 5860875
It is in your application ( statically linked from some lib )
You may put breakpoint into InitInstance and see what is on the stack.
WinMain calls AfxWinMain and AfxWinMain calls InitInstance.