My Custom Rack I Built
Reply to topic
 
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
Anyone here dealt with event trapping in C++? I keep getting a Catastrophic Error on my friggin' Advise statement.

I'm trying to trap the event of an ADO connection object.

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
I can't seem to find anything on it. It say, make it impossible for the user to make the error in the first place. eg check if the number they gave actually is a number before continuing. But I can't find any "on error do this" code. hehe, VB is so much simpler.

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
I'm trying to trap when the database goes down otherwise the dll just hangs. A solution someone did in the past doubled the processing time.

Yes, VB is A LOT easier when it comes to events.

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
maybe try reading a short thing from the database, if it can, then do the rest if it can't them you know the connection is down. or will this also hand the .dll?

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
I hangs when trying to do the actual connection. You'd think the stupid connection object would just bail but it doesn't.

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
how can the db go down anyways, is it online?

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
If something like a router went down, the connection could be lost. This isn't an app for personal use. This is a widely used database connection manager dll we use here at Anheuser-Busch (the people that make Budweiser). For some reason they like failsafe applications and stuff.

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
I've asked on another forum, I'll post any replies.

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
Thank ya!

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
Here's the thread:
http://vbforums.com/showthread.php?s=&threadid=287501

He's expecting you to post some code. Don't ask me what code.

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
Here is some of my code. m_pAdoCon is my ADO connection object. After I create the hADOEventHandle I pass it to WaitForSingleObject where the code waits for the connect to fire.

It would work but it yarfs on my Advise statement.

This code is based upon the ado event trapping example in MSDN.

***.CPP
Code:

DWORD   dwConnEvt = NULL;
IConnectionPointContainer   *pCPC = NULL;
IConnectionPoint   *pCP = NULL;
IUnknown   *pUnk = NULL;
CConnEvent   *pConnEvent= NULL;
int rc = 0;

//ConnectComplete Event for ADO
STDMETHODIMP CConnEvent::raw_ConnectComplete(
   struct Error *pError,
   ADODB::EventStatusEnum *adStatus,
   struct _Connection *pConnection)
   {
      *adStatus = ADODB::adStatusOK;
      SetEvent(hADOEventHandle); //Set the event handle
      return S_OK;
   };

//Disconnect Event for ADO
STDMETHODIMP CConnEvent::raw_Disconnect(
   ADODB::EventStatusEnum *adStatus,
   struct _Connection *pConnection)
   {
      *adStatus = ADODB::adStatusUnwantedEvent;
      return S_OK;
   };

//QueryInterface Function for CConnEvent
STDMETHODIMP CConnEvent::QueryInterface(REFIID riid, void ** ppv)
   {
      *ppv = NULL;
      if (riid == __uuidof(IUnknown) ||
          riid == __uuidof(ADODB::ConnectionEventsVt)) *ppv = this;
      if (*ppv == NULL)
         return ResultFromScode(E_NOINTERFACE);
      AddRef();
      return NOERROR;
   }

STDMETHODIMP_(ULONG) CConnEvent::AddRef() { return ++m_cRef; };

STDMETHODIMP_(ULONG) CConnEvent::Release()   
   {
   if (0 != --m_cRef) return m_cRef;
      delete this;
        return 0;
   }

......
......
         
//QueryInterface function is overridden and up above in this code
hr = m_pAdoCon->QueryInterface(__uuidof(IConnectionPointContainer), (void **)&pCPC);
if (FAILED(hr)) return rc;
      
hr = pCPC->FindConnectionPoint(__uuidof(ADODB::ConnectionEvents), &pCP);
pCPC->Release();
if (FAILED(hr)) return rc;

pConnEvent = new CConnEvent();
hr = pConnEvent->QueryInterface(__uuidof(IUnknown), (void **) &pUnk);
if (FAILED(hr)) return rc;

hr = pCP->Advise(pUnk, &dwConnEvt);
pCP->Release();
if (FAILED(hr)) return rc;


//hADOEventHandle gets set in the raw_ConnectComplete event
pConnEvent->hADOEventHandle = CreateEvent(NULL, false, false, NULL);
if(pConnEvent->hADOEventHandle == NULL)
     CBUDNETStdException::BUDNETThrowException(E_FAIL,"Could not open connection.", BudNETMessage);



***.H
Code:

class CConnEvent :
   public CComCoClass<ADODB::ConnectionEventsVt>
{
private:
      ULONG      m_cRef;
    
public:
  CConnEvent() { m_cRef = 0; };
  ~CConnEvent() {};
HANDLE   hADOEventHandle;
  STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
  STDMETHODIMP_(ULONG) AddRef(void);
  STDMETHODIMP_(ULONG) Release(void);

  STDMETHODIMP raw_ConnectComplete(struct Error *pError, ADODB::EventStatusEnum *adStatus, struct _Connection *pConnection);
  STDMETHODIMP raw_Disconnect(ADODB::EventStatusEnum *adStatus, struct _Connection *pConnection);
};


Thanks for any help you can provide!

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping

Moderator

Moderator

Joined:06 Jun 2002
Posts:1482
Location:London, UK
Reply with quote
OK, the other forum is stumped.
Sorry about that.

_________________
View user's profileFind all posts by AcidSend private messageSend e-mailVisit poster's websiteMSN Messenger
C++ Event Trapping

Moderator

Moderator

Joined:25 Jan 2003
Posts:1312
Location:England
Reply with quote
Eric are you sure the Advise method has two arguementss? You have pUnk & & dwConnEvt, should there only be one arguement here?
Code:
hr = pCP->Advise(pUnk, &dwConnEvt);
View user's profileFind all posts by batfinkSend private message
C++ Event Trapping

Moderator

Moderator

Joined:25 Jan 2003
Posts:1312
Location:England
Reply with quote
View user's profileFind all posts by batfinkSend private message
C++ Event Trapping

Moderator

Moderator

Joined:23 Sep 2002
Posts:949
Location:St. Louis, MO
Reply with quote
Well then they are a bunch of poop heads

_________________
Sometimes you feel like a nut, and sometimes you don't.
View user's profileFind all posts by EricMEvansSend private messageAIM AddressYahoo MessengerICQ Number
C++ Event Trapping
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
All times are GMT - 6 Hours  
Page 1 of 2  


  
  
 Reply to topic