Code::Blocks Forums

User forums => Help => Topic started by: Culfa on December 30, 2007, 09:39:32 pm

Title: WIN-API - stupid errors.
Post by: Culfa on December 30, 2007, 09:39:32 pm
Hi next problem  :lol:

If I change the code from a WIN32 GUI Application, the compiler says only stupid errors:

My first line:

#include <windows.h>

He says:

syntax error: '+'

line 32:

    /* Use Windows's default colour as the background of the window */

error:

too many characters in constant

But this happens just then, when I change the code in anyway. In a Code::Block Version by a friend, it works without problems.

I use Nightlybuild 24.12.2007
Title: Re: WIN-API - stupid errors.
Post by: Jenna on December 31, 2007, 09:58:34 am
This sounds a liittle bit like a problem with character-encoding. Do you use a special (non-standard) File-Encoding ?
Title: Re: WIN-API - stupid errors.
Post by: Culfa on December 31, 2007, 02:19:12 pm
Eh well... I did no changes in the settings, except the code completition.

Sry but I don't know what u mean
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 02, 2008, 02:58:47 pm
Sry for double post but has noone any idea?
Title: Re: WIN-API - stupid errors.
Post by: diegoreymendez on January 02, 2008, 03:11:13 pm
Could you post the whole code?  Maybe there's something wrong with it...
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 02, 2008, 03:35:19 pm
Code
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Code::Blocks Template Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);

        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;

}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static POINT point;

    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
            point.x = -1; // noch nicht gesetzt deswegen -1
            point.y = -1;

            return 0;
        case WM_RBUTTONDOWN: // wenn Rechte Maustaste gedrückt wurde
            InvalidateRect(hwnd, NULL, TRUE); // alles neuzeichen
            return 0;

        case WM_LBUTTONDOWN:
            {
                HDC hdc = GetDC(hwnd);
                {
                    SetPixel(hdc, LOWORD(lParam), HIWORD(lParam),RGB( rand()%256, rand()%256, rand()%256));
                }
                ReleaseDC(hwnd,hdc);

                point.x = LOWORD(lParam);
                point.y = HIWORD(lParam);
                return 0;
            }

        case WM_LBUTTONUP:
            {
                if(point.x != -1)
                {
                    HDC hdc = GetDC(hwnd);
                        MoveToEx(hdc, point.x, point.y, NULL);
                        LineTo(hdc,LOWORD(lParam),HIWORD(lParam));
                    ReleaseDC(hwnd, hdc);
                point.x = -1;
                point.y = -1;
                }

                return 0;
            }


        case WM_DESTROY:

            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

Errors:

Quote
-------------- Build: Debug in ddds ---------------

main.cpp
main.cpp(1) : error C2059: syntax error : '+'
main.cpp(30) : error C2332: 'class' : missing tag name
main.cpp(32) : error C2001: newline in constant
main.cpp(32) : error C2015: too many characters in constant
main.cpp(35) : error C2332: 'class' : missing tag name
main.cpp(39) : error C2001: newline in constant
main.cpp(39) : error C2015: too many characters in constant
main.cpp(43) : error C2653: 'Code' : is not a class or namespace name
main.cpp(83) : error C2143: syntax error : missing ';' before '.'
main.cpp(83) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2065: 'hwnd' : undeclared identifier
main.cpp(88) : error C2065: 'NULL' : undeclared identifier
main.cpp(88) : error C2065: 'TRUE' : undeclared identifier
main.cpp(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2078: too many initializers
main.cpp(88) : error C2143: syntax error : missing ';' before '+'
main.cpp(92) : error C2059: syntax error : '+'
main.cpp(105) : error C2059: syntax error : '+'
main.cpp(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(122) : error C2143: syntax error : missing ';' before '+'
main.cpp(124) : error C2059: syntax error : '/'
main.cpp(124) : error C2001: newline in constant
main.cpp(124) : error C2015: too many characters in constant
Process terminated with status 2 (0 minutes, 6 seconds)
23 errors, 0 warnings
Title: Re: WIN-API - stupid errors.
Post by: stahta01 on January 02, 2008, 10:08:02 pm
Which Compiler are you using?
Do you have the search directory setup right?
Looks like it is not finding <windows.h>

I would turn on full compiler logging.
And post the results.

Tim S


Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 03, 2008, 04:01:48 pm
I use Visual Studio 2008 by MS.

(http://img176.imageshack.us/img176/5632/unbenanntyk7.jpg)

This is the search directory setup.

But what do you mean with "full compiler logging"? I find it nowhere in the compiler settings.
Title: Re: WIN-API - stupid errors.
Post by: MortenMacFly on January 03, 2008, 04:17:39 pm
But what do you mean with "full compiler logging"? I find it nowhere in the compiler settings.
Read my sig... ;-)
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 03, 2008, 04:28:36 pm
Lol thx^^


-------------- Build: Debug in ddds ---------------

cl.exe /nologo /W3  /Zi /D_DEBUG    /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\include" /I"C:\Programme\Microsoft Visual Studio 9.0\VC\include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Lib"  /c main.cpp /Foobj\Debug\main.obj
main.cpp
main.cpp(1) : error C2059: syntax error : '+'
main.cpp(30) : error C2332: 'class' : missing tag name
main.cpp(32) : error C2001: newline in constant
main.cpp(32) : error C2015: too many characters in constant
main.cpp(35) : error C2332: 'class' : missing tag name
main.cpp(39) : error C2001: newline in constant
main.cpp(39) : error C2015: too many characters in constant
main.cpp(43) : error C2653: 'Code' : is not a class or namespace name
main.cpp(83) : error C2143: syntax error : missing ';' before '.'
main.cpp(83) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2065: 'hwnd' : undeclared identifier
main.cpp(88) : error C2065: 'NULL' : undeclared identifier
main.cpp(88) : error C2065: 'TRUE' : undeclared identifier
main.cpp(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2078: too many initializers
main.cpp(88) : error C2143: syntax error : missing ';' before '+'
main.cpp(92) : error C2059: syntax error : '+'
main.cpp(105) : error C2059: syntax error : '+'
main.cpp(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(122) : error C2143: syntax error : missing ';' before '+'
main.cpp(124) : error C2059: syntax error : '/'
main.cpp(124) : error C2001: newline in constant
main.cpp(124) : error C2015: too many characters in constant
Process terminated with status 2 (0 minutes, 4 seconds)
23 errors, 0 warnings
 
Title: Re: WIN-API - stupid errors.
Post by: MortenMacFly on January 03, 2008, 04:38:47 pm
Lol thx^^
Although it's hard to believe that these errors come from this file, try to create a new C - project, rename the main.cpp to main.c, add it to the project and try again.
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 03, 2008, 04:48:44 pm
Doesn't work. Again the same errors :-/

Maybe it's important: I tried once this: I deleted all files, belonging to the nightly build, and extracted all again, but there are the same settings as it was in the nightly build before... But these archives are downloaded from this page.
Title: Re: WIN-API - stupid errors.
Post by: MortenMacFly on January 03, 2008, 04:59:18 pm
but there are the same settings as it was in the nightly build before...
Well... try removing the settings file then.
What Encoding do you have (Settings -> Editor -> General Settings -> Default Encoding... and on the bottom status line of C::B for the current file - main.c)?
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 03, 2008, 05:09:47 pm
Quote
What Encoding do you have (Settings -> Editor -> General Settings -> Default Encoding...

UTF-7

Quote
and on the bottom status line of C::B for the current file - main.c)?

xD Sry for this stupid question, but where is that?^^ :oops:

On the bottom is: UTF-7 Line 1, Column 1, Insert, Read/Write, defualt
Title: Re: WIN-API - stupid errors.
Post by: Biplab on January 03, 2008, 05:36:34 pm
Quote
What Encoding do you have (Settings -> Editor -> General Settings -> Default Encoding...

UTF-7

Try changing it to UTF-8 / Windows-1252.

Quote
and on the bottom status line of C::B for the current file - main.c)?

xD Sry for this stupid question, but where is that?^^ :oops:

On the bottom is: UTF-7 Line 1, Column 1, Insert, Read/Write, defualt

If you save the file in UTF-8 then save it with BOM. Click Edit > File encoding > Save byte-order-mark (BOM) to save BOM. MS compiler expect files with BOM and may fail to compile in some cases.
Title: Re: WIN-API - stupid errors.
Post by: MortenMacFly on January 03, 2008, 05:39:51 pm
On the bottom is: UTF-7 Line 1, Column 1, Insert, Read/Write, defualt
Looks good - that's the status line.

I can reproduce if I set the encoding to UTF-7. Ok - so in order fto fix this please choose a different (e.g. "default") encoding and it'll work.
Title: Re: WIN-API - stupid errors.
Post by: MortenMacFly on January 03, 2008, 05:42:05 pm
Try changing it to UTF-8 / Windows-1252.
Aaaah - the unicode master is on-line. ;-) This is a strange issue. If you copy/paste the content of this file into a "usual" encoded one it works. Then if you choose Edit > file encoding -> UTF-7 and save the file it will stop working. The reason is that the content now looks like this (the first lines...):
Code
+ACM-include +ADw-windows.h+AD4-

/+ACo-  Declare Windows procedure  +ACo-/
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM)+ADs-

/+ACo-  Make the class name into a global variable  +ACo-/
char szClassName+AFs- +AF0- +AD0- +ACI-CodeBlocksWindowsApp+ACIAOw-
Is that how it should look like, Biplab? ...or did we find an error, possibly?!
Edit: Answering myself: Yepp, looks like proper UTF-7. But: If you close the editor and re-open it it is not detected as UTF-7. Thus you see the +AC... in C::B. That is no good.

With regards, Morten.
Title: Re: WIN-API - stupid errors.
Post by: Biplab on January 03, 2008, 05:58:32 pm
Try changing it to UTF-8 / Windows-1252.
Aaaah - the unicode master is on-line. ;-) This is a strange issue. If you copy/paste the content of this file into a "usual" encoded one it works. Then if you choose Edit > file encoding -> UTF-7 and save the file it will stop working. The reason is that the content now looks like this (the first lines...):
Code
+ACM-include +ADw-windows.h+AD4-

/+ACo-  Declare Windows procedure  +ACo-/
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM)+ADs-

/+ACo-  Make the class name into a global variable  +ACo-/
char szClassName+AFs- +AF0- +AD0- +ACI-CodeBlocksWindowsApp+ACIAOw-
Is that how it should look like, Biplab? ...or did we find an error, possibly?!
Edit: Answering myself: Yepp, looks like proper UTF-7. But: If you close the editor and re-open it it is not detected as UTF-7. Thus you see the +AC... in C::B. That is no good.

With regards, Morten.

I'd rather blame it on encoding detection and conversion routine. There is no code to handle UTF-7 encoding unless the fallback code detects it and converts it. For the time being you should avoid using this encoding. :)

I'll investigate it this weekend.

Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 03, 2008, 06:54:58 pm
Ahhhh .... :) It works now :) I changed the File Encoding to WINDOWS 1252 and it works perfect:) There are only "normal" errors^^

Big thanks to all :)

Thread can be close
Title: Re: WIN-API - stupid errors.
Post by: Culfa on January 04, 2008, 01:21:05 pm
OK... I started today C::B once more, but now, there are the stupid errors again... I changed the file encoding to UTF-8, saved, with BOM, than to WINDOWS-1252, and then to default. But there are again the stupid errors -.-


-------------- Build: Debug in newone ---------------

cl.exe /nologo /W3  /Zi /D_DEBUG    /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\include" /I"C:\Programme\Microsoft Visual Studio 9.0\VC\include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Lib"  /c fenstercreate.cpp /Foobj\Debug\fenstercreate.obj
fenstercreate.cpp
fenstercreate.cpp(1) : error C2059: syntax error : '+'
fenstercreate.cpp(3) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(6) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(6) : error C2589: '+' : illegal token on right side of '::'
fenstercreate.cpp(9) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(36) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(49) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(79) : error C2653: 'cGame' : is not a class or namespace name
fenstercreate.cpp(90) : error C2653: 'cGame' : is not a class or namespace name
Process terminated with status 2 (0 minutes, 0 seconds)
9 errors, 0 warnings

What can I do now?

edit: Lol after a lot of changing of the default encoding, it works now. But C::B does not save the Settings...  :?