我已经使用函数gethostbyname函数来获取主机信息。该函数需要一个 const char * 字符串,但我有一个 LPWSTR 类型的字符串,因此我收到错误消息
error C2664: 'gethostbyname' : cannot convert parameter 1 from 'LPWSTR' to 'const char *'
我尝试执行从 LPWSTR 到 const char * 的类型转换,如下所示,但编译器错误似乎消失了,但它没有给出预期的结果。
host = gethostbyname((const char *)resource.lpRemoteName);
我跟进了谷歌并使用了如下的Cstring,但该功能似乎失败了。请让我知道转换。
CString strFullName =resource.lpRemoteName;
host = gethostbyname(strFullName);