Convertir const wchar_t* const char*

Je suis en train d'utiliser GetHostByName() cela nécessite un const char*. J'ai l'adresse de ma page dans une variable qui est dans un coût wchar_t* format. Comment puis-je convertir ce donc que GetHostByName peut l'utiliser? Le code.

BSTR bstr;
pBrowser->get_LocationURL(&bstr);
std::wstring wsURL;
wsURL = bstr;
size_t DSlashLoc = wsURL.find(L"://");
if (DSlashLoc != wsURL.npos)
{
wsURL.erase(wsURL.begin(), wsURL.begin() + DSlashLoc + 3);
}
DSlashLoc = wsURL.find(L"www.");
if (DSlashLoc == 0)
{
wsURL.erase(wsURL.begin(), wsURL.begin() + 4);
}
DSlashLoc = wsURL.find(L"/");
if (DSlashLoc != wsURL.npos)
{
wsURL.erase(DSlashLoc);
}
wprintf(L"\n   Current Website URL: %s\n\n", wsURL.c_str());
HOSTENT *pHostEnt;
int  **ppaddr;
SOCKADDR_IN sockAddr;
char* addr;
pHostEnt = gethostbyname(wsURL.c_str());
ppaddr = (int**)pHostEnt->h_addr_list;
sockAddr.sin_addr.s_addr = **ppaddr;
addr = inet_ntoa(sockAddr.sin_addr);
printf("\n   Current Website IP:%s", addr);
int length = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, NULL, 0,  NULL, NULL); 
std::string LogURL(length+1, 0); 
int result = WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsURL.c_str(), -1, &LogURL[0],length+1,  NULL, NULL);
myfile << "\n   Current Website URL:" << LogURL;
myfile << "\n   Current Website IP:"<< addr;

C'est l'erreur que j'obtiens.
IntelliSense:argument de type "const wchar_t *" est incompatible avec le paramètre de type "const char *"

Tel qu'il est actuellement rédigé, vous êtes en essayant de passer wsURL.c_str() pour la fonction gethostbyname. N'avez-vous pas envie de passer LogURL.c_str() à la place?

OriginalL'auteur ME-dia | 2011-11-09