2010-09-02 13 views
6
1>cb.c(51): error C2061: syntax error : identifier 'SaveConfiguration' 
1>cb.c(51): error C2059: syntax error : ';' 
1>cb.c(51): error C2059: syntax error : 'type' 
1>cb.c(52): error C2061: syntax error : identifier 'LoadConfiguration' 
1>cb.c(52): error C2059: syntax error : ';' 
1>cb.c(52): error C2059: syntax error : 'type' 
1>cb.c(122): error C2061: syntax error : identifier 'SaveConfiguration' 
1>cb.c(122): error C2059: syntax error : ';' 
1>cb.c(122): error C2059: syntax error : 'type' 
1>cb.c(127): error C2061: syntax error : identifier 'LoadConfiguration' 
1>cb.c(127): error C2059: syntax error : ';' 
1>cb.c(127): error C2059: syntax error : 'type' 
1> 
1>Build FAILED. 

Es ist nur eine einzelne C-Datei im Projekt. Hier ist der Code:C2061 Syntax Fehler (Bezeichner)

#define WIN32_LEAN_AND_MEAN 

#include <Windows.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <process.h> 
#include <tchar.h> 

typedef struct _Configuration 
{ 
    int    KeyActivate; 
    int    BlockWidth; 
    int    BlockHeight; 
    double   HueStart; 
    double   HueEnd; 
    double   SaturationStart; 
    double   SaturationEnd; 
    double   ValueStart; 
    double   ValueEnd; 
} Configuration; 

typedef struct _DIBSection 
{ 
    HDC  ScreenDC; 
    HDC  WindowDC; 
    HDC  MemoryDC; 
    HBITMAP ScreenBMPHandle; 
    BITMAP ScreenBMP; 
} DIBSection; 

typedef struct _Thread 
{ 
    HANDLE  Handle; 
    unsigned Id; 
} Thread; 

typedef struct _Window 
{ 
    HANDLE Handle; 
    HDC  DC; 
    int  Width; 
    int  Height; 
    int  Top; 
    int  Left; 
} Window; 

__declspec (dllexport) int Initialize (void); 
unsigned __stdcall Start (void * Arguments); 

void LoadDefaultConfiguration (Configuration * Config); 
bool SaveConfiguration (Configuration * Config, LPTSTR FilePath); 
bool LoadConfiguration (Configuration * Config, LPTSTR FilePath); 

Thread   MainThread; 
Window   Screen; 
Configuration Settings; 

BOOL WINAPI DllMain (HINSTANCE Instance, DWORD Reason, LPVOID Reserved) 
{ 
    switch (Reason) 
    { 

     case DLL_PROCESS_ATTACH: 

      // TODO: Load settings from file 
      LoadDefaultConfiguration (& Settings); 

      // Create main thread 
      MainThread.Handle = (HANDLE) _beginthreadex (
       NULL, 
       0, 
       Start, 
       NULL, 
       0, 
       & MainThread.Id 
       ); 

      if (MainThread.Handle) 
      { 
       SetThreadPriority (MainThread.Handle, THREAD_PRIORITY_BELOW_NORMAL); 
      } 
      else 
      { 
       MessageBox (NULL, L"Unable to create main thread; exiting", L"Error", MB_OK); 
       ExitProcess (0); 
      } 

      break; 

     case DLL_PROCESS_DETACH: 

      break; 

    } 

    return TRUE; 
} 

__declspec (dllexport) int Initialize (void) 
{ 
    return 1; 
} 

unsigned __stdcall Start (void * Arguments) 
{ 
    return 1; 
} 

void LoadDefaultConfiguration (Configuration * Config) 
{ 
    Config->BlockHeight = 50; 
    Config->BlockWidth = 100; 
    Config->HueEnd = 0.00; 
    Config->HueStart = 0.00; 
    Config->KeyActivate = VK_SHIFT; 
    Config->SaturationEnd = 0.00; 
    Config->SaturationStart = 0.00; 
    Config->ValueEnd = 0.00; 
    Config->ValueStart = 0.00; 
} 

bool SaveConfiguration (Configuration * Config, LPTSTR FilePath) 
{ 
    return true; 
} 

bool LoadConfiguration (Configuration * Config, LPTSTR FilePath) 
{ 
    return true; 
} 

Zeile 51 ist

bool SaveConfiguration (Configuration * Config, LPTSTR FilePath); 
+0

Dieser Fehler kann durch gegenseitig abhängige Header-Dateien verursacht werden. – Grault

Antwort

8

bool ist kein C-Typ.

Ich vermute, BOOL ist irgendwo definiert.

Gleiches gilt für die Verwendung von true und false.

+0

Ich kann nicht glauben, dass ich das verpasst habe, ich habe C++ gemacht, kurz bevor ich damit angefangen habe, danke. –

+0

@ gitarre-: Vergessen Sie nicht, die richtige Antwort zu akzeptieren – abatishchev

+0

C99 hat 'bool' in seiner ganzen Pracht. Ein guter Link zu Windows und seinen Booleans (und Lookalikes) ist hier: http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx – dirkgently

7

Eigentlich ist bool ein gültiger Typ (na ja, ein Makro tatsächlich) im C99-Standard, vorausgesetzt, Sie verwenden einen aktuellen Compiler. Sie müssen hinzufügen:

#include <stdbool.h> 

Beachten Sie, dass bool in der älteren ANSI, C89 nicht gültig ist, C90 usw. Varianten der C-Normen.

Wie von JeremyP in den Kommentaren hervorgehoben, fehlt dem C-Compiler von Microsoft noch die richtige Unterstützung für C99-Features.

Welche drei Alternativen lässt:

  1. behandeln es als C++, nicht C; weil C++ hat bool als eine Art
  2. Ihre eigene bool Implementierung
  3. neu schreiben den Code zu vermeiden, mit bool

Für Option 2 so etwas wie dies funktionieren würde, aber es ist eine hässliche Arbeit Create-in gebaut -around:

typedef short bool; 
#define true 1 
#define false 0 
+1

Er verwendet keinen neuen Compiler, den er benutzt Microsoft Visual C, das C99 nicht unterstützt. – JeremyP

+0

Guter Punkt. Ich hatte angenommen, dass Microsoft es irgendwann im letzten Jahrzehnt hinzugefügt hätte, aber sie erscheinen (nachdem sie etwas gelesen haben), C99 zu ignorieren und konzentrieren sich stattdessen auf C++ 0x. – Simon

Verwandte Themen