I don't know much about dll and all, but this seems right to me:
SevenZipCMD(sCMDLine, hWnd = 0)
result := DllCall(7-zip32.dll, "int", "SevenZip", "hwnd", %hWnd%, "str", %sCMDLine%, "str", 0)
If errorlevel
Return 0
ExitApp
else
Return 1
ExitApp
There are
various errors in the above. The least obvious of which is that DllCall accepts different parameters in AutoIt3:
DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]] )
AutoHotkey:
Result := DllCall("[DllFile\]Function" [, Type1, Arg1, Type2, Arg2, "Cdecl ReturnType"])
Directly translating the AutoIt3 function to AutoHotkey results in:
_SevenZipCMD(sCMDLine, hWnd = 0)
{
dll := DllCall("LoadLibrary", "str", "7-zip32.dll")
result := DllCall("7-zip32.dll\SevenZip", "uint", hWnd, "str", sCMDLine, "str", 0, "int")
if ErrorLevel
{
ErrorLevel = 1
return 0
}
DllCall("FreeLibrary", "uint", dll)
return 1
}
However,[*:y8ns7hgz]The DllOpen/DllClose/LoadLibrary/FreeLibrary calls are superfluous since DllCall will automatically do this (in both languages.)
[*:y8ns7hgz]The ErrorLevel checks seem unnecessary, and if the DllCall fails, the DLL is not unloaded! (until the script exits.)
[*:y8ns7hgz]I'm assuming
"str",0 in AutoIt3 passes a valid pointer to a string of characters (containing the character '0'). That is what AutoHotkey does, but for all I know AutoIt3 might pass a NULL pointer instead.
_SevenZipCMD(sCMDLine, hWnd = 0) {
return DllCall("7-zip32.dll\SevenZip", "uint", hWnd, "str", sCMDLine, "str", 0)
}
Now the question is whether the AutoIt3 function had the usage correct...
The "original API description file" PhiLho linked to has this:
-----------------------------------------------------------------------
int WINAPI SevenZip(const HWND _hwnd, LPCSTR _szCmdLine,
LPSTR _szOutput, const DWORD _dwSize)
-----------------------------------------------------------------------
Number 1
Function
Compression thawing and the like is done.
Argument
_hwnd The window handle of the application which calls 7-zip32.dll.
7-zip32.dll EnableWindow () executes the execution time vis-a-vis this window and controls the operation of the window.
It is the console application where the window does not exist when and, when it is not necessary to appoint, NULL is transferred.
_szCmdLine The command character string which transfers to 7-zip32.dll.
_szOutput The buffer because 7-zip32.dll returns the result.
When it is global memory or like that, it is necessary to be locked.
_dwSize Größe des Puffers.
When the result exceeds designated size, it is economized in this size.
If size is 1 or more, always NULL letter is added lastly.
So it appears SevenZip() has an extra parameter that the AutoIt3 function omitted! You could try:
_SevenZipCMD(sCMDLine, hWnd = 0) {
return DllCall("7-zip32.dll\SevenZip", "uint", hWnd, "str", sCMDLine, "uint", 0, "uint", 0)
}
This passes a NULL pointer as _szOutput and zero for _dwSize. I'm guessing SevenZip() ignores the output buffer if it is a NULL pointer. If not, you'll need to provide a buffer of sufficient size for the output. (I'm not sure what the output would be.)
_SevenZipCMD(sCMDLine, hWnd = 0) {
buffer_size := VarSetCapacity(buffer, 1024**2) ; how to decide how big it should be?
return DllCall("7-zip32.dll\SevenZip", "uint", hWnd, "str", sCMDLine, "str", buffer, "uint", buffer_size)
}
Obviously untested...
Maybe _szOutput is for statistics/operational information rather than the resulting compressed data? If that is the case, it is likely optional (i.e. may be "uint",0,"uint",0.)