Problems with COM

Jean-Louis Couturier jean-louis.replacebylastname at ixiasoft.com
Tue Jun 13 18:06:53 EDT 2000


Problem : I need to access an object created by an OUT variable in a
function call to a COM object.
Code example :

import win32com.client
import pythoncom

_testQueryString="""<?xml version="1.0" encoding="UTF-8"?><query
VERSION="1.0" RESULTSPACE="R1"><andkey><key
NAME="Date"><interval><start><date><year>1996</year><month>January</month><d
ay>4</day></date></start><end><date><year>1997</year><month>December</month>
<day>30</day></date></end></interval></key><key NAME="Full
Text"><elem>commission</elem></key></andkey></query>"""

def debug(msg):
    print "[DEBUG]",msg

def get_docbase_service(servername="jeanlouix", docbasename="TEXTML Demo"):
    debug("Connecting to COM server")
    clientService=win32com.client.Dispatch("TextmlServer.ClientServices")
    debug("Connecting to server "+servername)
    serverService=clientService.ConnectServer(servername)
    debug("Connecting to DocBase "+docbasename)
    docBaseService=serverService.ConnectDocBase(docbasename)
    return docBaseService

def query_server(docBaseService, queryString):
    searchService=docBaseService.SearchServices
    resultSpace=win32com.client.Dispatch
    debug("Querying... ")
    searchService.SearchDocuments(queryString,resultSpace)
    return resultSpace.Count

def main():
    docBaseService=get_docbase_service()
    print query_server(docBaseService,_testQueryString)

if __name__=="__main__":
    print "Testing pyTEXTMLServer"
    main()

My example above gives the following error on the line "return
resultSpace.Count":
AttributeError: Count
The resultSpace object is a COM object that cannot be created beforehand.
It has to be placed in a VARIANT that is fed to the function
SearchDocuments.  How do I do this?  I tried creating a Dispatch object
without specifying a type but it doesn't seem to work.

Thank you in advance for any solution or direction to relevant
documentation.
I will be happy to provide more details if I have not been precise enough.

Jean-Louis Couturier
Developer
Ixiasoft







More information about the Python-list mailing list