Reputation: 29
I'm using the following code after a call to FtpOpenFile:
error=GetLastError();
if(error!=0)
{
if(error==ERROR_INTERNET_EXTENDED_ERROR)
{
InternetGetLastResponseInfo(&error,NULL,&bufferLength);
buffer=malloc(bufferLength);
InternetGetLastResponseInfo(&error,buffer,NULL);
printf("FtpOpenFile error : %s.\n",buffer);
}
else
{
printf("FtpOpenFile error : %d.\n",(int)error);
}
}
I confirmed that error=ERROR_INTERNET_EXTENDED_ERROR, but instead of printf-ing something like
FtpOpenFile error : The server denied the request due to the fact that it has a personal dislike, or in other words, a subtle hatred, towards you.
It gives me
FtpOpenFile error : x☺?.
Thanks.
Upvotes: 0
Views: 817
Reputation: 125708
Your second call to IntergetGetLastResponseInfo
is wrong; you're not passing the length of the buffer as required. The first call you make retrieves the size of the buffer needed, but you still have to tell the function how large the buffer is when you call it the second time.
(Also note that the documentation says that the value returned in the first call does not include space for the terminating zero.)
InternetGetLastResponseInfo(&error, NULL, &bufferLength);
buffer = malloc(bufferLength + 1);
InternetGetLastResponseInfo(&error, buffer, &bufferLength);
See the InternetGetLastReponseInfo
documentation for more info.
Upvotes: 1