win32 COM and data types / direction

  • Thread starter Alexander Eisenhuth
  • Start date
A

Alexander Eisenhuth

Hello everybody,

i wonder how the win32 COM extension handles different C-int types
(short, int, long). Another question for me is weather the
"out-direction" of parameter is supported "out of the box" ?

To clarify look at the methode "FunWithTwoInts"
--------------------------------------------------------------------------
#SimpleCOMServer.py - A sample COM server - almost as small as they come!
#
# We expose a single method in a Python COM object
class PythonUtilities:
_public_methods_ = [ 'FunWithTwoInts' ]
_reg_progid_ = "PythonDemo.Utilities"

# NEVER copy the following ID!
# Use "print pythoncom.CreateGuid( )" to make a new one
_reg_clsid_ = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}"

def FunWithTwoInts(self, inShort, inInt, outSum):
print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum)
outSum = inShort + inInt

# Add code so that when this script is run by
# Python.exe, it self-registers
if __name__=='__main_ _':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
--------------------------------------------------------------------------
Does anybody have experiences in this ?

Any help/hints are very welcome.

Alexander
 
T

Thomas Heller

Alexander Eisenhuth said:
Hello everybody,

i wonder how the win32 COM extension handles different C-int types
(short, int, long). Another question for me is weather the
"out-direction" of parameter is supported "out of the box" ?

To clarify look at the methode "FunWithTwoInts"
--------------------------------------------------------------------------
#SimpleCOMServer.py - A sample COM server - almost as small as they come!
#
# We expose a single method in a Python COM object
class PythonUtilities:
_public_methods_ = [ 'FunWithTwoInts' ]
_reg_progid_ = "PythonDemo.Utilities"

# NEVER copy the following ID!
# Use "print pythoncom.CreateGuid( )" to make a new one
_reg_clsid_ = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}"

def FunWithTwoInts(self, inShort, inInt, outSum):
print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum)
outSum = inShort + inInt

# Add code so that when this script is run by
# Python.exe, it self-registers
if __name__=='__main_ _':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)

Since there is no type library, the client code has to guess. And it
will pass the server whatever the client calls with. That could even be
a string or anything else - but why not try it out?

*IF* there is a type library that the server implements, you will get
and return what it describes.

Thomas
 
T

Tim Roberts

Alexander Eisenhuth said:
Hello everybody,

i wonder how the win32 COM extension handles different C-int types
(short, int, long).

All of those types are passed on the stack as 32-bit dwords. No problem.
Another question for me is weather the
"out-direction" of parameter is supported "out of the box" ?

Yes, but you have to make them outputs from your function. Remember that
assigning to a parameter in Python does not change the parameter from the
caller's point of view:

def FunWithTwoInts( self, inShort, inInt ):
print "got as short:% as int%d" % (inShort, inInt)
return inShort + inInt

If you have multiple OUT parameters, you return a tuple of values.
To clarify look at the methode "FunWithTwoInts"
--------------------------------------------------------------------------
#SimpleCOMServer.py - A sample COM server - almost as small as they come!
#
# We expose a single method in a Python COM object
class PythonUtilities:
_public_methods_ = [ 'FunWithTwoInts' ]
_reg_progid_ = "PythonDemo.Utilities"

# NEVER copy the following ID!
# Use "print pythoncom.CreateGuid( )" to make a new one
_reg_clsid_ = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}"

def FunWithTwoInts(self, inShort, inInt, outSum):
print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum)
outSum = inShort + inInt

# Add code so that when this script is run by
# Python.exe, it self-registers
if __name__=='__main_ _':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
--------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top