I keep getting this error:
cannot convert parameter 1 from 'char' to 'LPCWSTR'
int main(int argc, char argv[])
{
// open port for I/O
HANDLE h = CreateFile(argv[1],GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(h == INVALID_HANDLE_VALUE) {
PrintError("E012_Failed to open port");
can someone help?
It should be
And
This is the main function that Visual Studio creates by default:
Where _TCHAR is defined to be char or wchar_t depending if _UNICODE is defined or not. The same thing happens with API functions. I would advise you against using explicit CreateFileA. Change your main and use CreateFile.
Go to the Properties for your Project and under Configuration Properties/General, change the Character Set to "Not Set". This way, the compiler will not assume that you want Unicode characters, which are selected by default:
I guess you're compiling with Unicode enabled. Then with
char argv[]
,argv
is achar
array, soargv[1]
is achar
, andCreateFile
wants aconst wchar_t*
as first parameter, not achar
.That said, your
main
definition is also broken, it should havechar* argv[]
. With that change, you can callCreateFileA
.Depending on your compiler setting for CharacterSet, you may need to perform a multibyte / widechar conversion, or change the CharacterSet if you don't care what it is.
For converting with MultiByteToWideChar, see the following...
http://www.codeguru.com/forum/showthread.php?t=231165