MFC 的 wWinMain 如何在可执行文件中结束?
在 MFC 中,wWinMain
定义在 appmodul.cpp
中.据我所知,该文件内置于 mfc90ud.dll 中.但是,当我运行我的应用程序时,调用堆栈显示 MyApplication.exe!wWinMain
.它是如何获取在 appmodul.obj
中导出的 wWinMain
函数并将其放置在我的应用程序中的?
In MFC, wWinMain
is defined in appmodul.cpp
. This file is built into mfc90ud.dll from what I can see. However, when I run my application, the call stack shows MyApplication.exe!wWinMain
. How has it taken the wWinMain
function that was exported in appmodul.obj
and placed it in my application?
在解决方案资源管理器"窗口中右键单击您的项目、属性"、链接器"、命令行".在其他选项"框中键入/verbose.重建你的项目.输出"窗口现在显示链接器找到符号的位置的跟踪.搜索winmain"以找到此内容:
Right-click your project in the Solution Explorer window, Properties, Linker, Command Line. Type /verbose in the "Additional Options" box. Rebuild your project. The Output window now shows a trace of where the linker found a symbol. Search it for "winmain" to find this:
1> Searching c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\lib\mfcs90ud.lib:
1> Found _wWinMain@16
1> Referenced in msvcrtd.lib(wcrtexew.obj)
1> Loaded mfcs90ud.lib(appmodul.obj)
注意库名,mfcs90ud.lib 是静态链接库.如果您搜索mfcs90ud.lib",那么您还可以看到该库是如何被引用的:
Note the library name, mfcs90ud.lib is a static link library. If you search for "mfcs90ud.lib" then you can also see how that library got referenced:
1>Starting pass 1
1>Processed /DEFAULTLIB:mfc90ud.lib
1>Processed /DEFAULTLIB:mfcs90ud.lib
1>Processed /DEFAULTLIB:msvcrtd.lib
etc..
如果您在 MFC 源代码中搜索mfcs",您会发现/defaultlib 选项是如何被注入的.来自 afx.h:
If you search the MFC source code for "mfcs", you'll find how this /defaultlib option got injected. From afx.h:
#ifdef _DEBUG
#pragma comment(lib, "mfc" _MFC_FILENAME_VER "ud.lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER "ud.lib")
#else
#pragma comment(lib, "mfc" _MFC_FILENAME_VER "u.lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER "u.lib")
#endif
长话短说,一个 MFC 应用链接了两个库.Mfc90u.lib 是 MFC DLL 版本的导入库.Mfcs90u.lib 是一个静态链接库,其中包含链接到可执行文件的位.包括 WinMain().
Long story short, an MFC app links two libraries. Mfc90u.lib is the import library for the DLL version of MFC. Mfcs90u.lib is a static link library that contains the bits that get linked into your executable. Including WinMain().