[python-win32] Byte arrays and COM

Dave Cross Dave.Cross at cdl.co.uk
Tue Mar 2 15:41:50 CET 2010


Hi All,
 
I'm tying myself in knots trying to pass a byte array between a C++ DLL
and python.
 
The simplified IDl looks like this:
    HRESULT Test([in,out] int *len, [in,out, size_is(*len)] byte* outp);
 and the implementation does this:
    STDMETHODIMP CComTestObj::Test(int *len, unsigned char* outp)
    {
     printf("input param is <%d>  %s at  %lx,\n",*len, outp, outp);
     strncpy((char*)outp,"TEST",*len);
     return S_OK;    
    }

Makepy generates the following:
 
     def Test(self, len=defaultNamedNotOptArg,
outp=defaultNamedNotOptArg):
          """method Test"""
          return self._ApplyTypes_(6, 1, (24, 0), ((16387, 3), (16401,
3)), u'Test', None,len, outp)
 
I interpret (16387,3) as VT_I4, ByREF, In & Out and (16401,3) as VT_UI1,
ByRef In & Out so this looks OK to me.
 
However when I call it like this:
 
     object = win32com.client.Dispatch("ComTest.ComTestObj.1")
     test = create_string_buffer("Hello")
     print "Test is ", object.Test(6,addressof(test))

Then
          a) The C++ routine gets an address that doesn't map to the
input string 
and     b) the returned value is (3, 84)
 
Any ideas as to where I'm going wrong would be much appreciated.
 
Dave.
 
 

</PRE>
<p style="font-family:'Arial';font-size:8pt">
**********************************************************************<br>
Please consider the environment - do you really need to print this email?<br>
<br>
This email is intended only for the person(s) named above and may contain private and confidential information. If it has come to you in error, please destroy and permanently delete any copy in your possession and contact us on +44 (0) 161 480 4420. The information in this email is copyright &copy; CDL Group Holdings Limited. We cannot accept any liability for any loss or damage sustained as a result of software viruses. It is your responsibility to carry out such virus checking as is necessary before opening any attachment.<br>
Cheshire Datasystems Limited uses software which automatically screens incoming emails for inappropriate content and attachments. If the software identifies such content or attachment, the email will be forwarded to our Technology Department for checking. You should be aware that any email which you send to Cheshire Datasystems Limited is subject to this procedure. <br>
Cheshire Datasystems Limited, Strata House, Kings Reach Road, Stockport SK4 2HD<br>
Registered in England and Wales with Company Number 3991057<br>
VAT registration: 727 1188 33</p>
<PRE> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100302/c2a5ac87/attachment.html>


More information about the python-win32 mailing list