Basic Serial Communication Tutorial - Arduino and C++

Hello Community!

I copied this code to my Visual Studio 2010 and followed of course the instructions inTHIS TUTORIAL.

When I tried to compile the code I got the error message:

Serial.cpp(16): error C2664: 'CreateFileW': Konvertierung des Parameters 1 von 'char *' in 'LPCWSTR' nicht möglich

Translated: converting from char* to LPCWSTR is not possible in the CreateFileW which is requested in the Serial.CPP

Google told me a solution:
Change the properties from Unicode to Multibyte Code. -> No problem, BUT, i get a new error message which I don't know how to solve:

LINK : fatal error LNK1287: Ungültiger verwalteter Einstiegspunkt "int __clrcall main(int,char * * const)" (?main@@$$HYMHHQAPAD@Z)

Translated: Not valid Entrypoint in" ... ".

Anyone has an idea what the problem could be?
I researched for similar errors and found this information, but my Visual Studio doesn't report more than mentioned above to me, throughout I hope that maybe the solution is the same.

warning LNK4002: "int __clrcall main(int,char * * const)" (?main@@$$HYMHHQAPAD@Z) defined in Release\INIwriter.obj
warning LNK4022: cannot find unique match for symbol 'main

Please bear in mind, that this Error is not the one I get! May this helps to find the Problem. What about the Release\INIwriter.obj?

My Visual Studio is running in Debug Mode at the moment.

Some additional information:
I have at all now three Serial Connection Codes. Two of them run fine. One of these two had the same problem with the conversion. But setting it to Multibyte-Code helped and since then it works fine.
Why I ask you for support is, that I want this code to run, because upper mentioned tutorial would have helped me a lot, especially it was not hard to find, BUT sadly it doesn't work. Think we should change this.

Change this...

int _tmain(int argc, _TCHAR* argv[])

To this...

int main(int argc,   char* argv[])

Still the same error.

What is the difference?

This is what I did…
• Build a Visual Studio project using the three source files from that link
• Click Project then ArduinoSerial Properties (or press Alt + F7)
• Under Configuration Properties navigate to General
• Change Character Set to Use Multi-Byte Character Set
• Click Build then Rebuild ArduinoSerial

This is the result…

1>ArduinoSerial - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

From what I’ve read, this class works a little better…

Thank you for testing the code!
Got it to work now!

The problem was the “main”.

By accident I saw that, with a precompiled header, which i can’t turn off when I create a "CLR → Windows Formular … ", automatically starts with

int main(array<System::String ^> ^args)

I changed the main, which i copied out of the example to the one in the quote. Yet I don’t know what’s the difference between these three mains, but I think I can change it back to standard main on my own, if it would be neccessary. At all I will ask in the University the Informatics People what the difference is and why it is doin’ this :slight_smile: