473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

COM callbacks in Python

Dan
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("ADODB.Connection")
recordset = win32com.client.Dispatch("ADODB.Recordset")
connect.Open("Driver={SQLServer};Server=devserver; Database=VidVisitation;UID=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 RecordsetChangeComplete(
[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?

Mar 23 '06 #1
4 1721

"Dan" <da*****@gmail.com> wrote in message news:11**********************@g10g2000cwb.googlegr oups.com...
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("ADODB.Connection")
recordset = win32com.client.Dispatch("ADODB.Recordset")
connect.Open("Driver={SQLServer};Server=devserver; Database=VidVisitation;UID=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 RecordsetChangeComplete(
[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?

Use win32com.client.DispatchWithEvents, 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 =---
Mar 24 '06 #2
Dan
Looked at the makepy, code now looks like this:
import win32com.client
import win32gui
import time
import pythoncom
finished = 0
defaultNamedNotOptArg=pythoncom.Empty
class ADOEvents:
def OnRecordsetChangeComplete(self, adReason=defaultNamedNotOptArg,
pError=defaultNamedNotOptArg, adStatus=pythoncom.Missing,
pRecordset=defaultNamedNotOptArg):
print "recordset has changed"
global finished
finished=1
connect = win32com.client.Dispatch("ADODB.Connection")
recordset =
win32com.client.DispatchWithEvents("ADODB.Recordse t",ADOEvents)
connect.Open("Driver={SQL
Server};Server=devserver;Database=VidVisitation;UI D=sa;PWD=;")
datestring = time.strftime("%m/%d/%Y")
sql = "Select * from VisSchedule where SDATE='" + datestring +"'"
recordset.Open(sql,connect)
while not finished:
win32gui.PumpMessages()
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:
http://groups.google.com/group/comp....2f9ce9ac6403f4

Mar 24 '06 #3
Dan
Ok, seems to fire at least once now, had to implement
OnWillChangeRecordset 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.

Mar 24 '06 #4
Dan
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

Mar 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: achrist | last post by:
I'm aving some trouble getting callbacks from a Delphi DLL back to python working through ctypes. The call from python to the DLL works fine. In the Delphi(5) code: type TCallbackFunc =...
3
by: Paul Moore | last post by:
I'm trying to check a graph (represented in the usual Python adjacency list format) for loops. This is dead simple - you use a depth-first search, and look out for "back edges" (edges from a vertex...
1
by: Melissa Wallis | last post by:
I have a class with 5 callbacks. Two of the callbacks work fine but the others don't. The main difference is that the callbacks that don't work are composed of a sequence of structs. I noticed a...
4
by: Randall Hopper | last post by:
What is the correct way to propagate exceptions from Python callbacks? When I do this: Python -> C++ -> Python Callback (example attached) an exception raised in the callback doesn't make it...
1
by: geoffschmidt | last post by:
I'm trying to write an extension in C that delivers callbacks to Python. The C code starts several threads, and I'd like one of the new threads that is started to be able to deliver callbacks to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.