CallDLL/WinDLL vs Python Wrapper Extension (Win32)

Sam Schulenburg samschul at pacbell.net
Fri Mar 24 00:15:30 EST 2000


As I recall their are examples , which I believe you allready found,
that discribe the use of Sam's structure module. Look also at the basic
Python struct module. I found that this helped in understanding Sam's
stuff. I did not need to use structures that were as complex as yours.

> In an article posted Fri, 24 Mar 2000 00:49:11 GMT,
> Sam Schulenburg (samschul at pacbell.net) said:
>
> > I have used windll with great success.
>
> That's good to know. I've at least tentatively started down this
path.
> I'm just mocking up some of the more simple functions seeing how this
> will fall out.
>
> > The biggest problem is maping
> > python data types to C data types using the struct module.
>
> I'm seeing that already. A couple of the structs that get passed back
to
> the callback functions contain buffers inside the structs themselves,
> rather than pointers to buffers.
>
> For example, given this typedef:
>
> typedef struct pborca_direntry {
> TCHAR szComments[PBORCA_MAXCOMMENT + 1]; /* Comments */
> LONG lCreateTime; /* Time of entry create/mod */
> LONG lEntrySize; /* Size of entry */
> LPTSTR lpszEntryName; /* Pointer to entry name */
> PBORCA_TYPE otEntryType; /* Entry type */
> } PBORCA_DIRENTRY, FAR *PPBORCA_DIRENTRY;
>
> PBORCA_MAXCOMMENT is 255, making the comments buffer 256 bytes long.
> Also, PBORCA_TYPE is an enum.
>
> Would I create a structure object, thus:
>
> MAXCOMMENT = 256
> class DirEntry(structob.struct_object):
> oracle = structob.Oracle (
> 'Directory Entry',
> 'N%dcllll' % MAXCOMMENT, (
> 'comments',
> 'createTime',
> 'entrySize',
> 'entryName',
> 'entryType'
> )
> )
>
> direntry = DirEntry()
>
> Given this, how do I extract the entryName (LPZSTR) and the comments
> (buffer) items into Python strings?
>
> The callback functions also require a user-defined buffer that the
API
> does nothing with. The API only sends the buffer to the callback for
it
> to use how it sees fit. Since the API ignores this buffer, should I
also
> use an Oracle call to create a buffer/structure of my own making and
use
> it to accumulate data between calls? I'm assuming that using a Python
> object wouldn't work -- or would it?
>
> Of course, all of this assumes that I can grok Sam Rushing's code
well
> enough to figure out how to actually define a Python callback
> function.... <g>
>
> > I think this is the fastest way to proceed with a known dll.
>
> Well, we'll see how it goes. At this point, my head's about to
> explode.... hehehe I love it!
>
> Thanks for the help, Sam.
>
> --
> -=< tom >=-
> Thomas D. Funk | "Software is the lever
> Software Engineering Consultant | Archimedes was searching for"
> Advanced Systems Design, Tallahassee FL. |
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list