2017-12-29 49 views
0

WindowsのVisual Studio Community 2017でWindows APIを使用してシリアルポートデバイスと通信するC++プログラムを作成しようとしていますコードのこのビットをコンパイルしようとすると、7Windows API構造体(DCB)のオブジェクトを宣言しています - エラーC4430:型指定子がありません - 想定されています

#include <iostream> 
#include <Windows.h> 
#include "stdafx.h" 
#pragma hdrstop 
using namespace std; 

DCB dcb; 

int main() 
{ 
    return 0; 
} 

私はDCB dcb;を指し、これらのエラーを取得:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
error C2146: syntax error: missing ';' before identifier 'dcb' 

The DCB structureは、次のようにWinbase.hで定義されています:あなたは、線の上にプリコンパイル済みヘッダー、何を使用している場合は

typedef struct _DCB { 
    DWORD DCBlength;  /* sizeof(DCB)      */ 
    DWORD BaudRate;  /* Baudrate at which running  */ 
    DWORD fBinary: 1;  /* Binary Mode (skip EOF check) */ 
    DWORD fParity: 1;  /* Enable parity checking   */ 
    DWORD fOutxCtsFlow:1; /* CTS handshaking on output  */ 
    DWORD fOutxDsrFlow:1; /* DSR handshaking on output  */ 
    DWORD fDtrControl:2; /* DTR Flow control    */ 
    DWORD fDsrSensitivity:1; /* DSR Sensitivity    */ 
    DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ 
    DWORD fOutX: 1;  /* Enable output X-ON/X-OFF  */ 
    DWORD fInX: 1;  /* Enable input X-ON/X-OFF   */ 
    DWORD fErrorChar: 1; /* Enable Err Replacement   */ 
    DWORD fNull: 1;  /* Enable Null stripping   */ 
    DWORD fRtsControl:2; /* Rts Flow control    */ 
    DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ 
    DWORD fDummy2:17;  /* Reserved      */ 
    WORD wReserved;  /* Not currently used    */ 
    WORD XonLim;   /* Transmit X-ON threshold   */ 
    WORD XoffLim;   /* Transmit X-OFF threshold  */ 
    BYTE ByteSize;  /* Number of bits/byte, 4-8  */ 
    BYTE Parity;   /* 0-4=None,Odd,Even,Mark,Space */ 
    BYTE StopBits;  /* 0,1,2 = 1, 1.5, 2    */ 
    char XonChar;   /* Tx and Rx X-ON character  */ 
    char XoffChar;  /* Tx and Rx X-OFF character  */ 
    char ErrorChar;  /* Error replacement char   */ 
    char EofChar;   /* End of Input character   */ 
    char EvtChar;   /* Received Event character  */ 
    WORD wReserved1;  /* Fill for now.     */ 
} DCB, *LPDCB;` 
+0

Winbase.h =はWindows.h @stark – stark

+1

:問題ありませんが、 'windows.h'が'含まれますwinbase.h' –

+0

@stark:[ドキュメント]から、(https://msdn.microsoft .com/en-us/library/windows/desktop/aa363214.aspx):* "ヘッダ:Winbase.h(** include Windows.h **)" *。 – IInspectable

答えて

1

#include "stdafx.h" 

(または任意のプリコンパイルのために指定されたヘッダの名前)

は無視されます。

あなたのインクルードを並べ替えて最初に入れてみてください。プリコンパイルと.hファイルの前に発生した

コンパイラ扱い、すべてのコード:

より説明on MSDN、特に重要なのはこれです。 .hファイルに関連付けられた#includeディレクティブの直後にスキップし、.pchファイルに含まれるコードを使用して、filenameの後にすべてのコードをコンパイルします。

+0

他のインクルードを 'stdafx.h'に入れてください。これはプリコンパイルされたヘッダのようなものです。 –

+0

@ JonathanPotter:はい、システムヘッダを 'stdafx.h 'の中に入れるのは良い方法です。ただし、プロジェクトローカルヘッダーの場合は、PCHの利点をすべて無効にするので、間違いなく推奨されます。 –

関連する問題