|
-
Jan 7th, 2009, 11:53 PM
#1
Thread Starter
New Member
[2008] Using old .DLL Files in 2008
I found a dll that i need really bad, and i can't seem to find any other ones that work with VB 2008 (express edition). Is there anyway i can port the 6.0 vb .dll to Visual Basic 2008.
The .DLL is sfMPQ, it is used to open and manipulate MPQ Files (I Hope).
Also when i try to import it the error i get is:
A Reference to sfMPQ.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
Thanks to all helpers.
-
Jan 8th, 2009, 12:02 AM
#2
Re: [2008] Using old .DLL Files in 2008
The DLL is not a COM component so you can't reference it directly. You will have to use the functions it exports in the same way as you access Windows API functions. There are lots of examples all over the forum for calling API functions but you should start by reading this. Note that you should put the DLL in the same folder as your EXE.
-
Jan 8th, 2009, 12:12 AM
#3
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
It says to declare the API, It's sort of confusing.
http://www.zezula.net/en/mpq/stormlib.html
That is the documentation for the .dll , could you give me a first hand example?
-
Jan 8th, 2009, 12:28 AM
#4
Re: [2008] Using old .DLL Files in 2008
I would suggest that you add a class to your project named MPQ and then declare all the functions you need from that library in that class. For example, this function:
Code:
BOOL WINAPI SFileOpenArchive(
const char * szMpqName, // Archive file name
DWORD dwPriority, // Archive priority
DWORD dwFlags, // Open flags
HANDLE * phMPQ // Pointer to result HANDLE
);
would be declared like so:
vb.net Code:
Imports System.Runtime.InteropServices Friend Class MPQ <DllImport("Storm.dll")> _ Public Shared Function SFileOpenArchive(ByVal szMpqName As String, _ ByVal dwPriority As Integer, _ ByVal dwFlags As Integer, _ ByVal phMPQ As IntPtr) As Boolean End Function End Class
You then call it in your VB code as you would any other method, e.g.
vb.net Code:
Dim result As Boolean = MPQ.SFileOpenArchive(mpqName, priority, flags, mpq)
It's up to you to determine the best .NET type to use to represent the unmanaged types used in the original function declarations. You got some of the most common substitutions here. You'll also need to read that documentation to determine what each parameter means.
-
Jan 8th, 2009, 12:37 AM
#5
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
Thank you for that, helped alot. Hopefully you can help me some more . I did all that and it works fine, though i tried a simple Debug Click button function to test if it actually opens and my program just doesn't respond and i need to turn it off.
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim result As Boolean = MPQ.SFileOpenArchive("C:\Users\#\Desktop\Warcraft III\war3.mpq", 0, 0, "C:\#\JAKE\Desktop\Warcraft III\war3.mpq") If result = True Then MsgBox("yes") Else MsgBox("no") End If End Sub
Last edited by TriggerHappy187; Jan 8th, 2009 at 12:46 AM.
-
Jan 8th, 2009, 12:53 AM
#6
Re: [2008] Using old .DLL Files in 2008
I think my code may have been not quite correct. I think the last parameter should be ByRef rather than ByVal.
I also think your parameters are wrong. The first parameter looks like it's supposed to be the path to a file, but yours looks like it's the path to a folder. Maybe I'm wrong and you've just omitted the file extension.
I'm fairly certain your last parameter is wrong though. As far as I can tell you should simply declare an IntPtr variable and pass that. If the method returns True then that IntPtr variable will contain the archive handle that you can then pass to other functions for processing. For instance, the SFileFindFirstFile function takes that IntPtr as an argument and finds the first file within the archive.
-
Jan 8th, 2009, 12:57 AM
#7
Re: [2008] Using old .DLL Files in 2008
Here's an example how I think the code should look:
vb.net Code:
Dim archiveName As String = "C:\MyArchive.mpq" Dim archiveHandle As IntPtr 'Open archive. If MPQ.SFileOpenArchive(archiveName, 0, 0, archiveHandle) Then 'Process archive here. 'Close archive. MPQ.SFileCloseArchive(archiveHandle) Else MessageBox.Show("Unable to open archive") End If
vb.net Code:
Imports System.Runtime.InteropServices Friend Class MPQ <DllImport("Storm.dll")> _ Public Shared Function SFileOpenArchive(ByVal szMpqName As String, _ ByVal dwPriority As Integer, _ ByVal dwFlags As Integer, _ ByRef phMPQ As IntPtr) As Boolean End Function <DllImport("Storm.dll")> _ Public Shared Function SFileCloseArchive(ByVal phMPQ As IntPtr) As Boolean End Function End Class
-
Jan 8th, 2009, 01:02 AM
#8
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
Yea, i fixed the first parameter. Sorry i'm a bit new to VB but not programming, what are IntPtr, i tried doing a quick Google search but it came up with some wierd things, or at least to me.
Help
EDIT : Nevermind, posted that before your ahead post. Also by storm.dll do you mean sfMPQ.dll?
-
Jan 8th, 2009, 01:15 AM
#9
Re: [2008] Using old .DLL Files in 2008
 Originally Posted by TriggerHappy187
EDIT : Nevermind, posted that before your ahead post. Also by storm.dll do you mean sfMPQ.dll?
Probably, yes. Whatever the name of the DLL is containing the functions. I just saw Storm.dll on that second page you linked to but upon closer inspection I see that that's a different file.
-
Jan 8th, 2009, 01:17 AM
#10
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
Thanks, a few more simple questions
byval are arguments?
byref is the returning value?
I also tried adding OpenFileEx, i did so like this
vb Code:
<DllImport("SFmpq.dll")> _ Public Shared Function SFileOpenFileEx(ByVal hMPQ As IntPtr, _ ByVal filename As String, _ ByVal dwSearchScope As Integer, _ ByVal phFile As IntPtr) End Function
did i do it right?
EDIT :
I Tried an extract function but it just freezes my program
vb Code:
<DllImport("SFmpq.dll")> _ Public Shared Function SFileExtractFile(ByVal hMPQ As IntPtr, _ ByVal filename As String, _ ByVal path As String) End Function
Last edited by TriggerHappy187; Jan 8th, 2009 at 01:32 AM.
-
Jan 8th, 2009, 01:33 AM
#11
Re: [2008] Using old .DLL Files in 2008
 Originally Posted by TriggerHappy187
Thanks, a few more simple questions
byval are arguments?
byref is the returning value?
Essentially, yes. Strictly speaking, in VB a ByVal parameter can pass a value in and a ByRef parameter can pass a value in and out. It's common in C/C++ programming to use the actual return value of the function to provide a success, failure or error code and pass the actual data back via a parameter pointer. The same thing happens in .NET code but less often, with the equivalent of the pointer being the ByRef parameter.
 Originally Posted by TriggerHappy187
I also tried adding OpenFileEx, i did so like this
vb Code:
<DllImport("SFmpq.dll")> _ Public Shared Function SFileOpenFileEx(ByVal hMPQ As IntPtr, _ ByVal filename As String, _ ByVal dwSearchScope As Integer, _ ByVal phFile As IntPtr) End Function
did i do it right?
I don't think you did but I don't think it's your fault. It looks to me like that documentation is incorrect. They show the signature for SFileOpenFileEx as:
Code:
BOOL WINAPI SFileOpenFileEx(
HANDLE hMPQ, // Handle of open archive
const char * szFileName, // Name of a file to open.
DWORD dwSearchScope, // Search scope for the file.
HANDLE phFile // Pointer to result HANDLE.
);
but the parts I've highlighted would suggest that it should actually be:
Code:
BOOL WINAPI SFileOpenFileEx(
HANDLE hMPQ, // Handle of open archive
const char * szFileName, // Name of a file to open.
DWORD dwSearchScope, // Search scope for the file.
HANDLE * phFile // Pointer to result HANDLE.
);
with the * indicating a pointer rather than a value. This is supported by the fact that this method appears to be opening a file within the archive, therefore it should be passing back a handle for that file. All this means that your declaration is correct except that the phFile parameter should be declared ByRef, just like the phMPQ parameter in the SFileOpenArchive function.
-
Jan 8th, 2009, 01:35 AM
#12
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
Thanks for that. Also i edited my post above
I Tried an extract function but it just freezes my program
vb Code:
<DllImport("SFmpq.dll")> _ Public Shared Function SFileExtractFile(ByVal hMPQ As IntPtr, _ ByVal filename As String, _ ByVal path As String) End Function
I Opened the mpq with another editor and a random file was file00000000.blp. Heres an example on how i used it
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim archiveHandle As IntPtr Dim archiveName As String = "C:\Users\#\Desktop\Warcraft III\war3x.mpq" If MPQ.SFileOpenArchive(archiveName, 0, 0, archiveHandle) Then MPQ.SFileExtractFile(archiveHandle, "File00000000.blp", "C:\Users\#\Desktop\test.blp") MPQ.SFileCloseArchive(archiveHandle) Else MessageBox.Show("Unable to open archive") End If End Sub
-
Jan 8th, 2009, 01:50 AM
#13
Re: [2008] Using old .DLL Files in 2008
I'll first point out that these methods you're declaring are all functions and should therefore be declared with a return type. All the original functions return type BOOL so all your functions should return type Boolean. I wouldn't think that that would cause the issue but just test it to see.
If it still doesn't work then the only thing I can think of is that your file name isn't correct.
-
Jan 8th, 2009, 01:57 AM
#14
Thread Starter
New Member
Re: [2008] Using old .DLL Files in 2008
You are one of the most helpful people i have ever met. Anyways on-topic. The error that was returned was
Unable to find an entry point named 'SFileAddFile' in DLL 'SFmpq.dll'.
But before i added the as boolean you suggested it was
PInvoke restriction: cannot return variants.
So here is my code, can you see any problems.
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim archiveHandle As IntPtr Dim archiveName As String = "C:\Users\#\Desktop\Warcraft III\war3x.mpq" If MPQ.SFileOpenArchive(archiveName, 0, 0, archiveHandle) Then If MPQ.SFileAddFile(archiveHandle, "C:\Users\#\Documents\realmlist.txt", "haha.txt", 0) Then MessageBox.Show("File Added") Else MessageBox.Show("File not Added") End If MPQ.SFileCloseArchive(archiveHandle) Else MessageBox.Show("Unable to open archive") End If End Sub
EDIT:
Stupid documentation... i opened the function list contained within the .dll and turns out the real name is MpqAddFileToArchive. Anyways. i will re-edit if there are any more problems.
EDIT 2:
i tried a simple if MpqAddFileToArchive then msgbox("added") or "not added" and it always came up as not added...
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim archiveHandle As IntPtr Dim archiveName As String = "C:\Users\#\Desktop\Warcraft III\war3x.mpq" If MPQ.SFileOpenArchive(archiveName, 0, 0, archiveHandle) Then If MPQ.MpqAddFileToArchive(archiveHandle, "C:\Users\#\Desktop\config.ini", "test", 0) Then MsgBox("added") Else MsgBox("not added") MPQ.SFileCloseArchive(archiveHandle) Me.Close() End If MPQ.SFileCloseArchive(archiveHandle) Else MessageBox.Show("Unable to open archive") End If
Last edited by TriggerHappy187; Jan 8th, 2009 at 03:46 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|