-
Man This Stinks
Could ne one help me here? im now gettin into windows API, and I tried to manually debug it, but I cannot snatch the error. help ne one?
Here it is:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hWindow, UNIT iMessage, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS kWndClass;
kWndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
kWndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
kWndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
kWndClass.hInstance = hInstance;
kWndClass.lpfnWndProc = WndProc;
kWndClass.lpszClassName = "Alex's Window";
kWndClass.lpszMenuName = NULL;
kWndClass.cbClsExtra = NULL;
kWndClass.cbWndExtra = NULL;
kWndClass.style = NULL;
if (!RegisterClass (&kWndClass))
{
return -1;
}
HWND hWindow;
hWindow = CreateWindow ("Alex's Window", "A Blank Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
MSG kMessage;
while (GetMessage (&kMessage, hWindow, 0, 0))
{
TranslateMessage (&kMessage);
DispatchMessage (&kMessage)
}
return 0;
}
LRESULT CALLBACK WndProc (HWND hWindow, UNIT iMessage, WPARAM wParam, LPARAm lParam)
{
switch (iMessage)
{
case WM_CLOSE;
POSTQUITMESSAGE (0);
break;
default:
return DefWindowProc (hWindow, iMessage, wParam, lParam);
}
return 0;
}
I'd Appreciate any help! thanks ohh and here are the errors....
--------------------Configuration: Window - Win32 Debug--------------------
Compiling...
Window S.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(3) : error C2061: syntax error : identifier 'UNIT'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(14) : error C2440: '=' : cannot convert from 'long (__stdcall *)(struct HWND__ *)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(37) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(42) : error C2061: syntax error : identifier 'UNIT'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(44) : error C2065: 'iMessage' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(46) : error C2143: syntax error : missing ':' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(47) : error C2065: 'POSTQUITMESSAGE' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(51) : error C2065: 'wParam' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(51) : error C2065: 'lParam' : undeclared identifier
Error executing cl.exe.
Window.exe - 9 error(s), 0 warning(s)
-
instead of UNIT try UINT where you declare the WndProc procedure...
-
I could solve every error for you, but that would be of little use to you.
First I recommend you walk through your app and search for missing ; or places where you confused : and ;
I see two errors coming from that.
Then you should correct the error Arawn pointed out. UINT is an abbreviation for unsigned integer.
Next check case. C++ is case sensitive and names of the windows API follow a simple case scheme: types and constants are all capitals (1 error) and functions start with a capital and each word in them also starts with a capital (1 error).
The remaining errors (2) are follow-ups.
-
Alright, thaks guys, I appreciate it
-
And please always place your code here between code tags:
[code] Your code here [/code]
It makes it easier to read since the code is posted exactely (formatting) as you wrote it, and it makes it easier to see in a glance what's code and what not.
-
Ok thanks guys, im down to 1 error, and im guessing its the function begining not begining with a capital, but where?????
Code:
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(43) : error C2447: missing function header (old-style formal list?)
-
What are the lines around line 43? And 43 itself too of course.
-
Could it be that you added a ; here?
Code:
}
LRESULT CALLBACK WndProc (HWND hWindow, UNIT iMessage, WPARAM wParam, LPARAm lParam) <--
{
switch (iMessage)
-
I erased it and still has one error of the header ****ing old style
-
Show me your new code.
And mark the line where the error occurs.
-
alright here:
Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS kWndClass;
kWndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
kWndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
kWndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
kWndClass.hInstance = hInstance;
kWndClass.lpfnWndProc = WndProc;
kWndClass.lpszClassName = "Alex's Window";
kWndClass.lpszMenuName = NULL;
kWndClass.cbClsExtra = NULL;
kWndClass.cbWndExtra = NULL;
kWndClass.style = NULL;
if (!RegisterClass (&kWndClass))
{
return -1;
}
HWND hWindow;
hWindow = CreateWindow ("Alex's Window", "A Blank Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
MSG kMessage;
while (GetMessage (&kMessage, hWindow, 0, 0))
{
TranslateMessage (&kMessage);
DispatchMessage (&kMessage);
}
return 0;
}
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
{
switch (iMessage)
{
case WM_CLOSE;
POSTQUITMESSAGE (0);
break;
default:
return DefWindowProc (hWindow, iMessage, wParam, lParam)
}
return 0;
}
It dose not really tell me where but once I saw a bue arrow right here:
Code:
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
{
The bracket under the function.
So I dont know if this helped you help me....
Thanks ne way.
-
Code:
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
{
Remove the ; like CornedBee has told you.
Code:
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
-
that generates 5 more errors and like 1 warning:
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(45) : warning C4060: switch statement contains no 'case' or 'default' labels
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(47) : error C2143: syntax error : missing ':' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(47) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(48) : error C2065: 'POSTQUITMESSAGE' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(49) : error C2143: syntax error : missing ';' before 'break'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(49) : error C2043: illegal break
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(51) : error C2047: illegal default
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(53) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.
The Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS kWndClass;
kWndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
kWndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
kWndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
kWndClass.hInstance = hInstance;
kWndClass.lpfnWndProc = WndProc;
kWndClass.lpszClassName = "Alex's Window";
kWndClass.lpszMenuName = NULL;
kWndClass.cbClsExtra = NULL;
kWndClass.cbWndExtra = NULL;
kWndClass.style = NULL;
if (!RegisterClass (&kWndClass))
{
return -1;
}
HWND hWindow;
hWindow = CreateWindow ("Alex's Window", "A Blank Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
MSG kMessage;
while (GetMessage (&kMessage, hWindow, 0, 0))
{
TranslateMessage (&kMessage);
DispatchMessage (&kMessage);
}
return 0;
}
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch (iMessage);
{
case WM_CLOSE;
POSTQUITMESSAGE (0)
break;
default:
return DefWindowProc (hWindow, iMessage, wParam, lParam)
}
return 0;
}
I cannot make ne thing of it lol
-
ok never mind, only creates 2 more errors, the other ones were my fault, here are the 2 more:
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(47) : error C2143: syntax error : missing ':' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(48) : error C2065: 'POSTQUITMESSAGE' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Window\Window S.cpp(53) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.
-
Look at the switch in WndProc.
-
-
ok this is really starting to piss me off..... Ok there are 0 errors in building it, but two errors in compieling it! *** god, I hate this compieler.................. and it hates me.. ok here they are:
--------------------Configuration: Window S - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Window S.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Window S.exe - 2 error(s), 0 warning(s)
Ok? some one help? dont tell me you need the code because I posted it only like 6 times above, please help! I need this crap to work!!!!!
-
-
Create a new project that is NOT a Win32 Console Application, but a Win32 Application. Console applications use main as the entry point, Win32 applications use WinMain.
Z.
-
Zaei, it is a win32 app. , not a console, thanks 4 trying tho
-
wait... hold on.... it works!!!!!!!!! YEAH THANKS FINALLY FOR THE SAKE OF GOD!!!!!!!! I thought I made sure it was a win 32 app.
damn....