newbie error
when i´m going to compile my first program,i get 2 errors:
error C2065: ''nCmdShow'' : undeclared identifier
error C2447: missing function header (old-style formal list?)
anybody knows why i get this messages?
Post some code. Your compiler should give you the lines where you got the error; post those lines. Also post the full error line and tell us more about your development environment (compiler/IDE, platform - Win32 Application or Win32 Console Application, etc).
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static char szAppName[]="Win32Base";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =0;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =szAppName;
if(!RegisterClass(&wndclass)) return 0;
hwnd = CreateWindow(szAppName,
"Programa base en Windows 32 bits",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{ TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam);
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DegWindowProc(hwnd,message,wParam,lParam);
}
}
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(47) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
Error executing cl.exe.
here you got the whole program an all the errors,i´ve been able to put in order the indelcared identifier error.I use Microsoft Visual C++, in Windows 98.I don´t know what kind of program to do, win32 application or win32 console application.
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static char szAppName[]="Win32Base";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =0;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =szAppName;
if(!RegisterClass(&wndclass)) return 0;
hwnd = CreateWindow(szAppName,
"Programa base en Windows 32 bits",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{ TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam);
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DegWindowProc(hwnd,message,wParam,lParam);
}
}
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(47) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
c:\archivos de programa\microsoft visual studio\myprojects\win32base\win32base.cpp(59) : error C2143: syntax error : missing '';'' before ''}''
Error executing cl.exe.
here you got the whole program an all the errors,i´ve been able to put in order the indelcared identifier error.I use Microsoft Visual C++, in Windows 98.I don´t know what kind of program to do, win32 application or win32 console application.
Your error messages are essentially saying this:
error C2065: 'nCmdShow' : undeclared identifier
This states that you have a undeclared variable, so you should declare it where it is appropriate. (i.e. int nCmdShow = 0; )
error C2447: missing function header (old-style formal list?)
You haven't declared the WndProc properly...
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam);
{
remove the ';'.
[edit: changed "(i.e. int nCmdShow = 0" so it displays properly]
Edited by - sp00nfed on September 23, 2001 9:41:22 AM
error C2065: 'nCmdShow' : undeclared identifier
This states that you have a undeclared variable, so you should declare it where it is appropriate. (i.e. int nCmdShow = 0; )
error C2447: missing function header (old-style formal list?)
You haven't declared the WndProc properly...
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam);
{
remove the ';'.
[edit: changed "(i.e. int nCmdShow = 0" so it displays properly]
Edited by - sp00nfed on September 23, 2001 9:41:22 AM
nCmdShow is a command line parameter. If you launch your application from within MSVC, it is never defined. Replace the reference to nCmdShow in ShowWindow() with one of the defined SW_xxx constants:
Remove the semicolon at the end of the definition of your WndProc(). Also, the final statement should be DefWindowProc() , not DegWindowProc():
ShowWindow(hwnd, SW_SHOW);
Remove the semicolon at the end of the definition of your WndProc(). Also, the final statement should be DefWindowProc() , not DegWindowProc():
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam){ switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } default: break; // sometimes MSVC will bitch if you don''t have a default label } return DefWindowProc(hwnd,message,wParam,lParam);}
when i create a windows 32 application, i get a message and i can choose between an empty project, a simple 32 windows application and a typicall "Hello World!" application.Which of this options should i choose and what´s the diference between them?
An empty project has no files or code in it; you need to manually add everything - source and headers, icons, bitmaps and other resources, etc.
A simple Win32 application contains an empty WinMain(), which you will need to fill out and add all the necessary code. It also places the necessary headers in stdafx.h if you choose to enable precompiled headers (PCH).
A typical "Hello World" (for Win32) simply has a MessageBox with "Hello World" on it and an OK button, I believe. It also includes standard headers in stdafx.h.
There''s very little difference between the three; I usually take the simple Win32 application and modify. The project wizards only really become useful with MFC applications.
A simple Win32 application contains an empty WinMain(), which you will need to fill out and add all the necessary code. It also places the necessary headers in stdafx.h if you choose to enable precompiled headers (PCH).
A typical "Hello World" (for Win32) simply has a MessageBox with "Hello World" on it and an OK button, I believe. It also includes standard headers in stdafx.h.
There''s very little difference between the three; I usually take the simple Win32 application and modify. The project wizards only really become useful with MFC applications.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement