2010-09-02 84 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. 

它只是項目中的一個.c文件。下面的代碼:51C2061語法錯誤(標識符)

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

線是

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

此錯誤可能是由相互依賴的頭文件造成的。 – Grault 2014-11-19 07:45:50

回答

8

bool是不是C型。

我懷疑BOOL是在某處定義的。

同樣適用於truefalse的使用。

+0

不能相信我錯過了,在開始之前我正在做C++,謝謝。 – 2010-09-02 07:15:48

+0

@吉他 - :不要忘記接受正確的答案 – abatishchev 2010-09-02 07:39:30

+0

C99確實擁有所有榮耀中的「bool」。 Windows和它的布爾(以及lookalikes)上的一個很好的鏈接在這裏:http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx – dirkgently 2010-09-02 07:57:34

7

其實,bool在C99標準中是一個有效的類型(實際上是一個宏),假設你使用的是最近的編譯器。您需要添加:

#include <stdbool.h> 

注意bool是不是在舊ANSI,C89有效的C類標準C90等變種。


正如JeremyP在評論中強調的那樣,微軟的C編譯器仍然缺乏對C99特性的適當支持。

就剩下三種選擇:

  1. 把它當作C++,不是C;因爲C++有bool爲內置型
  2. 創建自己的bool實現
  3. 重新編寫代碼來避免使用bool

選項2的像這樣的工作,但它是一個醜陋的工作-around:

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

他沒有使用最近的編譯器,他使用Microsoft Visual C不支持C99。 – JeremyP 2010-09-02 08:05:39

+0

好點。我曾假設微軟會在過去十年中的某個時候添加它,但是他們似乎忽略了C99,而將它們的努力集中在C++ 0x上。 – Simon 2010-09-02 13:30:47

相關問題