Pardon me for posting this here, but it seemed to be the most appropriate forum. It will also help me to understand why WIN32ASM works the way it does.

I've been going through Iczelion's Tutorials to help me understand Windows Programming. They have been quite helpful.

Tutorial 2 is quite simple. I have tried to convert the ASM program into a C++ program. This is what I have done.
#include <windows.h>


int main(int argc, char* argv[])
{
char * MsgBoxText = "Message Box Text!";
char * MsgBoxCaption = "Message Box Title";

MessageBox(NULL, MsgBoxText, MsgBoxCaption, MB_OK);

return 0;
}
Compiling it under VC++ 6.0, I get a DOS box until the MessageBox is closed.

So, why do I get a DOS box under C++ and I don't get one as an ASM compile? And can you show me how to get rid of the DOS box?

*baffled*
Posted on 2002-12-07 21:11:29 by Kdr Kane
Well, somebody has provided the answer to me. So, I thought I would post it. I'm still trying to figure out some of the details and why it works the way it does.
#define STRICT

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
char * MsgBoxText = "Message Box Text!";
char * MsgBoxCaption = "Message Box Title";

MessageBox(NULL, MsgBoxText, MsgBoxCaption, MB_OK);

return 0;
}
Posted on 2002-12-07 21:45:29 by Kdr Kane
you mean the dos box/command prompt that pops up together with the message box?

ANSWER: assuming you use MS-VC, go to projects->Settings->Link Tab->Project Options

change the parameter subsystem:console to subsystem:windows

or add this to your code

#pragma comment(linker, "/subsystem:\"windows\"")

- | -

I really don't know the real reason why it works that way, I assume this is the "standard" way of doing things. :) but
#include<windows.h>


#pragma comment(linker, "/entry:\"main\"")

int main(int argc, char* argv[])
{
char * MsgBoxText = "Message Box Text!";
char * MsgBoxCaption = "Message Box Title";

MessageBox(NULL, MsgBoxText, MsgBoxCaption, MB_OK);

return 0;
}
:)

using the WinMain.... blah! blah!... stuff... I think this is a "predefined" thingy, so you don't have to worry about the necessary startup codes like GetModuleHandle.... :)
Posted on 2002-12-08 23:48:38 by stryker
That makes sense to me. It's a Microsoft specific linker option to change the entry point.

Thanks for more information. :alright:
Posted on 2002-12-09 14:35:05 by Kdr Kane
You know it would be easier just to do:


#include blah blah

in WINAPI WinMain
{

MessageBox(NULL, "Message Box Text!", "Message Box Title", MB_OK);

return 0;
}
Posted on 2003-04-10 19:44:35 by AJAKE98