first the code compiles and runs with VS2010
but when I compile with cl.exe it gives
cannot convert parameter 1 from 'WCHAR [10]' to 'LPCTSTR'
the code is
char *fileName = "12.txt";
WCHAR ufileName[10];
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, fileName, -1, ufileName, 10);
postFile(ufileName, clientSock);
postFile(LPCTSTR lpFileName, SOCKET clientSock)
You’re trying to pass a
WCHARarray to a function that expects aLPCTSTR. This article explains thatLPCTSTRis an array ofTCHARs and thatTCHARvaries in size for unicode and non-unicode builds.Your code relies on
sizeof(TCHAR) == sizeof(WCHAR)so you need unicode support to be enabled.I’d guess that your build from within the IDE enables unicode while your command line build doesn’t. You can enable unicode support by adding
-DUNICODE -D_UNICODEto your command line.