COM callbacks in Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #1

    COM callbacks in Python

    I need to register for a COM callback under Windows. I am using an ADO
    recordset interface like this:

    import win32com.client
    import time
    connect = win32com.client .Dispatch("ADOD B.Connection")
    recordset = win32com.client .Dispatch("ADOD B.Recordset")
    connect.Open("D river={SQLServe r};Server=devse rver;Database=V idVisitation;UI D=sa;PWD=;")
    datestring = time.strftime(" %m/%d/%Y")
    sql = "Select * from VisSchedule where SDATE='" + datestring +"'"
    recordset.Open( sql,connect)

    Now I want to receive events for the recordset when the recordset
    changes. Here is the IDL for the event:
    [id(0x0000000e)]
    HRESULT RecordsetChange Complete(
    [in] EventReasonEnum adReason,
    [in] Error* pError,
    [in, out] EventStatusEnum * adStatus,
    [in] _Recordset* pRecordset);

    How do I wire up the recordset I have created to receive this event?

  • Roger Upole

    #2
    Re: COM callbacks in Python


    "Dan" <danbrwn@gmail. com> wrote in message news:1143148427 .605756.205120@ g10g2000cwb.goo glegroups.com.. .[color=blue]
    >I need to register for a COM callback under Windows. I am using an ADO
    > recordset interface like this:
    >
    > import win32com.client
    > import time
    > connect = win32com.client .Dispatch("ADOD B.Connection")
    > recordset = win32com.client .Dispatch("ADOD B.Recordset")
    > connect.Open("D river={SQLServe r};Server=devse rver;Database=V idVisitation;UI D=sa;PWD=;")
    > datestring = time.strftime(" %m/%d/%Y")
    > sql = "Select * from VisSchedule where SDATE='" + datestring +"'"
    > recordset.Open( sql,connect)
    >
    > Now I want to receive events for the recordset when the recordset
    > changes. Here is the IDL for the event:
    > [id(0x0000000e)]
    > HRESULT RecordsetChange Complete(
    > [in] EventReasonEnum adReason,
    > [in] Error* pError,
    > [in, out] EventStatusEnum * adStatus,
    > [in] _Recordset* pRecordset);
    >
    > How do I wire up the recordset I have created to receive this event?
    >[/color]
    Use win32com.client .DispatchWithEv ents, and create a class that
    implements the event methods defined for the Recordset object.
    You can find prototypes for the methods in the makepy-generated
    file.

    Roger




    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

    Comment

    • Dan

      #3
      Re: COM callbacks in Python

      Looked at the makepy, code now looks like this:
      import win32com.client
      import win32gui
      import time
      import pythoncom
      finished = 0
      defaultNamedNot OptArg=pythonco m.Empty
      class ADOEvents:
      def OnRecordsetChan geComplete(self , adReason=defaul tNamedNotOptArg ,
      pError=defaultN amedNotOptArg, adStatus=python com.Missing,
      pRecordset=defa ultNamedNotOptA rg):
      print "recordset has changed"
      global finished
      finished=1
      connect = win32com.client .Dispatch("ADOD B.Connection")
      recordset =
      win32com.client .DispatchWithEv ents("ADODB.Rec ordset",ADOEven ts)
      connect.Open("D river={SQL
      Server};Server= devserver;Datab ase=VidVisitati on;UID=sa;PWD=; ")
      datestring = time.strftime(" %m/%d/%Y")
      sql = "Select * from VisSchedule where SDATE='" + datestring +"'"
      recordset.Open( sql,connect)
      while not finished:
      win32gui.PumpMe ssages()
      pass

      any idea why it doesn't work? Ive not really seen much on this in the
      newsgroups so any help would be greatly appreciated. I came upon a post
      by Paul Moore and and angusm describing code like this. angusm
      suggested that all of the interfaces must be implemented within the
      Events class, while Paul Moore suggested they didn't. Who is right?
      Here is the link to the thread:


      Comment

      • Dan

        #4
        Re: COM callbacks in Python

        Ok, seems to fire at least once now, had to implement
        OnWillChangeRec ordset as well. Definitely don't have to implement all
        the events though. Still not sure why its not acting like it should.
        Maybe I am looking at the wrong event? I want to know if the database
        has changed when someone else enters, edits etc... a record from
        another application. Ill investigate, if anyone knows, please help.

        Comment

        • Dan

          #5
          Re: COM callbacks in Python

          One final note, The code posted does work. Unfortunately, the event
          only fires for the ADO connection who actually triggered the event. In
          my opinion, completely useless event. So the Python worked, The ADO
          does not do what its name implies. Thanks to all. Dan

          Comment

          Working...