cannot convert parameter 1 from 'char' to 'LPCWSTR'

≯℡__Kan透↙ 提交于 2019-11-27 12:04:51

It should be

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

And

HANDLE h = CreateFileA(argv[1],GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);

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:

This is the main function that Visual Studio creates by default:

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

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.

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

I guess you're compiling with Unicode enabled. Then with char argv[], argv is a char array, so argv[1] is a char, and CreateFile wants a const wchar_t* as first parameter, not a char.

That said, your main definition is also broken, it should have char* argv[]. With that change, you can call CreateFileA.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!