Problem with WinInet

I've got a function in a CDocument derived class CFtpDoc which attempts to
get the current directory.

Got some reason, whenever I try to GetCurrentDirectory() or
GetCurrentDirectoryAsURL() I get an error.  When I call GetLastError() as
below, I get a value 997. I have looked it up in WinError.h -->
ERROR_IO_PENDING.  What does this mean??



void CFtpDoc::GetFtpCurDir(CString& str)
TCHAR strDirectory[5];
LPTSTR lpStr=strDirectory;
CString str1="Hello";

BOOL b=m_pFtpConnection->GetCurrentDirectory(str1);

#ifdef _DEBUG
TRACE("Last error was: %d\n", GetLastError());
#endif //_DEBUG

str+= szURLftp;
str+= m_pFtpConnection->GetServerName();

if (strDirectory[0] != '/')


Who is Participating?

Improve company productivity with a Business Account.Sign Up

mikeblasConnect With a Mentor Commented:
Did you constrcut any of the objects in your connection hierarchy using FLAG_ASYNC?  That's the educated guess I'd give you.

While you are, indeed, not appropriately handling the string buffer, buffer sizes obviously have no relation to an IO_PENDING error. To solve your buffer problems, you shouldn't do any of the hokey casts these guys have suggested. You should, instead, call the LPTSTR override of GetCurrentDirectory(), like this:

   BOOL b = m_pFtpConnection->GetCurrentDirectory(strDirectory, 5);

or you should use a CString:

   CString str;
   BOOL b = m_pFtpConnection->GetCurrentDirectory(str);

From the looks of your code, you're really struggling with the notion of pointers; perhaps, before you go any further, you should complete a C++ tutorial.

If you're, indeed, using INTERNET_FLAG_ASYNC, your code is broken. Clearly, from the code you've written, you'll not benefit from ASYNC internet access--your program is dependant on getting an answer from a call before it can continue doing any other work. If your program would benefit from async access, it would have other things to go and do while waiting for a response.

If you want to rearchitect your program to do ASYNC access, see the KB article at

By the way, most people ask MFC questions in the MFC area.

B ekiM

You  have to do something else with the way your pass str1

I don't know off hand but something like.

BOOL b=m_pFtpConnection->GetCurrentDirectory(str1);
BOOL b=m_pFtpConnection->GetCurrentDirectory((CSTRING&)str1);

first one should have been

BOOL b=m_pFtpConnection->GetCurrentDirectory(&str1);
Allocate more space for str1 (str1="Hello" is just not enough...)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.