Struct and windll question (please help)

Calishar calishar at *NOSPAM*home.com
Mon Dec 6 17:07:52 EST 1999


Hi folks,

  Since i havent received a successful answer yet, I am going to
repost the question, with examples. Sorry about the length, but I am
starting to lose my hair over this, it seems like it should be simple,
but I think my brain is teasing me.

  I am trying to call the infozip unzip32.dll (on a windows 95 system
at the moment, but eventually on a winNT system too) in order to unzip
a pkzip file (not gzip). Zlib doesn't seem to understand this type of
file, so I am having to go outside standard python stuff.

  The calldll module has a function (call_foreign_function(address,
input_args_format, result_args_format, argument_tuple)) which should
be able to do what I need. What I am having problems with is
constructing the format strings and tuple.

  The best effort I have had so far had an interesting error message
when it failed----- expected impossible. 

  Could someone who truly understands this better than I do (not hard
at the moment, no brain cells left) please post a sample code snippet
that I can work from?


  The dll function I am calling has the following definition:

Wiz_SingleEntryUnzip(int ifnc, char **ifnv, int xfnc, char **xfnv,
                     LPDCL lpDCL, LPUSERFUNCTIONS lpUserFunc)

where ifnv and xfnv can be Null. (I think the format code should be
'i255si255s??' (no idea for the structs) or (iPiP??) using the struct
module codes. Or should I be using the codes from PyArg_ParseTuple?
I am creating the two structs using struct.pack at the moment, is this
right?


  The LPDCL structure has the following definition

typedef struct {
int ExtractOnlyNewer;   = true if you are to extract only newer
int SpaceToUnderscore;  = true if convert space to underscore
int PromptToOverwrite;  = true if prompt to overwrite is wanted
int fQuiet;             = quiet flag. 1 = few messages, 2 = no
messages, 0 = all messages
int ncflag              = write to stdout if true
int ntflag              = test zip file
int nvflag              = verbose listing
int nUflag              = "update" (extract only newer/new files)
int nzflag              = display zip file comment
int ndflag              = all args are files/dir to be extracted
int noflag              = true if you are to always over-write files,
false if not
int naflag              = do end-of-line translation
int nZIflag;            = get zip info if true
int C_flag;             = be case insensitive if TRUE
int fPrivilege          = 1 => restore Acl's, 2 => Use privileges
LPSTR lpszZipFN         = zip file name
LPSTR lpszExtractDir    = Directory to extract to. This should be NULL
if you
                          are extracting to the current directory.
} DCL, far * LPDCL;

and the LPUSERFUNCTIONS struct has this defintion:

typedef unsigned short ush;
typedef int (WINAPI DLLPRNT) (LPSTR, unsigned long);
typedef int (WINAPI DLLPASSWORD) (LPSTR, int, LPCSTR, LPCSTR);
typedef int (WINAPI DLLSERVICE) (LPSTR, unsigned long);
typedef void (WINAPI DLLSND) (void);
typedef int (WINAPI DLLREPLACE)(LPSTR);
typedef void (WINAPI DLLMESSAGE)(unsigned long, unsigned long,
unsigned,
   unsigned, unsigned, unsigned, unsigned, unsigned,
   char, LPSTR, LPSTR, unsigned long, char);

Structure USERFUNCTIONS

typedef struct {
DLLPRNT *print;         = a pointer to the application's print
routine.
DLLSND *sound;          = a pointer to the application's sound
routine. This
                          can be NULL if your application doesn't use
                          sound.
DLLREPLACE *replace     = a pointer to the application's replace
routine.
DLLPASSWORD *password   = a pointer to the application's password
routine.
DLLMESSAGE *SendApplicationMessage = a pointer to the application's
routine
                          for displaying information about specific
files
                          in the archive. Used for listing the
contents of
                          an archive.
DLLSERVICE *ServCallBk  = Callback function designed to be used for
                          allowing the application to process Windows
messages,
                          or canceling the operation, as well as
giving the
                          option of a progress indicator. If this
function
                          returns a non-zero value, then it will
terminate
                          what it is doing. It provides the
application with
                          the name of the name of the archive member
it has
                          just processed, as well as it's original
size.
NOTE: The values below are filled in only when listing the contents of
an
      archive.

unsigned long TotalSizeComp = value to be filled in by the dll for the
                          compressed total size of the archive. Note
this
                          value does not include the size of the
archive
                          header and central directory list.
unsigned long TotalSize = value to be filled in by the dll for the
total
                          size of all files in the archive.
int CompFactor          = value to be filled in by the dll for the
overall
                          compression factor. This could actually be
computed
                          from the other values, but it is available.
unsigned int NumMembers = total number of files in the archive.
WORD cchComment;        = flag to be set if archive has a comment
} USERFUNCTIONS, far * LPUSERFUNCTIONS;

Thanks for reading this far

Calishar





More information about the Python-list mailing list