I am working on the following function:
int initSerialPort(HANDLE* hSerialPort, LPCSTR portName){
*hSerialPort = CreateFile(
portName,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0
);
....
}
However, I get a red error mark under the "portName" variable with the error message
argument of type "LPCSTR" is incompatible with parameter of type "LPCWSTR"
However, despite this error, the code compiles and runs as expected. I am currently passing in an argument as follows:
LPCSTR portName = "COM1";
initSerialPort(&hSerialPort, portName);
Furthermore, when I try to use type LPCWSTR instead, the code does not compile. When I instead change the parameter to LPCWSTR and initialize the argument like this:
LPCWSTR portName = L"COM5";
initSerialPort(&hSerialPort, portName);
I no longer see the red error squiggly, however when I try to compile this I get the following error
.\test.cpp:28:17: error: cannot convert 'LPCWSTR' {aka 'const wchar_t*'} to 'LPCSTR' {aka 'const char*'}
28 | portName,
| ^~~~~~~~
| |
| LPCWSTR {aka const wchar_t*}
What the heck is going on?