2010-09-02 51 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 solo un archivo .c en el proyecto. Aquí está el código:C2061 Error de sintaxis (identificador)

#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; 
} 

Línea 51 es

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

Este error puede deberse a archivos de encabezado mutuamente dependientes. – Grault

Respuesta

8

bool no es un tipo C.

Sospecho BOOL se define en alguna parte.

Igual va para el uso de true y false.

+0

No puedo creer lo extraño, estaba haciendo C++ justo antes de comenzar esto, gracias. –

+0

@ guitar-: No se olvide de aceptar la respuesta correcta – abatishchev

+0

C99 tiene 'bool' en todo su esplendor. Un buen enlace en Windows y sus booleanos (y versiones similares) está aquí: http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx – dirkgently

7

En realidad, bool es un tipo válido (bueno, una macro en realidad) en el estándar C99, suponiendo que está utilizando un compilador reciente. Es necesario añadir:

#include <stdbool.h> 

Tenga en cuenta que bool no es válida en la mayor ANSI, C89, C90, etc variantes de las normas C.


Como se destacó por JeremyP en los comentarios, compilador de C de Microsoft todavía tiene falta de apoyo adecuado para las características de C99.

Lo que deja tres alternativas:

  1. tratarlo como C++, no C; debido a que C++ tiene bool como un tipo incorporado
  2. Crear su propio bool aplicación
  3. Vuelva a escribir el código para evitar el uso de bool

Para la opción 2 algo como esto iba a funcionar, pero es un trabajo feo -mediante:

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

No está usando un compilador reciente, está usando Microsoft Visual C que no es compatible con C99. – JeremyP

+0

Buen punto. Supuse que Microsoft lo habría agregado en algún momento de la última década, pero parecen (después de leerlo un poco) ignorar C99, en lugar de centrar sus esfuerzos en C++ 0x. – Simon

Cuestiones relacionadas