CallDLL/WinDLL vs Python Wrapper Extension (Win32)

Tom Funk _spam_sux_tdfunk at _spam_sux_nettally.com
Thu Mar 23 22:18:19 EST 2000


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. |




More information about the Python-list mailing list