HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

c++, sfmpq.dll

01-30-2009, 07:19 PM#1
TriggerHappy
Not to long ago i tried using sfmpq.dll with visual baisc, probably not the best idea.

I'm a bit new to c++ and could anyone give me a little info on how to use .dll's, more specifically sfmpq.

So could someone show me an example on how to import, and then use the functions provided within the .dll, with a simple console application, that would just extract one of the files from the mpq.

I found something like....

PHP Code:
LPCSTR lpFileName "C:\\program files\\Warcraft III\\war3.mpq";
MPQHANDLE hMPQ;
DWORD dwPriority 666;

if (
SFileOpenArchive(lpFileNamedwPrioritySFILE_OPEN_HARD_DISK_FILE, &hMPQ) == true)
{
  
DWORD dwHashTableSize SFileGetFileInfo(hMPQSFILE_INFO_HASH_TABLE_SIZE)
  
FILELISTENTRY *lpListBuffer = new FILELISTENTRY[dwHashTableSize];
  
LPCSTR lpFileLists "C:\\WinMpq\\MyListFile.txt";
  
BOOL r SFileListFiles(hMPQlpFileListslpListBufferSFILE_LIST_ONLY_KNOWN);
  for (
DWORD i 0dwHashTableSizei++);
  {
     if (
lpListBuffer[i].dwFileExists != 0)
     {
       
printf("Found: %s\n"lpListBuffer[i].szFileName);
       
printf("Compressed size: %u\n"lpListBuffer[i].dwCompressedSize);
       
printf("Uncompressed size: %u\n"lpListBuffer[i].dwFullSize);
     }
  }
  
delete(lpListBuffer);
  
SFileCloseArchive(hMPQ);


But it gives me a few errors.

"Expected unqualified-id before "if""
"Expected ',' or ';' before if"
"[Build error] [main.o] Error 1"
01-30-2009, 08:48 PM#2
Vexorian
You have a missing ; after the first if and an extra one before the second if.
01-30-2009, 09:05 PM#3
TriggerHappy
I get even more errors when fixing those.

I'd rather not use that example.

Quote:
So could someone show me an example on how to import, and then use the functions provided within the .dll, with a simple console application, that would just extract one of the files from the mpq.
01-31-2009, 02:51 AM#4
midiway
I started this thread with the same questions and there you can find a sample program I've made (pure Win32API) and some sources that Pitzer posted. I've already told you via PM to not use SFmpq, but StormLib instead
01-31-2009, 03:09 AM#5
TriggerHappy
Yes i went through your code, but it was extra long because it was a windows application, i want to just see a source code for a dos application.

sfmpq is also used alot, which is why i chose it. Whats so special about storm lib also?
01-31-2009, 03:12 AM#6
Vexorian
Quote:
I get even more errors when fixing those.
That's a good sign.
01-31-2009, 03:14 AM#7
TriggerHappy
Well, what im looking for is maybe an example of how to make a simple dos application that can extract a random file from the mpq.

Hopefully pitzermike sees this.
01-31-2009, 03:30 AM#8
midiway
As I sayed strange problems happened to me using that DLL, also, since it's a dynamic DLL you have all the hassle to load the library (LoadLibrary) at run-time and get the function pointer (GetProcAddress).

With Storm you link a static library to your executable and dont need to ship any dll with your program. Also I have more familiarity with Storm.
01-31-2009, 03:44 AM#9
TriggerHappy
I looked at your source code once more (from old link).

I managed to compile it in dev c++, though if i click Load Small/Big File, it says "could not read inside the mpq"

I have a feeling it's because i didn't link the library like you stated above.

I also looked at stormlib what do i use in the god damn .zip, there are about 20 files, what do i use to allow me to use the functions.

Thanks to all helpers.
01-31-2009, 04:12 AM#10
midiway
Try the StomLib, I've compiled it for you and included it with the headers in a zip.

I think Dev c++ have an option in the project setting where you select .lib files to be linked, located it and select StormLibRAS622.lib else it will give you linkin errors

-Basically you use a function to open an MPQ (SFileOpenArchive for only reading, SFileCreateArchiveEx for read/write)
-Then SFileOpenFileEx to open a given filename inside the MPQ
-Get the size with SFileGetFileSize of the file you just opened
-And read the file with SFileReadFile
Attached Files
File type: zipstorm.zip (117.2 KB)
01-31-2009, 04:21 AM#11
TriggerHappy
I thank you for all of your help, though i'm still trying to figure out how to link a library.

Don't forget this thread please, im sure i will have more questions.

EDIT: I am so sorry, could you show me a console application example, that successfully extracts a file from an mpq, else i will need to keep messing around for hours.
01-31-2009, 05:35 PM#12
midiway
In Dev C++ I wasn't able to compile the sample program that you asked, it doesn't want to link StormLib. Better you get Visual Studio where I can sucefully compile it and show you how it works.

Attached the Dev C++ test that I was trying.
Attached Files
File type: zipMPQsample.zip (690.3 KB)
01-31-2009, 05:44 PM#13
TriggerHappy
I have visual studio also.

Thanks once again. Don't know how i can thank you.

EDIT: A working visual studio example would also be much appreciated, considering the test example isn't working.

Sorry to nag.

Hopefully it isn't to much trouble.
01-31-2009, 07:58 PM#14
midiway
done, in the sample war3map.j is extracted from a .w3x map
Attached Files
File type: zipMPQsample2.zip (688.8 KB)
01-31-2009, 08:31 PM#15
TriggerHappy
I cannot thank you enough!! (or can i).

Is there anything you need, that i could give you.