how to compile as win32 from command line?

Yes , i am fullly aware this is a rediculous question, but no matter how much reading i do from anywhere , i keep encountering the same thing over and over.

*edit* Personally, i think its just like most books i have been reading, where it seems , code is always wrong, and explanations are only half complete at best :(

I have been working out of an older book named *Introduction to 3d programming iwth directX* Now i am not very good at programming, but i have dabbled in a bit, and the book shows an appendix that has an *Intro to Windows Programming* in the Appendix. Here it demonstrates this code, which is *apparently a simple window* fully functioning.
Heres the code.

But first , heres a quote from within the book itself.

**Note that you must create a Win32 Application Project,
not a Win32 Console Application Project.**

// File: hello.cpp
// Author: Frank D. Luna (C) All Rights Reserved
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP,
// MSVC++ 7.0
// Desc: Demonstrates creating a Windows application.
// Include the windows header file, this has all the
// Win32 API structures, types, and function declarations
// we need to program Windows.


// The main window handle. This is used to identify
// the main window we are going to create.

HWND MainWindowHandle = 0;

// Wraps the code necessary to initialize a Windows
// application. Function returns true if initialization
// was successful, else it returns false.

bool InitWindowsApp(HINSTANCE instanceHandle, int show);

// Wraps the message loop code.

int Run();

// The window procedure, handles events our window
// receives.

UINT msg,
WPARAM wParam,
LPARAM lParam);

// Windows equivalant to main()

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR pCmdLine,
int nShowCmd)

// First we create and initialize our Windows
// application. Notice we pass the application
// hInstance and the nShowCmd from WinMain as
// parameters.

if(!InitWindowsApp(hInstance, nShowCmd))
::MessageBox(0, "Init - Failed", "Error", MB_OK);
return 0;

// Once our application has been created and
// initialized we enter the message loop. We
// stay in the message loop until a WM_QUIT
// message is received, indicating the application
// should be terminated.

return Run(); // enter message loop

bool InitWindowsApp(HINSTANCE instanceHandle, int show)

// The first task to creating a window is to describe
// its characteristics by filling out a WNDCLASS
// structure.

wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = instanceHandle;
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hbrBackground =
wc.lpszMenuName = 0;
wc.lpszClassName = "Hello";

// Then we register this window class description
// with Windows so that we can create a window based
// on that description.

::MessageBox(0, "RegisterClass - Failed", 0, 0);
return false;

// With our window class description registered, we
// can create a window with the CreateWindow function.
// Note, this function returns a HWND to the created
// window, which we save in MainWindowHandle. Through
// MainWindowHandle we can reference this particular
// window we are creating.

MainWindowHandle = ::CreateWindow(

if(MainWindowHandle == 0)
::MessageBox(0, "CreateWindow - Failed", 0, 0);
return false;

// Finally we show and update the window we just created.
// Observe we pass MainWindowHandle to these functions so
// that these functions know what particular window to
// show and update.
::ShowWindow(MainWindowHandle, show);

return true;

int Run()
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));

// Loop until we get a WM_QUIT message. The
// function GetMessage will only return 0 (false)
// when a WM_QUIT message is received, which
// effectively exits the loop.

while(::GetMessage(&msg, 0, 0, 0) )

// Translate the message, and then dispatch it
// to the appropriate window procedure.


return msg.wParam;

UINT msg,
WPARAM wParam,
LPARAM lParam)

// Handle some specific messages:

switch( msg )
// In the case the left mouse button was pressed,
// then display a message box.

::MessageBox(0, "Hello, World", "Hello", MB_OK);
return 0;

// In the case the escape key was pressed, then
// destroy the main application window, which is
// identified by MainWindowHandle.


if( wParam == VK_ESCAPE )


return 0;

// In the case of a destroy message, then
// send a quit message, which will terminate
// the message loop.

return 0;

// Forward any other messages we didn't handle
// above to the default window procedure.
return ::DefWindowProc(windowHandle,


Here3s what microsoft says over and over as far as compiling a win32 app.

To create a win32 application, select File, New Project, and choose the win32 application.

Well the problem is , im trying to compile from the visual studio command line , i dont want to use the IDE, but nothing is explaining how to do this. The closest thing i have encoutnered so far is this , which i tried , and it throws a hella lot of errors saying , it cant find this and that ....

cl test.cpp /link /entry:winMain /subsystem:windows

Neither of these are usefull - i know this ...

cl test.cpp <--- creates a standard c++ exe
cl test.cpp /clr <---creates the same exe but with clr support.

If anyone can help a poor noob sort out this mess in my head , thanks in advance!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!