I'm creating an FTP downloader using WinInet in a Univeral Windows program with Visual Studio 2019.
Visual Studio 2019 doesn't give an option to change the character set in the properties configuration tab.
I need to convert the following, which is in multibyte format, to Unicode:
CHAR * szHead[] = "Accept: */*\r\n\r\n";
The overall code comes from a previous older project using a compiler that had multi-byte character set options, and works fine as is. Unfortunately, I need to make this work in a compiler that has Windows Store support, which only has Unicode.
if (!(hConnect = InternetOpenUrlW(hOpen, szUrl, szHead, strlen(szHead), INTERNET_FLAG_DONT_CACHE, 0)))
I get the following errors:
Error (active) E0520 initialization with '{...}' expected for aggregate object
Error C2440 'initializing': cannot convert from 'const wchar_t [16]' to 'LPCTSTR []'
Error C2664 'size_t strlen(const char *)': cannot convert argument 1 from 'LPCTSTR []' to 'const char *'
From other research, these errors are arising because the compiler is expecting Unicode but is getting multibyte.
First off,
CHAR * szHead[] = "Accept: */*\r\n\r\n";does not compile. You are trying to initialize an array of non-const pointers using a single const pointer. You need to use this instead:Or this:
That being said,
InternetOpenUrlW()takesWCHARstrings (hence theWin its name), notCHARstrings. Have you considered simply usingInternetOpenUrlA()instead?If that is not an option, then you will have to either:
MultiByteToWideChar()(or equivalent) to convert theCHARstring into aWCHARstring, eg:WCHARstrings to begin with, eg: