M
MatuX
Guest
Again, MatuX invades the board with boring programming questions 
I'm still learning CPP (I started just 2 weeks ago), so, try to be nice...
I'm creating a MVE Player with GUI. What it has to do is to build an exe appending 2 files. One called w32stub.lib with a size of 310,784 and the MVE file (random size). It's just a front-end to don't have to use the harsh method of TeamX and a shortcut to don't have to download the 5mb program from the Descent group.
I'm using this simple method: Create an EXE, write w32stub.lib data in the EXE, and then write the MVE data in the EXE.
My problem is that the read and write functions aren't working correctly!
The final size of the exe is always some KBs bigger than what it should be.
I truncate the code to just the w32stub.lib creation part, to debug it. So, it will just copy w32stub.lib to afailed.exe (for example). The same as if you write in DOS: "copy w32stub.lib afailed.exe"
For my surprise, it does not even make the copy correctly!
Here is the code I'm using:
{
int hndStubFile, // Handle to the stub library (w32stub.lib)
hndMVEFile, // Handle to the MVE video
hndEXEFile; // Handle to the self-playing video
char *buf; // Buffer
unsigned int StubSize = _filelength(hndStubFile);
// Returns a correct file size
buf = (char *) malloc(StubSize);
// Allocate memory for the buffer
_read( hndStubFile, buf, StubSize);
// Read - returns 310,784 bytes readed
_write( hndEXEFile, buf, StubSize);
// Write - returns 310,784 bytes writen
}
The debug tells me that the bytes readed and writen by the functions is the correct, but, when I flush the memory (close the files and free the buffer), I found that the file size is 1051 bytes bigger.
All the files were opened as _O_RDONLY|_O_BINARY. And the EXE was created as _S_IWRITE. All the procedures are successful and the variables used (such as AppPath and strNewFName) are correct.
{
hndMVEFile = _open( strFileName, _O_RDONLY|_O_BINARY )
hndStubFile = _open( AppPath "\\w32stub.lib", _O_RDONLY|_O_BINARY )
hndEXEFile = _creat( AppPath strNewFName, _S_IWRITE )
}
Thanks in advance!
[p align=center]
MatuX
Co-Leader and Chief Programmer on
http://clanfusionn.hypermart.net/tmslogo1.gif
[font size=1]GFX by Smackrazor
[font size=2]http://www.modsquad.f2s.com[/p]

I'm still learning CPP (I started just 2 weeks ago), so, try to be nice...
I'm creating a MVE Player with GUI. What it has to do is to build an exe appending 2 files. One called w32stub.lib with a size of 310,784 and the MVE file (random size). It's just a front-end to don't have to use the harsh method of TeamX and a shortcut to don't have to download the 5mb program from the Descent group.
I'm using this simple method: Create an EXE, write w32stub.lib data in the EXE, and then write the MVE data in the EXE.
My problem is that the read and write functions aren't working correctly!
The final size of the exe is always some KBs bigger than what it should be.
I truncate the code to just the w32stub.lib creation part, to debug it. So, it will just copy w32stub.lib to afailed.exe (for example). The same as if you write in DOS: "copy w32stub.lib afailed.exe"
For my surprise, it does not even make the copy correctly!
Here is the code I'm using:
{
int hndStubFile, // Handle to the stub library (w32stub.lib)
hndMVEFile, // Handle to the MVE video
hndEXEFile; // Handle to the self-playing video
char *buf; // Buffer
unsigned int StubSize = _filelength(hndStubFile);
// Returns a correct file size
buf = (char *) malloc(StubSize);
// Allocate memory for the buffer
_read( hndStubFile, buf, StubSize);
// Read - returns 310,784 bytes readed
_write( hndEXEFile, buf, StubSize);
// Write - returns 310,784 bytes writen
}
The debug tells me that the bytes readed and writen by the functions is the correct, but, when I flush the memory (close the files and free the buffer), I found that the file size is 1051 bytes bigger.
All the files were opened as _O_RDONLY|_O_BINARY. And the EXE was created as _S_IWRITE. All the procedures are successful and the variables used (such as AppPath and strNewFName) are correct.
{
hndMVEFile = _open( strFileName, _O_RDONLY|_O_BINARY )
hndStubFile = _open( AppPath "\\w32stub.lib", _O_RDONLY|_O_BINARY )
hndEXEFile = _creat( AppPath strNewFName, _S_IWRITE )
}
Thanks in advance!
[p align=center]
MatuX
Co-Leader and Chief Programmer on
http://clanfusionn.hypermart.net/tmslogo1.gif
[font size=1]GFX by Smackrazor
[font size=2]http://www.modsquad.f2s.com[/p]