• 10
• 9
• 13
• 10
• 18

# What is wrong with this code?

This topic is 4876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
Just glancing over the code quickly, you forgot the opening bracket of the for statement at the bottom of the code.

##### Share on other sites
Offhand, I would suggest that the fact that you're reading Header as a whole, and then rereading the DirOffset and DirLength attributes, might be a problem.

##### Share on other sites
Yeah. I'll have to experiment a bit with all the objects :S Oh and to the first reply... You don't need the brackets if you have only one line of code following.

##### Share on other sites
 if (strncmp(Header.Signature, "PACK", 4))fclose(file);fread(&Header.DirOffset, sizeof(int), 1, file);

It might just be that I haven't used it enough, but it looks to me like you're reading from a dead file. I was reading over the file format description at Wotsit's, and...the signature of the header has to be "PACK", right? Maybe you wanted to put if(strncmp(Header.Signature,"PACK",4)<0) fclose(file)?

I don't know, don't really have much experience with stuff like this. Looks to me like it might generate an error if you close a file and then try to read from it, though.

EDIT: Also, what exactly is SendMessage sending? I don't see an hListView in your code here, so I assume it's global. I've never seen it before, but from what I can gather off the MSDN, it looks like you're just adding the filename of each .pak file to a list of strings...so that wouldn't be a problem, right?
Looks like you already explained that...

EDIT (again): I think your code to get the number of directories (NumFiles) may be wrong. The docs say to divide by 64 to get the number of directory files, but you divide by the sizeof the header, which is supposed to be only 12 (check). Really just trying to find anything that could possibly be a problem, and that may present itself if you find file errors in the future.

Just trying to learn.

##### Share on other sites
Over the last few minutes I've been revising it. I found the error to be in these lines:

At least I think it's there. About the handle to the listview, it's got nothing to do with that because I can add normal strings and numbers, etc.

##### Share on other sites
Quote:
 Original post by KryptusOver the last few minutes I've been revising it. I found the error to be in these lines:fread(&Header.DirOffset, sizeof(int), 1, file);fread(&Header.DirLength, sizeof(int), 1, file);At least I think it's there. About the handle to the listview, it's got nothing to do with that because I can add normal strings and numbers, etc.

Upon rereading your original post I did figure out just what the heck hListView was :P.

Did you check the line right above those two (mentioned in last post), about closing the file and then reading from it? Just what kind of error did you find?

##### Share on other sites
It was that Windows 2K/XP error dialog saying: "This program has encountered an error." and then it has a Debug button a Don't Send and a Send button, for sending the error to Microsoft.

I think I've nearly solved the problem. By focusing more on the PAK file guide on http://www.wotsit.org I have come closer to a solution. After removing that code and dividing the directory length by 64 it now displays the files in the PAK file. Also adding to the problem was the fact that the PAK file generator I used to make PAK files wasn't making them properly. I downloaded Pak Explorer and then tested my program and it now seems to work! I'm just going to further test it before I start cheering and parading.

##### Share on other sites
Alright my code finally works now for opening pak files! All because of some corrupt PAK files and dodgy code!

typedef struct
{
char Signature[4];
int DirOffset;
int DirLength;

typedef struct
{
char FileName[56];
int FilePosition;
int FileLength;
} pakEntry;

bool OpenPAK(HWND hWnd, char FileName[])
{
// Open a PAK file
FILE *file;
pakEntry *Entry;
int NumFiles;

file = fopen(FileName, "rb");

fclose(file);

Entry = new pakEntry[NumFiles];

for (int i = 0; i < NumFiles; i++)

return true;
}

This code works for opening Quake 2 PAK files and displaying them in a listbox!