|
Thanks for helping with this. I do:
delete [] m_pData;
right after the fread function. Now I am getting the following error:
"The instruction at "0x00405f3b" refereced memory at "0x04731000". The memory could not be "read"."
This is familiar, but I still can't figure out why fread is doing this. If I do the delete later after I manipulate the memory, I get the previously mentioned error. Does this prompt any ideas about what might be going on?
-Drew
|
|
|
|
|
Are you opening the file in binary mode?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Yes, I am opening it in binary. I believe it is supposed to be(this is an image file). I am using:
if( ( fp = fopen( fileName, "rb" ) ) == NULL )
{
return false;
}
I changed it to "r", and the same problem happened.
|
|
|
|
|
bool CTexture::LoadBMPTexture( char *fileName )
{
BITMAPINFOHEADER texInfo;
if( m_pData != NULL )
{
delete [] m_pData;
m_pData = NULL;
}
if( !LoadBMPFile( fileName, &texInfo ) )
{
if( m_pData != NULL )
{
delete [] m_pData;
m_pData = NULL;
}
return false;
}
if( m_pData == NULL )
{
delete [] m_pData;
m_pData = NULL;
return false;
}
m_nWidth = texInfo.biWidth;
m_nHeight = texInfo.biHeight;
m_pPalette = NULL;
m_nScaledHeight = 0;
m_nScaledWidth = 0;
m_TextureType = BMP;
return true;
}
bool CTexture::LoadBMPFile( char *fileName, BITMAPINFOHEADER *bitmapInfoHeader )
{
FILE *fp;
BITMAPFILEHEADER bitmapFileHeader;
unsigned int imageIdx = 0;
unsigned char tempRGB;
if( ( fp = fopen( fileName, "rb" ) ) == NULL )
{
return false;
}
fread( &bitmapFileHeader, sizeof( BITMAPFILEHEADER ), 1, fp );
if( bitmapFileHeader.bfType != BITMAP_ID )
{
fclose( fp );
return false;
}
fread( bitmapInfoHeader, sizeof( BITMAPINFOHEADER ), 1, fp );
fseek( fp, bitmapFileHeader.bfOffBits, SEEK_SET );
if( m_pData != NULL )
{
delete [] m_pData;
m_pData = NULL;
}
m_pData = new unsigned char[bitmapInfoHeader->biSizeImage];
if( m_pData == NULL )
{
return false;
}
fread( m_pData, 1, bitmapInfoHeader->biSizeImage, fp );
fclose( fp );
if( m_pData == NULL )
{
delete [] m_pData;
m_pData = NULL;
return false;
}
for( imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3 )
{
tempRGB = m_pData[imageIdx];
m_pData[imageIdx] = m_pData[imageIdx + 2];
m_pData[imageIdx + 2] = tempRGB;
}
return true;
}
|
|
|
|
|
The problem is that you are overrunning the buffer in your last for loop.
Even if you were handling the image correctly, which you are not, the correct for statement should be:
for( imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage - 2; imageIdx += 3 )
(Note the "-2", in the loop you read/write "imageIdx + 2")
A bigger problem is all rows in a bitmap are aligned to a DWORD boundary. You algorithm will fail if ((width * 3) % 4 != 0)
The loop fails because there are padded bytes which means that biSizeImage is not divisable by three.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thank you very much for the help. Things work fine now. If only I had posted this code first. I was aware of the DWORD boundary issue, and have at this point just limited my images to powers of 2. Is there anywhere you can think of where I could learn a little more about working with images that would fail the test you mentioned?
Again, thank you very much.
-Drew
|
|
|
|
|
Hello all
I've a project which contains a list of .cpp files. I'm using vc++ 6.0. When ever I tried to build the .exe after modifying a single file, vc++ environment is recompiling all the files in my project and building the exe. How do I compile only modified file and link it to build the new .exe ?
Thanks
Hari.
|
|
|
|
|
|
Hi!
How do I get the current gateway IP address?
|
|
|
|
|
Use GetAdaptersInfo () function with an object of structure IP_ADAPTER_INFO as argument. Then if the function success, the IP_ADAPTER_INFO.GatewayList will give you the IP Addresse of default gateway.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
hi,
I would like to know how to open a closed output file !!!!
thanks
Ehsan Behboudi
|
|
|
|
|
A CSV file is a "Comma Seperated Value" file for excel. In that file, the data for each cell is seperated with a comma and a row is seperated with a newline.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hey folks. Anyone know how to go about closing all browser windows through Visual C++?
|
|
|
|
|
One rather "arbitrary" solution comes to mind, do a window ennumeration via the EnumWindows() API fn, and for each window, get its caption via GetWindowText(), then just look for the "Microsoft Internet Explorer" string insinde the window´s title, if found, send it a WM_CLOSE msg or something like that.
HTH.
|
|
|
|
|
Hm. Now there's a good idea. I'll have to look into how to do that. Thanks a ton, you've sent me in the right direction.
|
|
|
|
|
Hi,
I would like to know if its possible to write to an already closed output file.
I am actually using a .CSV file.
Thanks
Ehsan Behboudi
|
|
|
|
|
not unless you re-open it first.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2003 Microsoft Corporation. All rights reserved.
|
|
|
|
|
what is the code to reopen the file?
Ehsan Behboudi
|
|
|
|
|
The term "reopen" implies that you have previously opened the file. Can you not use the same method again?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
mr2003 wrote:
what is the code to reopen the file?
FILE *fopen( const char *filename, const char *mode ); ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
How can I ROUND double to int, please?
Love is the law, love under will.
|
|
|
|
|
try
floor(dValue + 0.5)
for positive values
|
|
|
|
|
Hello,
maybe it will be useful for you to know a little bit more about this:
double val1 = floor( 2.3 + 0.5 );
double val2 = floor( -2.3 + 0.5 );
double val3 = ceil( 2.3 + 0.5 );
double val4 = ceil( -2.3 + 0.5 );
printf( "%f, %f, %f, %f\r\n", val1, val2, val3, val4 );
will give you:
2.000000, -2.000000, 3.000000, -1.000000
Cheers,
Marcello
|
|
|
|
|
I am trying to localize a Property Sheet Wizard for a Japanese version of the software. However when I do include Japanese resources, the wizard seems to retain the size of the English version of the dialogs. Both resources actually have the same size in dialog units, but the Japanese version uses a different font which causes it to be slightly wider. However it appears cutoff in the wizard.
Anybody seen this before and better yet know any fix for this?
Thanks
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
Hi all:
Could somebody tell me how can i convert from CString to CTime?
Thanks in advance.
|
|
|
|