I am using Boost::Asio for network communication. The following code fails with the following compilation error.
Code:
std::wstring hostName(L"myserver");
std::wstring portName(L"myport");
auto query = boost::asio::ip::udp::resolver::query(boost::asio::ip::udp::v4(), hostName, portName);
Compilation error:
Error 1 error C2665: 'boost::asio::ip::basic_resolver_query<InternetProtocol>::basic_resolver_query' :
none of the 5 overloads could convert all the argument types
My questions:
Currently running on Windows, using Visual Studio 2013.
Thanks in advance.
Does Boost::Asio expect ANSI-strings (std::string) only? It expects std::string, but not necessarily ANSI, since std::string can store UTF-8.
Does this mean that hostnames with non-ANSI characters are not supported? I haven't personally tried it, but since this is essentially a wrapper on top of the underlying OS networking code, I can't find any reason it wouldn't support using UTF-8.
Or do I have to convert my wide strings to UTF8 first? Most likely, yes, since the wide string format is only used by core Windows APIs, while UTF-8 is used by everyone else including Boost.
And in the latter case, does Boost::Asio provide standard methods to do this or can I use my own ANSI/Unicode conversion routines? Boost doesn't appear to support wide-char. As long as you are using Windows-specific character encoding, you can either use the COM interfaces that are provided by Windows for converting (MultiByteToWideChar, WideCharToMultiByte), or use your own routines. If your own routines are known to be reliable/correct, and you are not already using COM, you might want to stick with your own rather than adding a dependency on COM to your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With