Exception handling/Error question (wodFtpDLX / wodFtpDLX.NET)
When I try to connect using the wrong password and userid, the Connect function throws an exception, rather than returning a failed HRESULT as I expected. I was wondering what type of exception it was throwing (com_error + errorcode maybe?) so I can catch it rather than using catch(...).
Also, in this situation, it crashes my app when it drops out of my ftp function. I get an exception access violation in wodFtpDLX.dll at 0x6d0182d0 (base address = 0x6d000000).
Any recommendations on exception handling or ideas on the error I am getting? Here's a code snippet:
EVENT HANDLER:
class CwodFtpDLXEventHandler
: public IDispEventSimpleImpl<1, CwodFtpDLXEventHandler, &DIID__IwodFtpDLXComEvents>
{
public:
CwodFtpDLXEventHandler() {}
virtual ~CwodFtpDLXEventHandler () {}
void __stdcall ConnectedEvent (long ErrorCode, BSTR ErrorText)
{
lErrCode = ErrorCode;
bstrErrText = ErrorText;
bConnected = TRUE;
}
void __stdcall DoneEvent (long ErrorCode, BSTR ErrorText)
{
lErrCode = ErrorCode;
bstrErrText = ErrorText;
bDone = TRUE;
}
_bstr_t GetLastErrorText() { return bstrErrText; };
long GetLastErrorCode() { return lErrCode; };
BEGIN_SINK_MAP (CwodFtpDLXEventHandler)
SINK_ENTRY_INFO(1, DIID__IwodFtpDLXComEvents, 1, ConnectedEvent, &Connected_Info)
SINK_ENTRY_INFO(1, DIID__IwodFtpDLXComEvents, 8,DoneEvent, &Done_Info)
END_SINK_MAP ()
private:
long lErrCode;
_bstr_t bstrErrText;
};
PART OF MY FTP FUNCTION:
IwodFtpDLXComPtr m_Ftp = NULL;
CwodFtpDLXEventHandler m_FtpEvent;
try
{
hr = m_Ftp.CreateInstance(CLSID_wodFtpDLXCom, NULL);
if (FAILED(hr))
throw CreateInstance failed ;
m_Ftp->LicenseKey = blah blah ;
m_FtpEvent.DispEventAdvise(m_Ftp);
m_Ftp->put_Blocking(VARIANT_TRUE);
m_Ftp->put_Authentication(authPassword);
m_Ftp->put_Protocol(FTPSwithdata);
m_Ftp->put_Hostname(_bstr_t(cstrServerName));
m_Ftp->put_Login(_bstr_t(cstrUser));
m_Ftp->put_Password(_bstr_t(cstrPwd));
m_Ftp->put_Port(990);
m_Ftp->put_Timeout(60);
m_Ftp->Connect();
if (m_Ftp->State == Connected)
{
// not getting here
}
}
//other catches here
catch(...)
{
if (m_Ftp != NULL)
{
cstrError = (LPCSTR) m_FtpEvent.GetLastErrorText();
if (m_Ftp->State == Connected) m_Ftp->Disconnect(VARIANT_TRUE);
}
}
m_FtpEvent.DispEventUnadvise(m_Ftp);
m_Ftp.Release();
I can debug all the way through and the error returned says its an invalid username or password, but as soon as it drops out of my ftp function it crashes.
Thanks,
Jason Henderson