Jump to content
  • Advertisement
Sign in to follow this  
JonBMN

Serial C++ help!

This topic is 2122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having trouble with my program to simply open the serial port COM4. any help would be appreciated.


#define STRICT
#define _AFXDLL
#include "stdafx.h"
#include <tchar.h>
#include <AFXWIN.H>
#include <windows.h>
#include "Serial\Serial\Serial.h"
#include "Serial\Serial\SerialEx.h"
#include "Serial\Serial\SerialMFC.h"
#include "Serial\Serial\SerialWnd.h"
int WINAPI_tWinMain
(
HINSTANCE //hInst
HINSTANCE //hInstPrev
int
)
{
CSerial serial;

serial.Open(_T("COM4"));

serial.Setup (CSerial::EBaud9600, CSerial::EData8, CSerial::EParNone, CSerial::EStop1);
CSerial::SetupHandshaking;
serial.Write("Hello World");

serial.Close();
return 0;
}


along with the error code..

1>------ Build started: Project: SerialComm, Configuration: Debug Win32 ------
1> stdafx.cpp
1> SerialWnd.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.cpp(23): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.cpp(24) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.h(25): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> SerialEx.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.cpp(23): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.cpp(24) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.h(26): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> Serial.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serial.h(22): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> SerialComm.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(2): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(5) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(3): warning C4603: '_AFXDLL' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(5) : use of precompiled header
1>c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
1> Serial.cpp
1>c1xx : fatal error C1083: Cannot open source file: '..\Serial\Serial\Serial.cpp': No such file or directory
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Advertisement
None of these errors seem to be related to working with the serial port. Your precompiled headers seem to be messed up. Either fix stdafx.h or remove the include and switch them off in the compile settings. You also seem to be trying to link MFC statically while using the dynamic runtime. Do you actually need MFC at all in the first place?

Share this post


Link to post
Share on other sites
#include "stdafx.h" needs to be the first line in any source file if you are using a precompiled header. Anything before that is ignored. Move the two defines down below #include "stdafx.h" or put them in the stdafx.h file instead. Edited by turch

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!