O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

C Strings and Passing by Reference

WinDLL also includes a class cstring that makes it easy to pass string or character buffer arguments back and forth. This class should be initialized with a Python string (which may be empty), and an optional length. Internally, cString maintains a buffer with a null-terminated string and the address of the buffer it passes to the DLL when used as an argument. To test this, the DLL exports a function StringRepeat that repeats a string a number of times:

>>> inBuf = cstring('spam')               # make a buffer holding a c string
>>> outBuf = cstring('',50)               # make another big enough for output
>>> mod1.StringRepeat(inBuf, outBuf, 10)  # returns the length of out string
40
>>> outBuf
'spamspamspamspamspamspamspamspamspamspam'

Rather than go any further, you can refer to the documentation and examples in the CallDLL and DynWin packages.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required