Q
Q
Quad_Tree2014-09-12 17:50:32
C++ / C#
Quad_Tree, 2014-09-12 17:50:32

Why does Visual Studio throw an error when compiling a program for a COM2 connection in C++?

Gives errors starting from the line HANDLE port; . Tell me what to fix:

#include <windows.h>;
#include "stdafx.h";
#include <iostream>;

using namespace std;

HANDLE port;

int main(int argc, _TCHAR* argv[])
{

  int code;

  cout << "DjkC start." << endl;
  cout << "Print number code: ";
  cin >> code;

  if (code == 0) {
    exit;
    return 0;
  }

  if (code == 1) {
    port = CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    if (port == INVALID_HANDLE_VALUE) {
      cout << "Error" << endl;
      ExitProcess(1);
    }

    CloseHandle(port);
  }
}

error C2146: syntax error: missing ";" before identifier "port"
error C4430: missing type specifier - expected int. Note. C++ does not support int by default

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ins52, 2014-10-22
@ins52

try to move this line to the very beginning
#include "stdafx.h";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question