[python-win32] win32com calling C++ COM interface

Mark Hammond mhammond at skippinet.com.au
Wed Oct 19 23:57:16 CEST 2005


Your code is explicitly creating a buffer object, which the win32com
framework translates as "array of bytes".  Try just passing a list (or
tuple) of integers instead of the buffer.

Mark
  -----Original Message-----
  From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of Shad Muegge
  Sent: Thursday, 20 October 2005 6:23 AM
  To: python-win32 at python.org
  Subject: [python-win32] win32com calling C++ COM interface


  Hi,

  I've just started looking at Python.  I am trying to resolve an issue a
user is having trying to access the COM interface in our application from
Python.

  C++ code:

  STDMETHODIMP
  CMyClass::Read(
    const int   x,
    VARIANT  *indexlist,          // IN:  "safe" array of  4-byte integers
    VARIANT  *results)


  Python code:

      def read(self, x, addr):
          try:
              addr = buffer(array.array('L', addr))
              data = self.__Api.Read(x, addr)
  ...

  x.read(0, 0x12345678)

  The variant that shows up on the C++ code is a safearray of 1-byte
integers with 4 elements: 12, 34, 56, 78.

  The API treats them each as individual "addresses"...

  Here's the COM definition from the .py file.

   def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg,
results=pythoncom.Missing):
    """method Read"""
    return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396,
2)), 'Read', None,x
     , indexlist, results)

  Thanks,
  Shad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051020/7040a424/attachment.htm


More information about the Python-win32 mailing list