<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16981" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>Hi
All,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=377422214-02032010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>I'm tying myself in
knots trying to pass a byte array between a C++ DLL and
python.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=377422214-02032010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>The simplified IDl
looks like this:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>
HRESULT Test([in,out] int *len, [in,out, size_is(*len)] byte*
outp);</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010> and the
implementation does this:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>
STDMETHODIMP CComTestObj::Test(int *len, unsigned char*
outp)<BR> {<BR></SPAN></FONT><FONT face=Arial size=2><SPAN
class=377422214-02032010> printf("input param is
<%d> %s at %lx,\n",*len, outp,
outp);<BR>
strncpy((char*)outp,"TEST",*len);<BR> return
S_OK; <BR> }<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>Makepy generates the
following:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=377422214-02032010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010>
def Test(self, len=defaultNamedNotOptArg,
outp=defaultNamedNotOptArg):<BR> """method
Test"""<BR> return
self._ApplyTypes_(6, 1, (24, 0), ((16387, 3), (16401, 3)), u'Test', None,len,
outp)</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial size=2>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.</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial size=2>However when I call
it like this:</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2> object =
win32com.client.Dispatch("ComTest.ComTestObj.1")<BR> test
= create_string_buffer("Hello")<BR> print "Test is ",
object.Test(6,addressof(test))<BR></FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2>Then</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2> a) The C++
routine gets an address that doesn't map to the input string
</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial size=2>and
b) the returned value is (3, 84)</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial size=2>Any ideas as to
where I'm going wrong would be much appreciated.</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2>Dave.</FONT></SPAN></DIV>
<DIV><SPAN class=377422214-02032010><FONT face=Arial
size=2> </DIV></FONT></SPAN>
<DIV><FONT face=Arial size=2><SPAN class=377422214-02032010> </DIV>
<DIV><BR></DIV></SPAN></FONT><pre></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 © 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>
</pre></BODY></HTML>