UnRAROCX.ocx and unrar.dll

  • Thread starter Thread starter Ben S
  • Start date Start date
B

Ben S

Hello all,

Has anyone managed to use the UnRAR OCX from www.rarlabs.com ?
Or even the unRAR.dll file using declares ?

If so, how ? :)

With the ocx I get in interop error message, with the dll I get a Null
exception on the "ReadRARHeader" function.

If anyone can help or wants to see the code just drop me a mail/message.
Hope someones had more luck than me !

Thanks
Ben S
---
 
Hello all,

Has anyone managed to use the UnRAR OCX from www.rarlabs.com ?
Or even the unRAR.dll file using declares ?

If so, how ? :)

With the ocx I get in interop error message, with the dll I get a Null
exception on the "ReadRARHeader" function.

If anyone can help or wants to see the code just drop me a mail/message.
Hope someones had more luck than me !

I haven't used either - but the null reference exception is more then
likely because of improper declaration. Can you post your declaration
of the function and the original C/C++ prototype?

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"I teleported home one night
With Ron and Sid and Meg.
Ron stole Meggie's heart away
And I got Sidney's leg."

- A poem about matter transference beams.
 
Hello Tom,

OK, these are the original Strutures and DLL declares.
(from the VB6 Expamle)

Private Type RARHeaderData
ArcName As String * 260
FileName As String * 260
Flags As Long
PackSize As Long
UnpSize As Long
HostOS As Long
FileCRC As Long
FileTime As Long
UnpVer As Long
Method As Long
FileAttr As Long
CmtBuf As String
CmtBufSize As Long
CmtSize As Long
CmtState As Long
End Type

Private Type RAROpenArchiveData
ArcName As String
OpenMode As Long
OpenResult As Long
CmtBuf As String
CmtBufSize As Long
CmtSize As Long
CmtState As Long
End Type

Private Declare Function RAROpenArchive Lib "unrar.dll" (ByRef ArchiveData
As RAROpenArchiveData) As Long
Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As
Long) As Long
Private Declare Function RARReadHeader Lib "unrar.dll" (ByVal hArcData As
Long, ByRef HeaderData As RARHeaderData) As Long
Private Declare Function RARProcessFile Lib "unrar.dll" (ByVal hArcData As
Long, ByVal Operation As Long, ByVal DestPath As String, ByVal DestName As
String) As Long
Private Declare Sub RARSetChangeVolProc Lib "unrar.dll" (ByVal hArcData As
Long, ByVal Mode As Long)
Private Declare Sub RARSetPassword Lib "unrar.dll" (ByVal hArcData As Long,
ByVal Password As String)

-------------------------------New------------------
These are the structures and DLL calls I used after changing them:

Private Type RARHeaderData
ArcName As String
FileName As String
Flags As Integer
PackSize As Integer
UnpSize As Integer
HostOS As Integer
FileCRC As Integer
FileTime As Integer
UnpVer As Integer
Method As Integer
FileAttr As Integer
CmtBuf As String
CmtBufSize As Integer
CmtSize As Integer
CmtState As Integer
End Type

Private Type RAROpenArchiveData
ArcName As String
OpenMode As Integer
OpenResult As Integer
CmtBuf As String
CmtBufSize As Integer
CmtSize As Integer
CmtState As Integer
End Type

Private Declare Function RAROpenArchive Lib "unrar.dll" (ByRef ArchiveData
As RAROpenArchiveData) As Integer
Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As
Integer) As Integer
Private Declare Function RARReadHeader Lib "unrar.dll" (ByVal hArcData As
Integer, ByRef HeaderData As RARHeaderData) As Integer
Private Declare Function RARProcessFile Lib "unrar.dll" (ByVal hArcData As
Integer, ByVal Operation As Integer, ByVal DestPath As String, ByVal
DestName As String) As Integer
Private Declare Sub RARSetChangeVolProc Lib "unrar.dll" (ByVal hArcData As
Integer, ByVal Mode As Integer)
Private Declare Sub RARSetPassword Lib "unrar.dll" (ByVal hArcData As
Integer, ByVal Password As String)


I've also tried making the strings like this in the structure this:
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=260)>Dim ArcName as String

And the same for FileName and CmtBuf but it still brings up the same error

"An unhandled exception of type 'System.NullReferenceException; occured in
RarOCXTest.exe

Additional information: Object reference not set to an instance of an
object."

Hope that's of some use. It all seems to be OK to me, but I can't spot
where I'm going wrong

Thanks
Ben S
 
Hello Tom,

OK, these are the original Strutures and DLL declares.
(from the VB6 Expamle)

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure RARHeaderData

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public ArcName As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public FileName As String

Public Flags As Integer
Public PackSize As Integer
Public UnpSize As Integer
Public HostOS As Integer
Public FileCRC As Integer
Public FileTime As Integer
Public UnpVer As Integer
Public Method As Integer
Public FileAttr As Integer
Public CmtBuf As String
Public CmtBufSize As Integer
Public CmtSize As Integer
Public CmtState As Integer
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>_
Private Structure RAROpenArchiveData
Public ArcName As String
Public OpenMode As Integer
Public OpenResult As Integer
Public CmtBuf As String
CmtBufSize As Integer
Public CmtSize As Integer
Public CmtState As Integer
End Structure

Private Declare Ansi Function RAROpenArchive Lib "unrar.dll" _
(ByRef ArchiveData As RAROpenArchiveData) As Integer

' using integer, but probably should by System.IntPtr
Private Declare Function RARCloseArchive Lib "unrar.dll" _
(ByVal hArcData As Integer) As Integer

Private Declare Ansi Function RARReadHeader Lib "unrar.dll" _
(ByVal hArcData As Integer, _
ByRef HeaderData As RARHeaderData) As Integer

Private Declare Ansi Function RARProcessFile Lib "unrar.dll" _
(ByVal hArcData As Integer, _
ByVal Operation As Integer, _
ByVal DestPath As String, _
ByVal DestName As String) As Integer

Private Declare Sub RARSetChangeVolProc Lib "unrar.dll" _
(ByVal hArcData As Integer, _
ByVal Mode As Integer)

Private Declare Ansi Sub RARSetPassword Lib "unrar.dll" _
(ByVal hArcData As Integer, ByVal Password As String)


With out looking at the docs, this is what I would do...
 
Hello there,
With out looking at the docs, this is what I would do...

Without looking at the docs, you've solved my problem ! I never did like
APIs ;)
If there's a place to vote you for to keep the MVP send me the link !!

Thanks Tom, your help is appreciated greatly, you're one of the people that
make the Internet a good place to be.

Right I'm off to introduce this to a couple of apps with "Under Development"
routines in them.

Thanks once again
Ben S
 
I'm glad it worked for you :) Good luck.

The listing works fine. The extraction, that's something else.
It seems to be ignoring the string that I'm giving it as a destination and
defaulting in the current folder.

I've now got what you suggested and for listing this works a treat, when I
pass any sort of sting as the DestPath it seems to be ignored.
How do I feed it a string in the correct format (I'm guessing something to
do with the ANSI setup of the DLL declare).
I've tried with and without a trailing \ on the path, with and without a
vbNull on the end
Also tried setting up a basic structure like the others with the string as
the only item, then passing that but it didn't want to work and dropped the
files in the same place as before.

Private Declare Ansi Function RARProcessFile Lib "unrar.dll" _
(ByVal hArcData As Integer, _
ByVal Operation As Integer, _
ByVal DestPath As String, _
ByVal DestName As String) As Integer

Sorry to keep picking your brains.

Thanks in advance
Ben S
 
The listing works fine. The extraction, that's something else.
It seems to be ignoring the string that I'm giving it as a destination and
defaulting in the current folder.

I've now got what you suggested and for listing this works a treat, when I
pass any sort of sting as the DestPath it seems to be ignored.
How do I feed it a string in the correct format (I'm guessing something to
do with the ANSI setup of the DLL declare).
I've tried with and without a trailing \ on the path, with and without a
vbNull on the end
Also tried setting up a basic structure like the others with the string as
the only item, then passing that but it didn't want to work and dropped the
files in the same place as before.

Private Declare Ansi Function RARProcessFile Lib "unrar.dll" _
(ByVal hArcData As Integer, _
ByVal Operation As Integer, _
ByVal DestPath As String, _
ByVal DestName As String) As Integer

Sorry to keep picking your brains.

No problem... I'm a little stumped. I just downloaded and installed
the unrar.dll stuff, and this should work - though I haven't actually
tried it out. Can you post the actuall code were it's failing?
I would like to see what arguments your passing and also I would like
to know what the return value of RARProcessFile is...
 
No problem... I'm a little stumped.

Kinda glad it's not just being a little dense !
I just downloaded and installed the unrar.dll stuff, and this should work - though I haven't actually
tried it out. Can you post the actuall code were it's failing?

----Code----
..
Case RarOperations.OP_EXTRACT
txtOut.text += "Extracting " & sStat
Ret = RARProcessFile(lHandle, RAR_EXTRACT, "D:\TestFolder\Dump",
uHeader.FileName.ToString)
Case RarOperations.OP_TEST
..
----Code----

The Ret value is 0 when I look at it showing success, which is true, but
it's ignored the DestFolder pram.
Looking though the DLL documentation I've found one error with the code,
I've specified the filename which overrides the DestPath and uses the
current folder.
After changing this I've now got it to the stage where it looks like

Ret = RARProcessFile(lHandle, RAR_EXTRACT, "D:\TestFolder\Dump", vbNull)

Which gives an error.
<time passes>
And playing with it as I typed this gave me

Ret = RARProcessFile(lHandle, RAR_EXTRACT, "D:\TestFolder\Dump", "")

which worked !!
This creates the folder in the "D:\TestFolder\Dump" folder and then extracts
all the files to it!
It's so much easier to work when you can bounce ideas of someone!!

Once again, thanks for you time, this has been a good learning experience
for me.
My mind is wandering to a .Net Component for UnRARing now..... The phrase
"Learn to walk before you run" springs to mind.
If you're ever Kent way I'll buy you a drink ;)

Thanks
Ben S
---
 
Back
Top