468,491 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

UnRAROCX.ocx and unrar.dll

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
---
Nov 20 '05 #1
8 6461
On 2004-02-01, Ben S <be*********@hotmail.com> wrote:
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.
Nov 20 '05 #2
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
---
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.

Nov 20 '05 #3
In article <nY***********@news-binary.blueyonder.co.uk>, Ben S wrote:
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...

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 5 Days, 0 Hours, 8 Minutes, 46 Seconds
Nov 20 '05 #4
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
---

"Tom Shelton" <to*@mtogden.com> wrote in message
news:eg**************@TK2MSFTNGP12.phx.gbl... In article <nY***********@news-binary.blueyonder.co.uk>, Ben S wrote:
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)

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 5 Days, 0 Hours, 8 Minutes, 46 Seconds

Nov 20 '05 #5
In article <lu***************@news-binary.blueyonder.co.uk>, Ben S wrote:
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 ;)


I'm glad it worked for you :) Good luck.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 5 Days, 2 Hours, 8 Minutes, 50 Seconds
Nov 20 '05 #6
> 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
---

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 5 Days, 2 Hours, 8 Minutes, 50 Seconds

Nov 20 '05 #7
In article <RG*************@news-binary.blueyonder.co.uk>, Ben S wrote:
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.


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...

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 22 Hours, 39 Minutes, 42 Seconds
Nov 20 '05 #8
> 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
---
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian Mitchell | last post: by
reply views Thread by Shadowboxer | last post: by
2 posts views Thread by mmmobasher | last post: by
2 posts views Thread by mmmobasher | last post: by
reply views Thread by Ben S | last post: by
reply views Thread by federico | last post: by
1 post views Thread by Christian Reizlein | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.