Advertisement

Unexpected End of File? AHHHHHH!

Started by March 22, 2000 01:47 PM
6 comments, last by Wilben 24 years, 8 months ago
Hello, Sorry for the slightly unerving, but I''m a beginning Windows preogramer and having spent so much time getting this to work and then finding it gives me this error is a little agravating. Here is my code for the main .cpp file: #include "WPWin.h" #include /*----------------------------------------------------------------*\ Function: WindowProc(); Purpose: Handles window messages; \*----------------------------------------------------------------*/ LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_MOVE: MessageBox(hWnd, "WM_MOVE: The Window Moved", TITLE, MB_OK); return 0; case WM_DESTROY: MessageBox(hWnd, "WM_DESTROY: Exiting Application", "Goodbye!", MB_OK); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int Cmd) { { StartRegWin(); wc.lpfnWndProc = WindowProcedure; EndRegWin(); MakeWin(); if(hWnd==NULL) return FALSE; else { ShowWindow (hWnd, Cmd); UpdateWindow(hWnd); return 0; // Message loop; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage (&msg); } return msg.wParam; } Here is the code for WPWin.h: #include #define TITLE "WinCode" #define WIN32_LEAN_AND_MEAN // Quicker build times; HWND hWnd; MSG msg; WNDCLASS wc; HINSTANCE hInstance; int Cmd; StartRegWin(void) { wc.style =CS_HREDRAW/CS_VREDRAW; wc.cbClsExtra =0; wc.cbWndExtra =0; wc.hInstance =hInstance; wc.hIcon =LoadIcon(hInstance,IDI_APPLICATION); wc.hCursor =LoadCursor(NULL,IDC_ARROW); wc.hbrBackground =(HBRUSH)(COLOR_WINDOW+3); wc.lpszMenuName =NULL; wc.lpszClassName =TITLE; return 0; } EndRegWin(void) { RegisterClass(&wc); return 0; } MakeWin(void) { hWnd = CreateWindow(TITLE, // class name; TITLE, // window name; WS_OVERLAPPEDWINDOW, // window style; CW_USEDEFAULT, CW_USEDEFAULT, // starting position (x,y); 320, 240, // width and height; NULL, // parent handle; NULL, // menu handle; hInstance, // instance handle; NULL); // other parameters; // Check if window creation failed; otherwise show and update; return 0; } I know it seems strange to put the functions in header files, but the aim is these will simplify making windows, (I''ve done one for DirectDraw) as I''m entering them for a competition. When I compile the code I get the error: c:\wintest\simple.cpp(51) : fatal error C1004: unexpected end of file found If someone could help me I would really appreciate it. I''ve turned off pre-compiled header files and from what I can see there are no ''un-closed'' brackets anywhere. Thanks very much, Wilben Wilben wilben@nerdy.freeserve.co.uk
Hello,

Really sorry, but it seems that I somehow (?) didn''t paste in the #include parts of the test, so here they are:
#include "WPWin.h"
#include
(For the .cpp)
#include
(for the header file)

Sorry,

Wilben

Wilben
wilben@nerdy.freeserve.co.uk
Advertisement
Jsut browsed through it in a minute but I noticed these lines:

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int Cmd) {
{

Take away one of the brackets..

And there is a bracket missing in your else statement...
I think you should take away the else statement completely. But your return is before you message loop so your program won't get there!

Edited by - Geradian on 3/22/00 1:56:50 PM

Edited by - Geradian on 3/22/00 1:58:07 PM
Yeah, any time you get that error (or at least just about any time), it means that either you have one too many curly braces or not enough, so start lookin

BTW, it would be cool if MS would add something to VC++ like they have in CodeWarrior where when you type an end bracket it highlites the one it coresponds with and it beeps if you have an extra one (I think, last time I used CodeWarrior was last year in school)...

If you code it, they will come...

Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
In MSVC if you press ctrl-] when your cursor is next to a { or a } it will take you to the matching one. It would be nice if it would hilight while you are typing but this work around is useful.

- Brad Pickering
http://home.earthlink.net/~uubp/
Home for organically grown games
- Brad Pickeringhttp://home.earthlink.net/~uubp/Home for organically grown games
By the way, the #define WIN32_LEAN_AND_MEAN has to go before your #include <windows.h> otherwise it has no effect. What it does is tell the compiler to ignore a chunk of that header file (which loads in an extra set of header files) and so that must be defined before the preprocessor gets as far as Windows.h. Personally I define WIN32_LEAN_AND_MEAN in my project settings and that seems to be ok and saves me having to remember to type it.
Advertisement
you can also get those if you have:
#if

and no
#endif
match
-PoesRaven
Hello,

Thanks so very much for the help. I haven''t tested it yet, but I''m sure it will work, so thanks. Anyway, why Microsoft didn''t think of that before I don''t know, or maybe that would make things too easy for us, mm?

Wilben

Wilben
wilben@nerdy.freeserve.co.uk

This topic is closed to new replies.

Advertisement