Archived

This topic is now archived and is closed to further replies.

com

Old style function header and 3 missing ";" before "}"?

Recommended Posts

Im on my last six errors before (hopefully) i can run it; ive got 3 missing fuction header (old style formal list) and strangly 3 missing ";" before "}" on the same line? I have gone over and over my code and cant find where im missing ";" and i dont even understand the old style function header thing. dont want to make you guys count those lines so ill put in those numbers where they are The error: C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(43) : error C2447: missing function header (old-style formal list?) C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(151) : error C2447: missing function header (old-style formal list?) C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing ';' before '}' C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing ';' before '}' C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing ';' before '}' C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(220) : error C2447: missing function header (old-style formal list?) The code: #include <windows.h> #include <stdio.h> #include "resourse.h" char findItem[40]; char enterItemName[40]; char enterComponent[40]; char enterComponent2[40]; char enterComponent3[40]; char enterComponent4[40]; char enterComponent5[40]; char enterComponent6[40]; HINSTANCE g_hInst = NULL; // instance handle HWND g_hwndDlg = NULL; // handle to modeless dlg HWND g_hwndMain = NULL; const char *g_strAppName = "Item Database"; int g_iScreenWidth = 1024; int g_iScreenHeight = 768; HBITMAP g_hBitmap = NULL; HBITMAP g_hOldBitmap = NULL; HDC g_hDCBitmap = NULL; int g_iBitmapWidth = 0; int g_iBitmapHeight = 0; void PaintWindow(HDC hdc) { // set our mapping mode as text. this means 1 logical unit = 1 pixel. SetMapMode(hdc, MM_TEXT); StretchBlt(hdc, 0, 0, g_iScreenWidth, g_iScreenHeight, g_hDCBitmap, 0, 0, g_iBitmapWidth, g_iBitmapHeight, SRCCOPY); } LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); { switch(uMsg) { case WM_CREATE: { HDC hdcWindow = GetDC(hwnd); g_hDCBitmap = CreateCompatibleDC(hdcWindow); g_hBitmap = (HBITMAP)LoadImage(NULL,"background.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); g_hOldBitmap = (HBITMAP)SelectObject(g_hDCBitmap,g_hBitmap); BITMAP bmp; GetObject(g_hBitmap,sizeof(BITMAP),(LPVOID)&bmp); g_iBitmapWidth = bmp.bmWidth; g_iBitmapHeight = bmp.bmHeight; ReleaseDC(hwnd, hdcWindow); g_hwndDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_ITEM), hwnd, DialogProc); ShowWindow(g_hwndDlg, SW_SHOW); break; } break; case WM_DESTROY: { SelectObject(g_hDCBitmap, g_hOldBitmap); DeleteObject(g_hBitmap); DeleteDC(g_hDCBitmap); } break; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); HDC hdc = ps.hdc; PaintWindow(hdc); EndPaint(hwnd, &ps); } return(0); case WM_CLOSE: PostQuitMessage(0); return(0); case WM_SIZE: g_iScreenWidth = LOWORD(lParam); g_iScreenHeight = HIWORD(lParam); return(DefWindowProc(hwnd, uMsg, wParam, lParam)); break; } return(DefWindowProc(hwnd, uMsg, wParam, lParam)); } HWND InitWindow(HINSTANCE hinst, int nCmdShow) { HWND hwnd; WNDCLASSEX wc; memset(&wc, 0, sizeof(wc)); wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; // change this to NULL and crash wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinst; wc.hIcon = NULL; wc.hIconSm = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; // don't repaint background. this kills flicker. wc.lpszMenuName = NULL; wc.lpszClassName = "Item_database"; RegisterClassEx(&wc); hwnd = CreateWindowEx(0, "Item_Database", g_strAppName, WS_POPUP | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 10, 10, g_iScreenWidth, g_iScreenHeight, NULL, NULL, hinst, NULL); if (!hwnd) { ::MessageBox(NULL, "CreateWindow failed!", g_strAppName, MB_ICONSTOP); exit(-1); } ShowWindow(hwnd, nCmdShow); return(hwnd); } BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); { switch(uMsg) { case WM_INITDIALOG: SetFocus(GetDlgItem(hwndDlg, IDC_EDIT1)); return(false); case WM_COMMAND: { WORD idControl = LOWORD(wParam); HWND hwndCtl = (HWND) lParam; } switch(idControl) { case IDCANCEL: DestroyWindow(g_hwndDlg); g_hwndDlg = NULL; PostQuitMessage(0); return(true); } case IDC_FIND: { HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT8); GetWindowText(hwndEdit, findItem, sizeof(findItem)); InvalidateRect(g_hwndMain, NULL, true); } return(true); case IDC_CREATENEW: { HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT1); GetWindowText(hwndEdit, enterItemName, sizeof(enterItemName)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT2); GetWindowText(hwndEdit, enterComponent, sizeof(enterComponent)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT3); GetWindowText(hwndEdit, enterComponent2, sizeof(enterComponent2)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT4); GetWindowText(hwndEdit, enterComponent3, sizeof(enterComponent3)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT5); GetWindowText(hwndEdit, enterComponent4, sizeof(enterComponent4)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT6); GetWindowText(hwndEdit, enterComponent5, sizeof(enterComponent5)); InvalidateRect(g_hwndMain, NULL, true) HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT7); GetWindowText(hwndEdit, enterComponent6, sizeof(enterComponent6)); InvalidateRect(g_hwndMain, NULL, true) } return(true); } } //break was here ** LINE 213! } return(0); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); // LINE 220! { g_hInst = hInstance; g_hwndMain = InitWindow(hInstance, nCmdShow); while (1) { MSG msg; if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { int result = GetMessage(&msg, 0, 0, 0); if (!result) return(msg.wParam); . if (!IsWindow(g_hwndDlg) || !IsDialogMessage(g_hwndDlg, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } return 0; } thx in advance [edited by - com on August 13, 2002 1:22:41 PM] [edited by - com on August 13, 2002 1:26:08 PM]

Share this post


Link to post
Share on other sites
When i put a ";" at the end of the InvalidateRect() calls it created a mess of new errors and strangly the old ones iswell?


C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(38) : error C2143: syntax error : missing '')'' before '';''
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(42) : error C2059: syntax error : '')''
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(43) : error C2447: missing function header (old-style formal list?)
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(121) : 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:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(151) : error C2447: missing function header (old-style formal list?)
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing '';'' before ''}''
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing '';'' before ''}''
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(213) : error C2143: syntax error : missing '';'' before ''}''
C:\Windows\Desktop\Programming Projects\Item_database\windowanddialog.cpp(220) : error C2447: missing function header (old-style formal list?)


Share this post


Link to post
Share on other sites
I think everyone would appreciate your code in the SOURCE tags next time, hmmm?

First, function implementations don''t have semicolons. Line 220 is wrong. It should look like this:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) // NO SEMICOLON
{


There are a few other lines that have this error too. About the rest of your errors, I can''t help you, just because the code is so poorly presented. SOURCE tags would help, and giving ALL error lines a different color or comment label would help. All I can say is so go to the erroraneous lines and read a basic C book. It should cover all the syntax details early on.

quote:
When i put a ";" at the end of the InvalidateRect() calls it created a mess of new errors and strangly the old ones iswell?

And? Don''t be fooled into ignoring syntax errors because they reduce the number of compile errors. Syntax errors could actually be hiding problems because of the way the compiler handles and recovers from such errors.

Share this post


Link to post
Share on other sites
Three of your functions:

WindowProc, DialogProc, and WinMain

All have a ; after their parameter lists but before the definition of the function. Remove the ; and these errors should go away.

What you have is:

WindowProc(...,
...,
...);
{
...
}

What you should have is:

WindowProc(...,
...,
...) // Note no semicolon here
{
...
}

HTH,

Cheers, Dorix

Share this post


Link to post
Share on other sites
Your WinMain has a semicolon after the header.. that caused the old style error (i think).


  
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow); // <-- remove semicolon. only use that for prototyping



That should fix at least one error.. The other errors are just tracing {}''s and ()''s. Just study the code around the problem area... it will help a lot in future debugging.

Share this post


Link to post
Share on other sites