シリアルポートにアクセスするためのコードをVisualC++で記述しています。
コードを以下に示します:-
#include<stdio.h>
#include<cstring>
#include<string.h>
#include<conio.h>
#include<iostream>
using namespace std;
//#include "stdafx.h"
#ifndef __CAPSTONE_CROSS_SERIAL_PORT__
#define __CAPSTONE_CROSS_SERIAL_PORT__
HANDLE hSerial= CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hSerial==INVALID_HANDLE_VALUE)
{
if(GetLastError()==ERROR_FILE_NOT_FOUND){
//serial port does not exist. Inform user.
}
//some other error occurred. Inform user.
}
上記のコードでは、行にある場合にエラーが発生します
if(hserial==INVALID_HANDLE_VALUE)
エラーは以下のとおりです。-
Error:expected a declaration
ifステートメントの最後にある両方の中括弧で同じエラーが発生します}
このエラーが発生する理由とその解決方法を知りたい