Solved

Problem with WinInet

Posted on 1998-07-09
4
242 Views
Last Modified: 2012-06-27
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??

Regards

Oscar

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] != '/')
  lstrcat(lpStr,_T("/"));

str+=strDirectory;

}
0
Comment
Question by:ossentoo
  • 2
4 Comments
 
LVL 2

Expert Comment

by:lucidity
ID: 1167514
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);
-OR-
BOOL b=m_pFtpConnection->GetCurrentDirectory((CSTRING&)str1);


0
 
LVL 2

Expert Comment

by:lucidity
ID: 1167515
first one should have been

BOOL b=m_pFtpConnection->GetCurrentDirectory(&str1);
0
 
LVL 11

Expert Comment

by:alexo
ID: 1167516
Allocate more space for str1 (str1="Hello" is just not enough...)

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1167517
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 http://support.microsoft.com/support/kb/articles/q164/9/83.asp

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

B ekiM

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now