Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

DllCall and structure with strings


  • Please log in to reply
9 replies to this topic
Peter
  • Members
  • 448 posts
  • Last active: Jan 15 2010 05:41 AM
  • Joined: 30 Dec 2005
I want to use a dll for compressing files to zip format. I found zip32.dll here.
As far as I understand it, it seems to need a structure with strings (and others) for DllCall.
Is it possible to use this DLL with strings structure in AutoHotkey?
Thanks
(From WinDll.txt included in the download:)
BOOL WINAPI ZpSetOptions(ZPOPT)
typedef struct {
LPSTR Date;             /* Date to include after */
LPSTR szRootDir;        /* Directory to use as base for zipping */
LPSTR szTempDir;        /* Temporary directory used during zipping */
BOOL fTemp;             /* Use temporary directory '-b' during zipping */
BOOL fSuffix;           /* include suffixes (not implemented in WiZ) */
BOOL fEncrypt;          /* encrypt files */
BOOL fSystem;           /* include system and hidden files */
BOOL fVolume;           /* Include volume label */
BOOL fExtra;            /* Exclude extra attributes */
BOOL fNoDirEntries;     /* Do not add directory entries */
BOOL fExcludeDate;      /* Exclude files earlier than specified date */
BOOL fIncludeDate;      /* Include only files earlier than specified date */
BOOL fVerbose;          /* Mention oddities in zip file structure */
BOOL fQuiet;            /* Quiet operation */
BOOL fCRLF_LF;          /* Translate CR/LF to LF */
BOOL fLF_CRLF;          /* Translate LF to CR/LF */
BOOL fJunkDir;          /* Junk directory names */
BOOL fGrow;             /* Allow appending to a zip file */
BOOL fForce;            /* Make entries using DOS names (k for Katz) */
BOOL fMove;             /* Delete files added or updated in zip file */
BOOL fDeleteEntries;    /* Delete files from zip file */
BOOL fUpdate;           /* Update zip file--overwrite only if newer */
BOOL fFreshen;          /* Freshen zip file--overwrite only */
BOOL fJunkSFX;          /* Junk SFX prefix */
BOOL fLatestTime;       /* Set zip file time to time of latest file in it */
BOOL fComment;          /* Put comment in zip file */
BOOL fOffsets;          /* Update archive offsets for SFX files */
BOOL fPrivilege;        /* Use privileges (WIN32 only) */
BOOL fEncryption;       /* TRUE if encryption supported, else FALSE.
                           this is a read-only flag */
int  fRecurse;          /* Recurse into subdirectories. 1 => -r, 2 => -R */
int  fRepair;           /* Repair archive. 1 => -F, 2 => -FF */
char fLevel;            /* Compression level (0 - 9) */
} ZPOPT, _far *LPZPOPT;


shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

structure with strings... Is it possible to use this DLL with strings structure in AutoHotkey?

typedef struct {
LPSTR Date;
...
}


Yes.

LPSTR is a null-terminated string, and is defined as a pointer to a character (uint1) array. For example:

VarSetCapacity( struct, struct_size, 0 )

date = Sunday, January 15, 2006

EncodeInteger( &date, 4, &struct, 0 )
etc.


Peter
  • Members
  • 448 posts
  • Last active: Jan 15 2010 05:41 AM
  • Joined: 30 Dec 2005
Thank you. :)
I hope I can get it working now.

Venia Legendi
  • Members
  • 35 posts
  • Last active: Apr 04 2011 08:36 PM
  • Joined: 27 May 2005
Hi Peter, did you get it working?

Peter
  • Members
  • 448 posts
  • Last active: Jan 15 2010 05:41 AM
  • Joined: 30 Dec 2005
Regarding my question about ZpSetOptions, it seems to work so far, but not the zip function itselfs. Because, as far as I understand you have to be able to use Callback for the ZpArchive function of the dll. At that point I gave up. And AFAIK it's not possible in AHK.
So, maybe it's possible to use in AHK, but it goes beyond my knowledge.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
No it is not possible to use callbacks in AHK.
That is why I urge so hard for & extension to return function address.

Acctually it is possible to do so, but it requires nasty hack and good ASM knowledge. Chris rised priority to & wish so lets hope it will come soon.

Btw, peter, you might be able to find dll that will be able to compress without callback function. I am sure you ca.
Posted Image

SamuelPlentz
  • Members
  • 19 posts
  • Last active: Oct 11 2011 11:25 PM
  • Joined: 26 Jul 2006
Hi, I have a similar problem. I want to call:
void __stdcall SetDefaultParams(ParamStruct* dps);

typedef struct {
    int size;
    DWORD VersionLow;
    DWORD VersionHigh;
    char FileName[MAX_PATH];
} ParamStruct;

But I can't get it to work. Here is what I got:
ParamStruct_FileName=C:\test.txt
VarSetCapacity(ParamStruct, 16, 0)
NumPut(16, ParamStruct, 0, "int")
NumPut(2 , ParamStruct, 4, "uint")
NumPut(0 , ParamStruct, 8, "uint")
;NumPut(0 , ParamStruct, 12, "uint")
EncodeInteger(&ParamStruct + 12, &ParamStruct_FileName)
DllCall("dllfile.dll\SetDefaultParams" ,"uint", &ParamStruct)

EncodeInteger(Destination, Value)
{
    DllCall("ntdll\RtlFillMemoryUlong", "Uint", Destination, "Uint", 4, "Uint", Value)
}
Perhaps it is the "char[MAX_PATH]" that makes trouble?

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Right, a char array in a struct is different from having a pointer to a string. The char array occupies space inside the struct equal to the size of the array. So, your struct will need to be much bigger than 16 bytes... maybe 272 bytes?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Should be something like:

[color=black]File := "C:\test.txt"
StructLen := 12 + StrLen( File ) + 1
VarSetCapacity( ParamStruct, StructLen, 0 )
NumPut( StructLen, ParamStruct, 0, "Int"  )
NumPut(  2, ParamStruct, 4, "UInt" )
StrPut( File, &ParamStruct+12 )

;DllCall("dllfile.dll\SetDefaultParams" ,"uint", &ParamStruct)
[/color]
_=_______________________________________________________________________

; A function pair to read/write strings from/to memory address.

StrPut( Str, @ ) {
Return DllCall( "RtlMoveMemory", UInt,@, UInt,&Str, UInt,StrLen(Str) )
}

StrGet( @ ) {
Return DllCall( "MulDiv", int,@, int,1, int,1, "Str" )
}


SamuelPlentz
  • Members
  • 19 posts
  • Last active: Oct 11 2011 11:25 PM
  • Joined: 26 Jul 2006
Thanks for your help!
SKAN, your example works like a charm.