CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    8

    CInternetSession OnStatusCallback, usage

    Hi EveryOne,
    I am using the CinternetSession to write a small FTP Client.
    I need to know status on line using "OnStatusCallback". How do I implement this.

    The code I'm working is:

    void CFtpConsole::OnConnect()
    {
    // TODO: Add your control notification handler code here
    if (m_pFtpConnection != NULL)
    m_pFtpConnection->Close();
    delete m_pFtpConnection;
    m_pFtpConnection = NULL;
    UpdateData(TRUE);

    try
    {
    EnableStatusCallback(TRUE);
    }
    catch (CInternetException* pEx)
    {
    // catch errors from WinINet
    TCHAR szErr[1024];
    if (pEx->GetErrorMessage(szErr, 1024))
    AfxMessageBox(szErr, MB_OK);
    else
    //AfxMessageBox(IDS_EXCEPTION, MB_OK);
    AfxMessageBox("Unknown Exception", MB_OK);
    pEx->Delete();

    m_pFtpConnection = NULL;
    }


    // Connecting to the Server
    try
    { // I want to give status here1...
    m_pInetSession->GetFtpConnection(m_Server,m_UserName,m_PassWord,21,FALSE );
    }
    catch (CInternetException* pEx)
    {
    // catch errors from WinINet
    TCHAR szErr[1024];
    if (pEx->GetErrorMessage(szErr, 1024))
    AfxMessageBox(szErr, MB_OK);
    else
    //AfxMessageBox(IDS_EXCEPTION, MB_OK);
    AfxMessageBox("Unknown Exception", MB_OK);
    pEx->Delete();

    m_pFtpConnection = NULL;
    }

    // PopulateTree() will display an error if the FTP connection
    // could not be made, otherwise, it grabs the root listing
    // and expands any folder indicated by the site name
    if (m_pFtpConnection != NULL)
    {
    //m_FtpTreeCtl.PopulateTree(m_pFtpConnection, strObject);
    m_FtpTreeCtl.PopulateTree(m_pFtpConnection, "c2001");
    }
    else
    {
    m_FtpTreeCtl.PopulateTree();
    }

    }
    Do I need to call OnStatusCallBack evertime I need status. I don't understand how it is used.

    Warm Regards,
    Vijay


  2. #2
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: CInternetSession OnStatusCallback, usage

    Hi Vijay,

    you don't need to call OnStatusCallback, the MFC framework calls *your* implementation of OnStatusCallback. You need to inherit your own class from CInternetSession and overwrite OnStatusCallback. For example:

    class CMyInternetSession : public CInternetSession
    {
    public:
    void OnStatusCallback( DWORD dwContext,
    DWORD dwInternetStatus,
    LPVOID lpvStatusInformation,
    DWORD dwStatusInformationLength );
    };


    void CMyInternetSession::OnStatusCallback( DWORD dwContext,
    DWORD dwInternetStatus,
    LPVOID lpvStatusInformation,
    DWORD dwStatusInformationLength )
    {
    if ( INTERNET_STATUS_CONNECTING_TO_SERVER == dwInternetStatus )
    {
    AfxMessageBox( "Connecting to server..." );
    }
    }



    Martin

  3. #3
    Join Date
    Apr 1999
    Posts
    8

    Re: CInternetSession OnStatusCallback, usage

    Hi Martin,
    Thank you for your kind reply...
    I did exactly as you suggested.. I am now getting a new error , actually an assert fail.
    The assert fail occures in the MFC file Inet.cpp at this location
    begin..........................
    CInternetSession::CInternetSession(LPCTSTR pstrAgent /* = NULL */,
    DWORD dwContext /* = 1 */,
    DWORD dwAccessType /* = PRE_CONFIG_INTERNET_ACCESS */,
    LPCTSTR pstrProxyName /* = NULL */,
    LPCTSTR pstrProxyBypass /* = NULL */,
    DWORD dwFlags /* = 0 */)
    {
    Fails here--> ASSERT((dwFlags & INTERNET_FLAG_ASYNC) == 0);
    end.................................

    I derived an CInternetSession class the constructor for the same is as follows...
    begin..............................
    CDerivedInternetSession::CDerivedInternetSession(LPCTSTR pstrAgent, DWORD dwContext, DWORD dwAccessType,
    LPCTSTR pstrProxyName ,LPCTSTR pstrProxyBypass,DWORD dwFlags)
    : CInternetSession( pstrAgent, dwContext, dwAccessType, pstrProxyName, pstrProxyBypass,dwFlags )
    {
    //CInternetSession( pstrAgent, dwContext, dwAccessType, NULL, NULL, INTERNET_FLAG_ASYNC );

    }
    end...............................

    The call to make an object is as follows

    begin.....................
    m_pInetSession = new CDerivedInternetSession("Test1", 1, INTERNET_OPEN_TYPE_DIRECT,NULL, NULL ,INTERNET_FLAG_ASYNC );


    try{m_pInetSession->EnableStatusCallback(TRUE); }
    catch (CInternetException* pEx)
    {
    // catch errors from WinINet
    TCHAR szErr[1024];
    if (pEx->GetErrorMessage(szErr, 1024))
    AfxMessageBox(szErr, MB_OK);
    else
    //AfxMessageBox(IDS_EXCEPTION, MB_OK);
    AfxMessageBox("Unknown Exception", MB_OK);
    pEx->Delete();

    }

    end...................................

    Some thing goes wrong and an Assertion fails.

    If I choose to Ignore it I get an
    "Overlapped I/O operation in progress" message.

    Where am I going wrong.

    Warm Regards,
    Vijay



  4. #4
    Join Date
    Apr 1999
    Posts
    3

    Re: CInternetSession OnStatusCallback, usage

    Hi Vijay,
    m_pInetSession = new CDerivedInternetSession("Test1", 1, INTERNET_OPEN_TYPE_DIRECT,NULL,
    NULL ,INTERNET_FLAG_ASYNC );

    you do not pass "Test1" as the first parameter to the constructor,instead pass NULL so that framework can use AfxGetApp() to get
    your application name.And also,if you use asynchronous flag INTERNET_FLAG_ASYNC,you have chance to get
    the error message "Overlapped I/0 in progress.
    Just declare the session object as
    m_pInetSession = new CDerivedInternetSession;
    you are connecting to which FTP server? you have your own?.
    Hope this info. can help you.

    Bye
    S.Subbi.






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured