Errors + Syntax Q's

Started by
7 comments, last by Tac-Tics 22 years, 2 months ago
I''m starting Windows programming in c++ and I have a few questions. I tried to compile some sample code from my book and it''s giving me some erros.

#include <windows.h>

LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARMA);

int WINAPI WinMain (HINSTANCE hInstance, HINTANCE hPrevInstance,
					PSTR szCommandLine, int iCommandShow)
{
....
}
I hope HTML works here =-) It gives me an error saying "return type expected" for those two lines. Can anyone help me here? Also, why does the code implement that kind of syntax (like "int WINAPI WinMain"). I''m sure there something here I haven''t learned about. "I''''m not evil... I just use the power of good in evil ways."
Advertisement

there are about a billion ways to declare WinMain

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return 0;
}


return type expected means it wants to see a return type somewhere.

the APIENTRY or PASCAL or CALLBACK all set how parameters are pushed on the stack.
quote:Original post by Tac-Tics
Also, why does the code implement that kind of syntax (like "int WINAPI WinMain").


Welcome to the wonderful world of Windows programming.



-------------
SpaceRook
Latest Project: Paper Shredder
Visit my homepage for other projects!
>> return type expected means it wants to see a return type somewhere

Obviously, but aren''t LRESULT and int both the return types it''s asking for?

I also tried your example:

#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return 0;
}

and it''s now giving me an error: "unresolved external ''_main'' referenced from...."

I''ve seen this error a few times and I don''t know what it means.
Why can''t they make this as easy as it is in Java =-(

"I''''m not evil... I just use the power of good in evil ways."
May sound a silly question, but have you declared any of your variables you are passing?
Unifex
@Tac-Tics

Have you chosen the right application for your programm?
(i think wou need win32-app not win32-console-app)


The Wild Wild West - Desperado!
The Wild Wild West - Desperado!
When you created your project you chose console app, which means your compiler is looking for main(), and since this is a windows app, it''s not finding it, and is complaining appropriately.

Recreate your project/workspace and be careful to chose win32 app, not console. it will compile fine then.

In the declaration of fnMessageProcessor you misspelled LPARAM, and in the declaration of WinMain you misspelled HINSTANCE. This probably confuses the parser (though you should have received other errors as well, complaining about the unknown names).
Hrmm... I don''t know where that misspelling came in (I really hate the MS abbriviations for everything >=-( I think I tried compiling it correctly spelled at one point. It''s still giving me the _main reference error.

As for WildWest and AbsoluteDew, I thought I wrote this, but I''m using Borland''s C++ compiler and a text editor called Textpad. I at no point got to decide to make it a console app or a window app =-|

"I''''m not evil... I just use the power of good in evil ways."

This topic is closed to new replies.

Advertisement