Forcing the Linker to Look for a (w)WinMain Entry-Point Function

[Previous] [Next]

After readers add my source code modules to a new Microsoft Visual C++ project and then try to build the project, they receive linker errors. The problem is that they created a Win32 Console Application project, causing the linker to look for a (w)main entry-point function. Since all the book's sample applications are GUI applications, my source code has a _tWinMain entry-point function instead, which causes the linker to complain.

My standard reply to readers is as follows: delete the project, create a new Win32 Application project (note that the word "Console" doesn't appear in this project type) with Visual C++, and then add my source code files to it. The linker looks for a (w)WinMain entry-point function, which I do supply in my code, and which allows the projects to build properly.

To reduce the amount of e-mail I get on this issue, I added a pragma to CmnHdr.h that forces the linker to look for the (w)WinMain entry-point function even if you create a Win32 Console Application project with Visual C++.

In Chapter 4 of Programming Applications for Microsoft Windows, Fourth Edition (Jeffrey Richter, Microsoft Press, 1999), I go into great detail about what the Visual C++ project types are all about, how the linker chooses which entry-point function to look for, and how to override the linker's default behavior.



Programming Server-Side Applications for Microsoft Windows 2000
Programming Server-Side Applications for Microsoft Windows 2000 (Microsoft Programming)
ISBN: 0735607532
EAN: 2147483647
Year: 2000
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net