Hottest Forum Q&A on CodeGuru for the week of March 29th, 2004


Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:

Why does the CFtpConnection::Command function not work for me? (top)  


lspecht is working with the CFTPConnection class. He wants to use the Command method of that class. Unfortunately, the VC++ compiler complains that the Command function does not exist. Take a look:

I need some help . The CFtpConnection object in the code below
seems to work well if I comment out the line:

"if(pFTPSite->Command..." function

However, when the command function is not commented out, a
compilation error occurs.

What is causing this error? The CFtpConnection object is obviously
working for the other functions. I have included afxinet.h in the
file. I've also installed the latest SDK and added wininet.lib to
the project settings for the linker (something I saw in anotherthread).

The error is:
c:\Visual C++ Applications\UnixScriptGenerator\RunScriptWizard.cpp(929) :
error C2039: 'Command' : is not a member of 'CFtpConnection'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\
afxinet.h(371) : see declaration of 'CFtpConnection'
c:\Visual C++ Applications\UnixScriptGenerator\RunScriptWizard.cpp(929) 
: error C2065: 'CmdRespNone' : undeclared identifier
Here is the code:
void CRunScriptSTDIODialog::RetrieveInputList()
   CInternetSession sess;
   CFtpConnection* pFTPSite = NULL;
   CUnixScriptGeneratorDoc* pDoc =


      pFTPSite = sess.GetFtpConnection(pDoc->pDefaultCProfile->
         AfxMessageBox("Could not set current directory on ftp site",

      if(pFTPSite->Command("ls *.inp > UnixScriptGenTemp",
         CmdRespNone, FTP_TRANSFER_TYPE_ASCII, 1)==0){
         AfxMessageBox("Could not perform ls command on ftp site",

    catch (CInternetException* pEx){
      pFTPSite = NULL;
   delete pFTPSite;
According to the error:
'Command' : is not a member of 'CFtpConnection'

Command is not a function of the CFTPConnection class. But, according to the MSDN, the function does exist. If you take a look at the afxinet.h header file and search for the command function, you will see that it is declared like this:

#if _WIN32_IE >= 0x0500
CInternetFile* Command(LPCTSTR pszCommand,
                       CmdResponseType eResponse = CmdRespNone,
DWORD_PTR dwContext = 1);

And what does that mean? Well, it means that the command function is only available if you have installed IE5.0 or later. So far, so good. But, lspecht has installed IE6.0, so somewhere it is not picking up the correct version of IE. If you take a look at the stdafx.h, you will see that #define _WIN32_IE is defined as 0x0400. Just change it to 0x0600 and it will work.

How do I change the title of CMDIFrameWnd when the child is maximized? (top)  


jeffchen wants to change the title of a CMDIFrameWnd when the child window is maximized. Do you know how to do that?

As all you know, usually the title bar will show
"AppTitle - [DocTitle]". In my project, I want to change it to
"[DocTitle] - AppTitle".

I know the FWS_ADDTOTITLE and FWS_PREFIXTITLE settings. However, It
only works when the MDI child is not maximized. When the MDI child
is maximized, the title will restore to the "AppTitle - [DocTitle]"

I also Googled for the answer but did not find one.
I hope someone here knows how to solve it.

You can change your title by SetWindowText or override CMDIChildWnd::OnUpdateFrameTitle. The title is changed in the fuction. Your function should look like this:


if ((GetStyle() & FWS_ADDTOTITLE) == 0)
   return;    // leave child window alone!

CDocument* pDocument = GetActiveDocument();
if (bAddToTitle)
   TCHAR szText[256+_MAX_PATH];
   CString strTitle;


   if (pDocument == NULL)
      lstrcpy(szText, m_strTitle);
      lstrcpy(szText, pDocument->GetTitle());

   if (m_nWindow > 0)
      wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);

   // set title if changed, but don't remove completely
   lstrcat(szText, " - ");
   lstrcat(szText, (char *)((LPCTSTR) strTitle));

Besides that, you should get rid of the main frame's OnUpdateFrameTitle function.

How can I make sure whether a pointer is still good? (top)  


NittiLin is working with many dialogs. For this purpose, he is using an array to save the pointers of that dialogs. After usage, he loops through the array of dialogs. Here, he needs to check whether the pointers to the dialog are still valid or not. Can this be done?

I have 'A' dialog, which creates multiple modeless 'B' dialogs. 
I use GetDesktopWindow() as 'B' dialogs' parent for some reason. 

'A' dialog saves pointers of 'B' dialogs to a CArray in order to do 
something when user closes 'A' dialog.

The user can delete 'B' dialogs at any time before closing 'A' dialog. 
Since 'A' is not B's parent, I don't know how to notify 'A' dialog 
to remove the pointer from CArray if user deletes any of the 'B'

However, so far, program works fine without any problems. 

My question is:

1) If the user deleted a 'B' dialog, but its pointer still exists
in 'A' dialogs' CArray. When 'A' dialog loops though CArray and got
that pointer and use that to call some functions on B dialogs, will
it cause any problems?

2) How do I make sure if the pointers on CArray are still good to use?

The answer to the first question is: Yes, it will cause problems. The answer to your second question is that you should use a std::map instead of a CArray or a linked list. This way, dialog A generate keys when modeless dialogs are created. The modeless dialog then can use this key and the pointer to dialog A to be removed from the map when it is closed.

How do I recognize a STOP in Windows Services? (top)  


mattl is working with services. He needs to recognize that a STOP has been requested, so that he can shut down the service in a clean manner.

I am writing a Service in 'C' that has lots of database activity.
When the user requests to STOP the Service (within the Service
Control Manager) the program simply halts. It does not matter what
it is in the middle of doing.

How do I recognize that a STOP has been requested? I need this so I
can shut down the service gracefully.

There is a nice example of a Service posted on this Web site and it
shows how to pause or stop a servicem but both of these happen
instantly without any warning.

A STOP request for service looks like getting a SERVICE_CONTROL_STOP control message via its control handler routine. The service that has been requested to stop itself has to set its state to SERVICE_STOP_PENDING to initiate a cleanup procedure and, after cleanup, ends it has to set its state to SERVICE_STOP, notifying the system it's done. It has about 30 seconds (because SERVICE_CONTROL_STOP has been emitted) to do it before the system will decide to kill it as a hanging process. If the service needs more than 30 seconds, it has to use a checkpoint mechanism.

About the Author

Sonu Kapoor

Sonu Kapoor is an ASP.NET MVP and MCAD. He is the owner of the popular .net website DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at:


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The open source cloud computing project OpenStack has come a long way since NASA and Rackspace launched it in 2010. Backed by leading technology infrastructure providers including Cisco, Dell, EMC, HP, IBM, Intel, and VMware, OpenStack underpins significant workloads at an increasingly diverse set of organizations, including BWM, CERN, Comcast, eBay, and Wal-Mart. For CIOs engaged in broader programs to win, serve, and retain customers -- and refocus business technology (BT) spend -- a planned and pragmatic …

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date