Search code examples
c++parsingwinapiurlwininet

InternetCrackUrl() function


I've got a little problem with this function when I'm trying to crack my URL in URL_COMPONENTS structure, the value of HostName and urlPath members stays on '\0' and meanwhile it's so, I have the true Length of both(HostName and urlPath members). what is the problem?, it' would be my pleasure if you answer by code.

Thanks and best wishes, John Smith.

URL_COMPONENTS urlcomponents;
urlcomponents.dwStructSize=sizeof(URL_COMPONENTS);
urlcomponents.dwHostNameLength=10;
urlcomponents.dwPasswordLength=10;
urlcomponents.dwSchemeLength=10;
urlcomponents.dwUrlPathLength=10;
urlcomponents.dwUserNameLength=10;
urlcomponents.dwExtraInfoLength=10;
urlcomponents.lpszExtraInfo=extraInfo;
urlcomponents.lpszHostName=hostName;
urlcomponents.lpszPassword=passwordSet;
urlcomponents.lpszScheme=schemeUrl;
urlcomponents.lpszUrlPath=fileUrlPath;
urlcomponents.lpszUserName=userName;
//urlcomponents.nPort=80;

std::string originUrl="http://s1.asandownload.com/mobile/android/application/Color.Effect.Booth.Pro.v1.4.2_AsanDl.com.apk";

InternetCrackUrl(originUrl.c_str(),originUrl.Length(),0,&urlcomponents);

Solution

  • The Problem solved and I'm Gonna share it here :D

    it's so obvious that when GetLastError returns ERROR_INSUFFICIENT_BUFFER You need to increase the Length or size of something for god sake!!! :D so, I increased it :D , ex:

    urlcomponents.dwHostNameLength=1024;
    

    cause my buffer size was

    =new char [1024];
    

    AWESOME!