ub3*_*t4r 2 c++ url dll winapi nsis
我正在为NSIS(Unicode)开发一个插件,我正在尝试使用InternetCrackUrl()来获取URL的主机名(即:http://www.google.com/test.html - > www.google.com)但是只返回"www.google.com"而不是lpszHostName,它会返回"www.google.com/test.html".
这是我的代码:
void __declspec(dllexport) Example(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
g_hwndParent=hwndParent;
EXDLL_INIT();
LPWSTR szURI = new WCHAR[string_size];
URL_COMPONENTS urlComp;
// Sets szURI to "http://www.xyz.com/test.html"
popstring(szURI);
wstring strUri = szURI;
ZeroMemory(&urlComp, sizeof(urlComp));
urlComp.dwStructSize = sizeof(urlComp);
// Set required component lengths to non-zero so that they are cracked.
urlComp.dwHostNameLength = static_cast<DWORD>(-1);
urlComp.dwSchemeLength = static_cast<DWORD>(-1);
urlComp.dwUrlPathLength = static_cast<DWORD>(-1);
urlComp.dwExtraInfoLength = static_cast<DWORD>(-1);
if (!InternetCrackUrlW(strUri.c_str(), strUri.length(), 0, &urlComp)) {
return _T("InternetCrackUrl failed");
}
// urlComp.lpszHostName = www.xyz.com/test.html
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
如果您不提供自己的缓冲区,InternetCrackUrl将返回指向您作为输入传递的原始字符串中的字符的指针.它不会复制字符串.
因此,lpszHostName将指向第一个字符,dwHostNameLength将为您提供构成主机名的字符数.