Visual Studio 2010 Arduino cpp Error: argument of type "char *" is incompatible with parameter of type "LPCWSTR"

I am trying to configure arduino uno to communicate over a serial port with a C ++ program in visual studio 2010. I work from the code found here: http://playground.arduino.cc/Interfacing/CPPWindows

Unfortunately, the .cpp file gives me the following message for line 9 for the variable 'portName':

Error: argument of type "char *" is incompatible with parameter of type "LPCWSTR"

I do not understand this error message and tried several different actions to fix this. Any help would be greatly appreciated!

+4
source share
3 answers

, :

Serial::Serial(char *portName)
{
    ...

    this->hSerial = CreateFile(portName,  // <--- ERROR

CreateFile - API Win32, LPCTSTR .

LPCTSTR - Win32 typedef, :

  • const char* ANSI/MBCS
  • const wchar_t* Unicode ( VS2005)

VS2010, , Unicode .

"" CreateFile API, : CreateFileA CreateFileW. const char*, const wchar_t*.

Unicode- CreateFile - , CreateFileW; ANSI/MBCS CreateFile CreateFileA.

, Unicode, CreateFile CreateFileW(const wchar_t*, ...). portName char*, wchar_t* char*, .

, .

, CreateFileA() CreateFile(). , ANSI/MBCS (.. , const char*), ANSI/MBCS/Unicode Visual Studio.


- Unicode ANSI/MBCS. :

Project Properties | Configuration Properties | General | Character Set

" " , :

Setting Multi-Byte Character Set in VS2010 IDE

+9

Visual Studio, , Unicode, , , ASCII.

" " → " " → "" → " " " ".

-Surenthar

+2

Visual Studio, , Unicode, , , ASCII.

Go to "Project Properties" → "Configuration Properties" → "General" → "Character Set" and select "Use Multibyte Character Set".

You should also remove UNICODEeither _UNICODEfrom the C ++ → Preprocessor → Preprocessor options, if defined there.

This will cause your code to call the ASCII versions of the Windows API functions that accept strings char.

+1
source

All Articles