Win32

F

flingor

Hello everyone!

When I start a "Win32 Project" with Microsoft's Visual C++ I can't
produce any output by using my "normal" C++ code that I would use in a
console application. First, I'm not sure if i place my code in the
right position, but I think I'm right as I don't get any error
messages and the comments by Visual C++ tell me the right place:

-----------------------------------------------------------------------------------

[...]

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.

cout << "This is a test!";

[...]

}

[...]

-----------------------------------------------------------------------------------

When I compile this I just get an empty win32 window, and there's
nowhere written "This is a test!". I also included all necessary
header files, and didn't change nothing from the "main code" already
written by Visual C++, I just added "cout << "This is a test!" ".

Flingor
 
M

Manuel T

When I start a "Win32 Project" [...]

It's a sad feature of MS Windows: when a program uses GUI, output to console
is hidden. The same happens with Java Swing programs.
 
A

Alf P. Steinbach

* (e-mail address removed):
Hello everyone!

When I start a "Win32 Project" with Microsoft's Visual C++ I can't
produce any output by using my "normal" C++ code that I would use in a
console application. First, I'm not sure if i place my code in the
right position, but I think I'm right as I don't get any error
messages and the comments by Visual C++ tell me the right place:

-----------------------------------------------------------------------------------

[...]

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.

cout << "This is a test!";

[...]

}

[...]

-----------------------------------------------------------------------------------

When I compile this I just get an empty win32 window, and there's
nowhere written "This is a test!". I also included all necessary
header files, and didn't change nothing from the "main code" already
written by Visual C++, I just added "cout << "This is a test!" ".

Answer's too long to include here (although it's likely that others will
provide technically inaccurate and misleading short answers); see <url:
http://home.no.net/dubjai/win32apitut/01.pdf>. Please just ask in this
group if you have further questions regarding this specific issue. But
note: even though this is so common a newbie (and for that matter,
experienced dinosaur) a problem that it is in a way on-topic here,
please direct more specific Windows programming question to a Windows
programming group -- see the FAQ for group suggestions.

The referenced article also explains how you can use standard C++ 'main'.

Which you preferentially should.

Hth.,

- Alf
 
B

BobR

Alf P. Steinbach said:
* (e-mail address removed):
Hello everyone!
When I start a "Win32 Project" with Microsoft's Visual C++ I can't
produce any output by using my "normal" C++ code that I would use in a
console application. First, I'm not sure if i place my code in the
right position, but I think I'm right as I don't get any error
messages and the comments by Visual C++ tell me the right place:
--------------------------------------------------------------

[...]

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.

cout << "This is a test!";

[...]
}
[...]
-------------------------------------------------------------------
When I compile this I just get an empty win32 window, and there's
nowhere written "This is a test!". I also included all necessary
header files, and didn't change nothing from the "main code" already
written by Visual C++, I just added "cout << "This is a test!" ".

Answer's too long to include here (although it's likely that others will
provide technically inaccurate and misleading short answers);

You mean like:

// in main() or ?

MessageBox( 0, "This is a test!", "Hello World",
MB_OK | MB_ICONINFORMATION );
 
J

James Kanze

When I start a "Win32 Project" [...]
It's a sad feature of MS Windows: when a program uses GUI, output to console
is hidden. The same happens with Java Swing programs.

Are you kidding? When I was developping a Java Swing
application under Windows, we regularly output debugging
messages to the standard out or standard error. No problem.

Alf's got an exceptionally good page on this; regretfully, I
don't have the URL on this machine, but maybe he'll cite it
again for us. I'd consider it required reading for anyone doing
Windows programming.
 

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

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top