Author Topic: WIN-API - stupid errors.  (Read 19445 times)

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
WIN-API - stupid errors.
« 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

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: WIN-API - stupid errors.
« Reply #1 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 ?

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #2 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

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #3 on: January 02, 2008, 02:58:47 pm »
Sry for double post but has noone any idea?

Offline diegoreymendez

  • Single posting newcomer
  • *
  • Posts: 3
Re: WIN-API - stupid errors.
« Reply #4 on: January 02, 2008, 03:11:13 pm »
Could you post the whole code?  Maybe there's something wrong with it...

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #5 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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: WIN-API - stupid errors.
« Reply #6 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


C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #7 on: January 03, 2008, 04:01:48 pm »
I use Visual Studio 2008 by MS.



This is the search directory setup.

But what do you mean with "full compiler logging"? I find it nowhere in the compiler settings.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: WIN-API - stupid errors.
« Reply #8 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... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #9 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
 

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: WIN-API - stupid errors.
« Reply #10 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #11 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: WIN-API - stupid errors.
« Reply #12 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)?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Culfa

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: WIN-API - stupid errors.
« Reply #13 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
« Last Edit: January 03, 2008, 05:13:03 pm by Culfa »

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: WIN-API - stupid errors.
« Reply #14 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.
Be a part of the solution, not a part of the problem.