include files for WinMain

S

Steve Richter

I am working from the C++ .net step by step book ...

my project compiles and runs as a console application:

#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

int wmain(void)
{
Console::WriteLine(S"Forms Example");
Application::Run(new CppForm());
return 0;
}

Now I would like to get rid of the console part of the appl, so I
replace
int wmain( void )

with:
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow )

and the compiler does not know what HINSTANCE is.

so I add an include stmt:
#include <windef.h>

and all hell breaks loose. undefined this, what is that, ...

1st question: is it "wmain" that makes a console application? and
WinMain makes a window application?

2nd question: what include files are needed to use "WinMain" as the
program entry point?

3rd question: is there a good MS document that explains all the
different include files in C++ .NET and when to use them?


thanks,

Steve Richter
 
G

Gary Chang [MSFT]

Hi Steve,

Thanks for posting in the group!

"When you use Microsoft Visual C++ to create an application project, the
integrated environment sets up various linker switches so that the linker
embeds the proper type of subsystem in the resulting executable. This
linker switch is /SUBSYSTEM:CONSOLE for CUI applications and
/SUBSYSTEM:WINDOWS for GUI applications. When the user runs an application,
the operating system's loader looks inside the executable image's header
and grabs this subsystem value. If the value indicates a CUI-based
application, the loader automatically ensures that a text console window is
created for the application. If the value indicates a GUI-based
application, the loader doesn't create the console window and just loads
the application. Once the application starts running, the operating system
doesn't care what type of UI your application has." (from <<Programming
Applications for Microsoft Windows>> by Jeffrey Richter)

And the wmain is an entry-point function for CUI application that wants
Unicode characters and strings,
the WinMain for GUI application that wants ANSI characters and strings, the
specific type application needs its corresponding entry-point function.

For what include files are needed to build a windows form application in
VC.NET, I think you can create a test project in VC.NET, you can find them
in stdafx.h and Form1.cpp:

// in stdafx.h
#define WIN32_LEAN_AND_MEAN

#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

//in Form1.cpp
#include <windows.h>


Hopte that helps!


Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top