Jump to content
  • Advertisement
Sign in to follow this  
Azzazelus

Files

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I have some questions regarding file manipulation with Win32 API functions.

I want to make a header that is the size of INT and memories in it the number of USERS (for example);

After that I want to make a vector that contains the adresses of every USER and another vector that contains the size of the USER;

Lets assume that I will Create the file with 100 entries.

 

The created file would be like:

 

(INT) first 4 bytes; (the value of this one is 100 as 100 USERS)

INT[100] a vector with 100 ints and every element containing an adress of the USER (first element of the vector is the first user adress etc..)

INT[100] a vector with 100 ints and every element containing an sizeof the USER (first element of the vector is the first user size etc..)

 
WriteFile(test_usernames, (char*)&users_number, sizeof(int), &dwBytesWritten11, NULL);
WriteFile(test_usernames, (char*)&adrresses[0], sizeof(int)*users_number, &dwBytesWritten11, NULL);
WriteFile(test_usernames, (char*)&sizes[0], sizeof(int)*users_number, &dwBytesWritten11, NULL);
 

SetFilePointer(test_usernames,sizeof(int) , NULL, FILE_BEGIN);
WriteFile(test_usernames, (char*)sizes[0], sizeof(int), &dwBytesWritten11, NULL);

1. If I write  DATA1 that contains 4bytes for example and I want to return later and write exactly after that DATA1 i set the FilePointer to the sizeof(DATA1 ) of the sizeof(DATA1 ) + 1?

 

2. WriteFile(  ... (char*)users[0] , sizeof(int)*users_number ) will start to write from element 0 to the last element of the vector because of the sizeof that tells where to stop or because the & operator? What about if I want only to write a single element to the file (like in the last line of the code) it will be ok (char*)sizes[0] or (char*)&sizes[0] with smaller size to write specified in the WriteFile argument ?

Edited by Azzazelus

Share this post


Link to post
Share on other sites
Advertisement

1. If I write  DATA1 that contains 4bytes for example and I want to return later and write exactly after that DATA1 i set the FilePointer to the sizeof(DATA1 ) of the sizeof(DATA1 ) + 1?

That seams right to me, But you could use some dummy data and a hex editor.

I use HxD to check my binary files.

 

2. WriteFile(  ... (char*)users[0] , sizeof(int)*users_number ) will start to write from element 0 to the last element of the vector because of the sizeof that tells where to stop or because the & operator? What about if I want only to write a single element to the file (like in the last line of the code) it will be ok (char*)sizes[0] or (char*)&sizes[0] with smaller size to write specified in the WriteFile argument ?

That would treat the value of users[0] as the char pointer.

And it would write as many bytes as you tell it to, Which you set correctly.

 

 

 

Some nitpicks:

 

I would advise you use C++ cast operators( static_cast, dynamic_cast, reinterpret_cast ) instead of C syle as they are searchable and I find them more readable.

 

Why does the "WriteFile" function have so many parameters?, Could you not just do the same as std::fstream( pointer, byte count ) ?
 

HTH

-Ryan.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!