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
Re: Exception handling/Error question
Jason,
since this is C++ I would appreciate if you could zip your project and send it over to techsupport@weonlydo.com so we can run it in debug mode - and see why this exception happens.
We could paste your code, but it's not that easy to create same type of project as you use, include same libraries etc..
Can you do that please?
Kreso
Re: Exception handling/Error question
Jason,
since this is C++ I would appreciate if you could zip your project and send it over to techsupport@weonlydo.com so we can run it in debug mode - and see why this exception happens.
We could paste your code, but it's not that easy to create same type of project as you use, include same libraries etc..
Can you do that please?
Kreso
I would love to Kreso, but its a huge project. The FTP function is in a COM exe server which is called by a COM dll which is called from a powerbuilder/c++ application. Seriously, this wouldn't work.
Any other suggestions?
It breaks in the code on a call to DispatchMessage in my COM exe. The message is 275 (WM_TIMER) with a wparam of 1 and lparam of 0.
Re: Exception handling/Error question
Jason,
and, just as I could paste your code in new project, you could do the same (just for a test), but you know better than me what kind of project is it. Would same error appear? I think so - this could be a good way to duplicate the problem.
As for WM_TIMER.. Hmm.. What kind of exception gets fired? I have seen same exceptions like your that was result of regular error being returned (but not caught by environment). THat's why I think it's important for me to try the code.
If nothing else happens, I could send you debug build which could help, but I think of it as a last resort.
Kreso
Re: Exception handling/Error question
and, just as I could paste your code in new project, you could do the same (just for a test), but you know better than me what kind of project is it. Would same error appear? I think so - this could be a good way to duplicate the problem.
I'll create a new project just using the code I pasted to see if it still happens.
Thanks
Jason
Re: Exception handling/Error question
John,
excellent! Keep me posted, please.
Re: Exception handling/Error question
More info:
My app is catching a com error.
COMerr {-2146798272} _com_error
First-chance exception at 0x7c81eb33 in esinetconnect.exe: Microsoft C++ exception: _com_error @ 0x0012eb58.
First-chance exception at 0x6d0182d0 in esinetconnect.exe: 0xC0000005: Access violation reading location 0x01dc007e.
I will send you the ftp app (com exe) and a test app (mfc dialog). The test app does not crash but i get a _com_error in Connect.
Re: Exception handling/Error question
Ok, I did some calculation. Error you get is -2146798272 which converted to HEX is 800A7540. If I take only lower word, it's HEX 7540. Converting it back to dec gives us 30016 - so this is HRESULT error for invalid login/password, right?
But this isn't access violation exception I'm worried about, and for which I need to duplicate behavior. 30016 can be fixed if trapped correctly, right?
Or I'm missing something here. What are we after, if 30016 is expected?
Re: Exception handling/Error question
Ok, I did some calculation. Error you get is -2146798272 which converted to HEX is 800A7540. If I take only lower word, it's HEX 7540. Converting it back to dec gives us 30016 - so this is HRESULT error for invalid login/password, right?
But this isn't access violation exception I'm worried about, and for which I need to duplicate behavior. 30016 can be fixed if trapped correctly, right?
Or I'm missing something here. What are we after, if 30016 is expected?
30016 is expected, and that's what the connected event says we get. However, either I'm not handling this exception well or something is not getting released, etc. I just get an access violation in the wodftpdlx dll and I'm not sure why. It seems like I'm doing everything right. I'm sending up the code to my test app and my real app.
Thanks
Re: Exception handling/Error question
Is Connect supposed to throw a _com_error or is it supposed to return a failed HRESULT?
Jason
Re: Exception handling/Error question
Depends on your wrapper. wodFtpDLX does return HRESULT, but your wrapper reads that and throws exception for you - not wodFtpDLX itself. Try to 'step into' Connect call, and see what happens there.
Re: Exception handling/Error question
I took out the exception handling and now the error occurs as soon as I return from the Connect function in the wodftpdlx.tli file.
inline HRESULT IwodFtpDLXCom::Connect ( const _variant_t & Hostname, const _variant_t & Port, const _variant_t & Protocol ) {
HRESULT _hr = raw_Connect(Hostname, Port, Protocol);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}
Re: Exception handling/Error question
It looks like this is a problem with using smart pointers. If I call the raw_Connect function it works.
Re: Exception handling/Error question
Jason,
even you consider this solved - I am sure VC had a good reason why it didn't give you raw_Connect directly (I just don't know which one). I remember I used to use caps TRY CATCH_ALL sequence to fix this problem (or something very similar to that).
Although.. Hmm.. If it works with raw_Connect - go ahead, use it :)
Re: Exception handling/Error question
Maybe we can help each other out here....
I was surprised by exceptions being thrown, too. The documentation didn't mention anything about them. It came down to adding the raw_interfaces_only flag to the #import statement. Without that flag, the compiler generates wrapper code that throws _com_error exceptions. Adding the flag made them go away. I'm not sure about the memory access violation though.
Could you please tell me where you got the SINK_ENTRY_INFO from? I'm trying to implement some event sink methods and I'm not sure what the function signatures look like. Thanks!
Joe
Re: Exception handling/Error question
Joe,
manually :)
I can do them for you. Can you send me your code that you have so far and I'll add events to it?
Kreso
Re: Exception handling/Error question
Hey that would be great. My code is just a modification of the sample code at SamplesVCATLConsoleAppConsoleApp.cpp. I figured out how to generate the entries, but I do not know the correct DISPIDs to put in the SINK_ENTRY_INFO structures. Reading through other posts and looking at the sample code I found that
Connected = 1
Progress = 6
Done = 8
I need the DISPID for Progress64. Is there a list of them somewhere? Will these values stay the same in future releases of the product? Thanks!
Joe
Re: Exception handling/Error question
Hey,
I know this is way late, but I just found this problem to be associated with the file esinetconnect.exe
This file is installed by Eaglesoft software. I removed the file and the system stopped doing a memory dump, and I no longer suffered from the blue screen of death. The file is run at startup whether it is needed or not. The Eaglesoft software does not need be run. Hope this helps although I am sure you have all solved by now. Good luck.