Hello! I am trying to open my serial port in a Windows Form Application (Visual C++) however, I'm getting errors! Any help is much appreciated!
gpsProject.cpp
----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
// gpsProject.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
#include <iostream>
#include <windef.h>
#include <WinBase.h>
#include <Windows.h>
#include <string>
using namespace gpsProject;
using namespace System;
using namespace System::Windows::Forms;
using namespace std;
[STAThreadAttribute]
int main()
{
HANDLE myCommPort;
myCommPort = CreateFile("COM3",
GENERIC_READ|GENERIC_WRITE, // access ( read and write)
0, // (share) 0:cannot share the
// COM port
0, // security (None)
OPEN_EXISTING, // creation : open_existing
FILE_FLAG_OVERLAPPED, // we want overlapped operation
0 // no templates file for
// COM port...
);
if (myCommPort == INVALID_HANDLE_VALUE)
cout<<("Error in opening serial port");
else
cout<<("Opening serial port was successful");
CloseHandle(myCommPort);
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
|
1>------ Build started: Project: gpsProject, Configuration: Debug Win32 ------
1>Build started 4/11/2017 9:36:22 PM.
1>InitializeBuildStatus:
1> Touching "Debug\gpsProject.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> All outputs are up-to-date.
1> gpsProject.cpp
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(6361): error C2146: syntax error : missing ';' before identifier 'ContextRecord'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12983): error C2065: 'PCONTEXT' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): error C2146: syntax error : missing ')' before identifier 'ContextRecord'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): warning C4229: anachronism used : modifiers on data are ignored
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): error C2182: 'RtlCaptureContext' : illegal use of type 'void'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): warning C4394: 'RtlCaptureContext' : per-appdomain symbol should not be marked with __declspec(dllimport)
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): error C2491: 'RtlCaptureContext' : definition of dllimport data not allowed
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(12984): error C2059: syntax error : ')'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(13372): error C2143: syntax error : missing ';' before '__stdcall'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(13372): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(13372): warning C4394: 'PCONTEXT' : per-appdomain symbol should not be marked with __declspec(dllimport)
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(13376): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(14982): error C3861: '__readfsdword': identifier not found
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(1048): error C2146: syntax error : missing ';' before identifier 'LPCONTEXT'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(1048): error C2378: 'PCONTEXT' : redefinition; symbol cannot be overloaded with a typedef
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(13372) : see declaration of 'PCONTEXT'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(3610): error C2061: syntax error : identifier 'PCONTEXT'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(4449): error C2061: syntax error : identifier 'LPCONTEXT'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(4457): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(4457): error C2143: syntax error : missing ',' before '*'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(15112): error C2143: syntax error : missing ';' before '__stdcall'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(15112): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\WinBase.h(15116): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.92
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========