i want to use the UnRar dll functions but i need your Help Guys !

the Link:http://www.rarlab.com/rar_add.htm 3rd file
Thanks
Code: Select all
Global rar$="c:\.....yourdirectory\rar.exe"
;(...)
rarpackmode.s
If GetGadgetState(#Option_Fort) ; Strong packing
rarpackmode = "-m5"
Else
rarpackmode = "-m0" ; no packing
EndIf
Code: Select all
pass$=getgadgettext(#yourPassSting) ; password for rar
Size$=getgadgettext(#YouSizeChoice) ; if you want to cut your file in parts
Parameter$="a -s -ep -hp"+pass$+" "+rarpackmode+" "+"-v"+Size$+"m "+Chr(34)+Path$+nom_archive$+Chr(34)+" "+Chr(34)+File$+Chr(34)
Code: Select all
RunProgram(rar$,Parametre$,Fichier$,1)
Code: Select all
;PB_unRAR - Paul Leischow, Sept.6, 2002
;RAR Archive extractor that uses the free UNRAR.DLL
#RAR_OM_LIST=0
#RAR_OM_EXTRACT=1
#RAR_SKIP=0
#RAR_TEST=1
#RAR_EXTRACT=2
#RAR_VOL_ASK=0
#RAR_VOL_NOTIFY=1
#RAR_DLL_VERSION=3
Structure RARHeaderData
ArcName.b[260]
FileName.b[260]
Flags.l
PackSize.l
UnpSize.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.s
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
;rarheader.RARHeaderData
Structure RAROpenArchiveData
ArcName.s
OpenMode.l
OpenResult.l
CmtBuf.s
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
;raropen.RAROpenArchiveData
Global hDLL.l
Global *RAROpenArchiveEx.l
Global *RARCloseArchive.l
Global *RARReadHeaderEx.l
Global *RARProcessFileW.l
Global *RARSetChangeVolProc.l
Global *RARSetPassword.l
Global RarFile.s
OpenLibrary(0,"unrar.dll")
*RAROpenArchiveEx.l = GetFunction(0, "RAROpenArchiveEx")
*RARCloseArchive.l = GetFunction(0, "RARCloseArchive")
*RARReadHeaderEx.l = GetFunction(0, "RARReadHeaderEx")
*RARProcessFileW.l = GetFunction(0, "RARProcessFileW")
*RARSetChangeVolProc.l = GetFunction(0, "RARSetChangeVolProc")
*RARSetPassword.l = GetFunction(0, "RARSetPassword")
Procedure UnRar()
rarheader.RARHeaderData
raropen.RAROpenArchiveData
raropen\ArcName= RarFile
raropen\CmtBuf = Space(16384)
raropen\CmtBufSize = 16384
raropen\OpenMode=#RAR_OM_EXTRACT
hRAR=CallFunctionFast(*RAROpenArchiveEx,@raropen)
Debug hRAR
If raropen\OpenResult
MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR)
Else
Repeat
stat=CallFunctionFast(*RARReadHeaderEx,hRAR,@rarheader)
If stat=0
filelist.s=PeekS(@rarheader\FileName)
res=CallFunctionFast(*RARProcessFileW,hRAR,#RAR_EXTRACT,"","C:\testrar\"+filelist.s)
EndIf
Until stat<>0
MessageRequester("Files Extracted",filelist,#MB_ICONINFORMATION)
EndIf
CallFunctionFast(*RARCloseArchive,hRAR)
CloseLibrary(0)
EndProcedure
RarFile=OpenFileRequester("","C:\","WinRar (*.rar)|*.rar",0)
If RarFile :UnRar():EndIf
Code: Select all
RAROpenArchiveEx
RARReadHeaderEx
RARProcessFileW
Code: Select all
;PB_unRAR - Paul Leischow, Sept.6, 2002
;RAR Archive extractor that uses the free UNRAR.DLL
#ERAR_END_ARCHIVE = 10
#ERAR_NO_MEMORY = 11
#ERAR_BAD_DATA = 12
#ERAR_BAD_ARCHIVE = 13
#ERAR_UNKNOWN_FORMAT = 14
#ERAR_EOPEN = 15
#ERAR_ECREATE = 16
#ERAR_ECLOSE = 17
#ERAR_EREAD = 18
#ERAR_EWRITE = 19
#ERAR_SMALL_BUF = 20
#ERAR_UNKNOWN = 21
#ERAR_MISSING_PASSWORD = 22
#RAR_HEADERFLAG_ENCRYPTED = %00000100
#RAR_OM_LIST = 0
#RAR_OM_EXTRACT = 1
#RAR_OM_LIST_INCSPLIT = 2
#RAR_SKIP = 0
#RAR_TEST = 1
#RAR_EXTRACT = 2
#RAR_VOL_ASK = 0
#RAR_VOL_NOTIFY = 1
#RAR_DLL_VERSION = 4
Structure RARHeaderData
ArcName.b[260]
FileName.b[260]
Flags.l
PackSize.l
UnpSize.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
Structure RARHeaderDataEx
ArcName.b[1024]
ArcNameW.w[1024]
FileName.b[1024]
FileNameW.w[1024]
Flags.l
PackSize.l
PackSizeHigh.l
UnpSize.l
UnpSizeHigh.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
Reserved.l[1024]
EndStructure
Structure RAROpenArchiveData
*ArcName.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
Structure RAROpenArchiveDataEx
*ArcName.l
*ArcNameW.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
Flags.l
Reserved.l[32]
EndStructure
Global RarLib.l
Global RAROpenArchive.l
Global RARCloseArchive.l
Global RARReadHeader.l
Global RARProcessFile.l
Global RARSetCallback.l
Global RARSetChangeVolProc.l
Global RARSetProcessDataProc.l
Global RARSetPassword.l
Global RARGetDllVersion.l
Prototype.l Prot_RAROpenArchive(a.l)
Prototype.l Prot_RARCloseArchive(a.l)
Prototype.l Prot_RARReadHeader(a.l,b.l)
CompilerIf #PB_Compiler_Unicode=0
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-ascii,d.p-ascii)
CompilerElse
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-unicode,d.p-unicode)
CompilerEndIf
Prototype.l Prot_RARSetCallback(a.l,b.l,c.l)
Prototype.l Prot_RARSetChangeVolProc(a.l,b.l)
Prototype.l Prot_RARSetProcessDataProc(a.l,b.l)
CompilerIf #PB_Compiler_Unicode=0
Prototype.l Prot_RARSetPassword(a.l,b.p-ascii)
CompilerElse
Prototype.l Prot_RARSetPassword(a.l,b.p-unicode)
CompilerEndIf
Prototype.l Prot_RARGetDllVersion()
ProcedureDLL Rar_Init()
RarLib=OpenLibrary(#PB_Any,"unrar.dll")
If RarLib
CompilerIf #PB_Compiler_Unicode=0
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchive")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeader")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFile")
CompilerElse
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchiveEx")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeaderEx")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFileW")
CompilerEndIf
RARCloseArchive.Prot_RARCloseArchive = GetFunction(RarLib, "RARCloseArchive")
RARSetCallback.Prot_RARSetCallback = GetFunction(RarLib, "RARSetCallback")
RARSetChangeVolProc.Prot_RARSetChangeVolProc = GetFunction(RarLib, "RARSetChangeVolProc")
RARSetProcessDataProc.Prot_RARSetProcessDataProc = GetFunction(RarLib, "RARSetProcessDataProc")
RARSetPassword.Prot_RARSetPassword = GetFunction(RarLib, "RARSetPassword")
RARGetDllVersion.Prot_RARGetDllVersion = GetFunction(RarLib, "RARGetDllVersion")
EndIf
EndProcedure
ProcedureDLL Rar_End()
If RarLib
CloseLibrary(RarLib)
RarLib=0
EndIf
EndProcedure
Procedure UnRar(File$)
CompilerIf #PB_Compiler_Unicode=0
rarheader.RARHeaderData
raropen.RAROpenArchiveData
raropen\ArcName= @File$
CompilerElse
rarheader.RARHeaderDataEx
raropen.RAROpenArchiveDataEx
raropen\ArcNameW = @File$
CompilerEndIf
raropen\CmtBuf = 0
raropen\CmtBufSize = 0
raropen\OpenMode=#RAR_OM_EXTRACT
hRAR=RAROpenArchive(@raropen)
file.s=""
filelist.s=""
If raropen\OpenResult
MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR)
ProcedureReturn
EndIf
While RARReadHeader(hRAR,@rarheader)=0
CompilerIf #PB_Compiler_Unicode=0
file=PeekS(@rarheader\FileName)
CompilerElse
file=PeekS(@rarheader\FileNameW)
CompilerEndIf
Debug "File:"+file
filelist+file+Chr(10)
If rarheader\flags & #RAR_HEADERFLAG_ENCRYPTED
;Debug "#RAR_HEADERFLAG_ENCRYPTED"
RARSetPassword(hRAR,"free")
;MessageRequester("Error","file is password protected",#MB_ICONERROR)
EndIf
res=RARProcessFile(hRAR,#RAR_EXTRACT,"","C:\testrar\"+file)
Select res
Case #ERAR_BAD_DATA
Debug "File CRC error"
Case #ERAR_BAD_ARCHIVE
Debug "Volume is not valid RAR archive"
Case #ERAR_UNKNOWN_FORMAT
Debug "Unknown archive format"
Case #ERAR_EOPEN
Debug "Volume open error"
Case #ERAR_ECREATE
Debug "File create error"
Case #ERAR_ECLOSE
Debug "File close error"
Case #ERAR_EREAD
Debug "Read error"
Case #ERAR_EWRITE
Debug "Write error"
EndSelect
Wend
If filelist
MessageRequester("Files Extracted",filelist,#MB_ICONINFORMATION)
EndIf
If RARCloseArchive(hRAR)=#ERAR_ECLOSE
MessageRequester("RARCloseArchive","Archive close error",#MB_ICONINFORMATION)
EndIf
EndProcedure
Rar_Init()
RarFile$=OpenFileRequester("","","WinRar (*.rar)|*.rar",0)
If RarFile$
UnRar(RarFile$)
EndIf
Code: Select all
;PB_unRAR - Paul Leischow, Sept.6, 2002
;RAR Archive extractor that uses the free UNRAR.DLL
#ERAR_END_ARCHIVE = 10
#ERAR_NO_MEMORY = 11
#ERAR_BAD_DATA = 12
#ERAR_BAD_ARCHIVE = 13
#ERAR_UNKNOWN_FORMAT = 14
#ERAR_EOPEN = 15
#ERAR_ECREATE = 16
#ERAR_ECLOSE = 17
#ERAR_EREAD = 18
#ERAR_EWRITE = 19
#ERAR_SMALL_BUF = 20
#ERAR_UNKNOWN = 21
#ERAR_MISSING_PASSWORD = 22
#RAR_HEADERFLAG_ENCRYPTED = %00000100
#RAR_OM_LIST = 0
#RAR_OM_EXTRACT = 1
#RAR_OM_LIST_INCSPLIT = 2
#RAR_SKIP = 0
#RAR_TEST = 1
#RAR_EXTRACT = 2
#RAR_VOL_ASK = 0
#RAR_VOL_NOTIFY = 1
#RAR_DLL_VERSION = 4
Structure RARHeaderData
ArcName.b[260]
FileName.b[260]
Flags.l
PackSize.l
UnpSize.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
Structure RARHeaderDataEx
ArcName.b[1024]
ArcNameW.w[1024]
FileName.b[1024]
FileNameW.w[1024]
Flags.l
PackSize.l
PackSizeHigh.l
UnpSize.l
UnpSizeHigh.l
HostOS.l
FileCRC.l
FileTime.l
UnpVer.l
Method.l
FileAttr.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
Reserved.l[1024]
EndStructure
Structure RAROpenArchiveData
*ArcName.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
EndStructure
Structure RAROpenArchiveDataEx
*ArcName.l
*ArcNameW.l
OpenMode.l
OpenResult.l
*CmtBuf.l
CmtBufSize.l
CmtSize.l
CmtState.l
Flags.l
Reserved.l[32]
EndStructure
Global RarLib.l
Global RAROpenArchive.l
Global RARCloseArchive.l
Global RARReadHeader.l
Global RARProcessFile.l
Global RARSetCallback.l
Global RARSetChangeVolProc.l
Global RARSetProcessDataProc.l
Global RARSetPassword.l
Global RARGetDllVersion.l
Prototype.l Prot_RAROpenArchive(a.l)
Prototype.l Prot_RARCloseArchive(a.l)
Prototype.l Prot_RARReadHeader(a.l,b.l)
CompilerIf #PB_Compiler_Unicode=0
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-ascii,d.p-ascii)
CompilerElse
Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-unicode,d.p-unicode)
CompilerEndIf
Prototype.l Prot_RARSetCallback(a.l,b.l,c.l)
Prototype.l Prot_RARSetChangeVolProc(a.l,b.l)
Prototype.l Prot_RARSetProcessDataProc(a.l,b.l)
Prototype.l Prot_RARSetPassword(a.l,b.p-ascii)
Prototype.l Prot_RARGetDllVersion()
ProcedureDLL Rar_Init()
RarLib=OpenLibrary(#PB_Any,"unrar.dll")
If RarLib
CompilerIf #PB_Compiler_Unicode=0
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchive")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeader")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFile")
CompilerElse
RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchiveEx")
RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeaderEx")
RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFileW")
CompilerEndIf
RARCloseArchive.Prot_RARCloseArchive = GetFunction(RarLib, "RARCloseArchive")
RARSetCallback.Prot_RARSetCallback = GetFunction(RarLib, "RARSetCallback")
RARSetChangeVolProc.Prot_RARSetChangeVolProc = GetFunction(RarLib, "RARSetChangeVolProc")
RARSetProcessDataProc.Prot_RARSetProcessDataProc = GetFunction(RarLib, "RARSetProcessDataProc")
RARSetPassword.Prot_RARSetPassword = GetFunction(RarLib, "RARSetPassword")
RARGetDllVersion.Prot_RARGetDllVersion = GetFunction(RarLib, "RARGetDllVersion")
EndIf
EndProcedure
ProcedureDLL Rar_End()
If RarLib
CloseLibrary(RarLib)
RarLib=0
EndIf
EndProcedure
Procedure UnRar(File$)
CompilerIf #PB_Compiler_Unicode=0
rarheader.RARHeaderData
raropen.RAROpenArchiveData
raropen\ArcName= @File$
CompilerElse
rarheader.RARHeaderDataEx
raropen.RAROpenArchiveDataEx
raropen\ArcNameW = @File$
CompilerEndIf
raropen\CmtBuf = AllocateMemory(16384)
raropen\CmtBufSize = 16384
raropen\OpenMode=#RAR_OM_EXTRACT
hRAR=RAROpenArchive(@raropen)
Debug hRAR
file.s=""
filelist.s=""
stat=RARReadHeader(hRAR,@rarheader);without this line,can't check file header
;and no file extract after
If raropen\OpenResult
MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR)
ElseIf rarheader\flags & #RAR_HEADERFLAG_ENCRYPTED
;MessageRequester("Error","file is password protected",#MB_ICONERROR)
;Else
Repeat
stat=RARReadHeader(hRAR,@rarheader);
If stat=0
CompilerIf #PB_Compiler_Unicode=0
file=PeekS(@rarheader\FileName)
CompilerElse
file=PeekS(@rarheader\FileNameW)
CompilerEndIf
filelist+file+Chr(10)
RARSetPassword(hRAR,"free")
res=RARProcessFile(hRAR,#RAR_EXTRACT,"","C:\testrar\"+file)
EndIf
Until stat<>0
MessageRequester("Files Extracted",filelist,#MB_ICONINFORMATION)
EndIf
RARCloseArchive(hRAR)
EndProcedure
Rar_Init()
RarFile$=OpenFileRequester("","C:\","WinRar (*.rar)|*.rar",0)
If RarFile$
UnRar(RarFile$)
EndIf
Changed my above example, it should work nowMicko wrote:just to check if file is password protected but in my program it run and just extract one fileso here nothing
![]()