Advertisement

Debugging help please!

Started by February 11, 2000 11:49 AM
8 comments, last by PsYcHoPrOg 25 years ago
This has been driving me nutz! I don''t know what I am doing wrong! I am trying to load a bitmap in this code, but I am getting 3 annoying error messages. I will mark each place where each error is and the error can be found at the bottom of this post with the coresponding number. The code may be a bit distorted. int BMPLOAD(BMPPTR bmp, char *filename) { int file_handle, //handle to file i; //looping int OFSTRUCT file_data;//file data for openfile //open a bitmap and return error if not successful if(file_handle = OpenFile(filename, file_data, OF_READ) == -1)//error #1 { _close(file_handle);//close file return(0);//return error } //get bitmap''s information _lread(file_handle, bmp->binfoheader, sizeof(BITMAPINFOHEADER));//error 2 _lread(file_handle, bmp->bfileheader, sizeof(BITMAPFILEHEADER)); //error #3 //get the 8-bit palette if it''s an 8-bit file if(bmp->binfoheader.biBitCount == 8) { //get palette _lread(file_handle, bmp->palette, 256*sizeof(PALETTEENTRY)); //switch red and blue palette for RGBQUAD for(i; i<256; i++) { int changecolor = bmp->palette.peRed; bmp->palette.peRed = bmp->palette.peBlue; bmp->palette.peBlue = changecolor; bmp->palette.peFlags = PC_NOCOLLAPSE; } }//end if //find the image data _lseek(file_handle, -(int) (bmp->binfoheader.biSizeImage), SEEK_END); //read data if(bmp->binfoheader.biBitCount == 8) { //allocate memory for thebuffer if(!(bmp->buffer = (UCHAR*)malloc (bmp->binfoheader.biSizeImage))) { //return error if false _close(file_handle); return(0); } _lread(file_handle, bmp->buffer, bmp->binfoheader.biSizeImage); } else { _close(file_handle); return(0); } _close(file_handle); Errors: #1 error C2664: ''OpenFile'' : cannot convert parameter 2 from ''struct _OFSTRUCT'' to ''struct _OFSTRUCT *'' #2 error C2664: ''_lread'' : cannot convert parameter 2 from ''struct tagBITMAPINFOHEADER'' to ''void *'' #3 see error 2 please Help! </i>
D:
I just looked at the code and realized that it''s completely disfigured, so I''m going to try again:

int BMPLOAD(BMPPTR bmp, char *filename)
{
int file_handle, //handle to file
i; //looping int

OFSTRUCT file_data;//file data for openfile
//open a bitmap and return error if not successful
if(file_handle = OpenFile(filename, file_data, OF_READ) == -1)
{
_close(file_handle);//close file
return(0);//return error
}
//get bitmap''s information
_lread(file_handle, bmp->binfoheader, sizeof(BITMAPINFOHEADER));

_lread(file_handle, bmp->bfileheader,sizeof(BITMAPFILEHEADER));
//get the 8-bit palette if it''s an 8-bit file
if(bmp->binfoheader.biBitCount == 8)
{ //get palette
_lread(file_handle, bmp->palette,
256*sizeof(PALETTEENTRY));
//switch red and blue palette for RGBQUAD format
for(i; i<256; i++)
{
int changecolor = bmp->palette.peRed;
bmp->palette.peRed = bmp->palette.peBlue;<br> bmp->palette.peBlue = changecolor;<br><br> bmp->palette.peFlags = PC_NOCOLLAPSE;<br> }<br> }//end if<br> //find the image data<br> _lseek(file_handle, -(int) (bmp->binfoheader.biSizeImage), SEEK_END);<br> //read data<br> if(bmp->binfoheader.biBitCount == 8)<br> { //allocate memory for the buffer<br> if(!(bmp->buffer = (UCHAR*)malloc (bmp->binfoheader.biSizeImage)))<br> { //return error if false<br> _close(file_handle);<br> return(0);<br> }<br> _lread(file_handle, bmp->buffer, bmp->binfoheader.biSizeImage);<br> }<br> else<br> {<br> _close(file_handle);<br> return(0);<br> }<br><br> _close(file_handle);<br>}//end<br><br><br> </i>
D:
Advertisement
again, disfigured, sorry. I''m trying one last time.

int BMPLOAD(BMPPTR bmp, char *filename)
{
int file_handle,//handle to file
i; //looping int

OFSTRUCT file_data;; //file data for openfile

if(file_handle = Openfile(filename, file_data, OF_READ)
==-1)
{
_close(file_handle);
}
_lread(file_handle, bmp->binfoheader, sizeof(
BITMAPINFOHEADER));

_lread(file_handle, bmp->bfileheader, sizeof(
BITMAPFILEHEADER));

if(bmp->binfogeader.biBitCount == 8)
{
_lread(file_handle, bmp->palette,
256*sizeof(PALETTEENTRY));

for(i; i;<256; i++)
{
int changecolor = bmp->palette.peRed;
bmp->palette.peRed= bmp->palette.peBlue;<br> bmp->palette.peFlags = PC_NOCOLLAPSE;<br> }<br> }<br> <br> _lseek(file_handle, -(int) <br> (bmp->binfoheader.biSize.Image), SEEK_END));<br> <br> if(bmp->binfoheader.biBitCount == 8)<br> {<br> if(!(bmp->buffer = (UCHAR*)malloc(bmp->binfoheader.<br> BiSizeImage)))<br> {<br> _close(file_handle);<br> return(0);<br> }<br> _lread(file_handle, bmp->buffer, bmp->binfoheader.<br> biSizeImage);<br> }<br> else<br> {<br> _close(file_handle);<br> return(0);<br> }<br> _close(file_handle);<br>}<br> </i>
D:
The first error is the the OpenFile(filename,file_data, OF_READ) is expecting file_data to be a pointer to a OFSTRUCT, so just do this:
OpenFile(filename,&file_data, OF_READ) to pass the address of file_data
the other two errors are the same problem: on th _lread you have to pass &(bmp->binfoheader) ''cos the func is expecting a pointer. I''m not sure If you won''t have to cast it to (void *) but I don''t think so.
good luck (just curious, don''t take offence: are you new to c/c++?)
Do you know that you can edit your own messages by clicking on the magnifying glass beside your post? It's also possible to delete your own messages. I suggest you remove two of the above...

Now for the help:

error #1: write &file_data to get a pointer to the structure

error #2: write (void *)&bmp->binfoheader to convert the pointer to void*

error #3: the same

(Damn! alexmoura got his post in as I was writing mine =)

Edited by - Spellbound on 2/11/00 12:29:00 PM
Looks like someone needs to learn the code tag.

function thisisafunction(func) {  dosomething = whateveryouwant;}  





Edited by - Gromit on 2/11/00 12:30:51 PM
William Reiach - Human Extrodinaire

Marlene and Me


Advertisement
just answering some question, yes, I am fairly new to C++. I got sick of BASIC and QBASIC after mastering them so I have been trying to learn quickly. I think I should slow down and overview some things. I would be taking the courses in school but our school district seems to have a thing for macs *gag*. So teachers know nothing about it. The class introducing C++, when I asked, was considered a college course.
D:
V''been there, though not so much into basic;
One advice, I don''t know where you''re studiyng C/C++ from, but the single hardest thing I remember when learning C/C++ was ***fully*** understanding the pointers/references to variables/data/memory (even today I''m not sure I got it all figured out, but some assembler gave me an insight on the "reasons behind all that", to the point where I found myself predicting some VB behaviour better that some VB programmers )
For me, it is also the single most powerfull toy C/C++ has, to either play around or totally screw thing up
So, Invest time in learning them.

**question about tags; I''ve been to the faq, and found nothing about the tags; where can I found some info on them?


Uh, it was on the post/reply page but it''s been removed. (why?)

Anyway, you use them kind of like HTML

There are b and /b for bold, i and /i for italics u, and /u (?) for underline, and code and /code for formatting source code (so it doesn''t put in smily faces and what-not). Put them in angle brackets ''<'' and ''>'' like HTML

italics

bold

bold and italics

source code
Maybe you forgot i=0 in for loop
replace :
for(i; i<256; i++)
{
int changecolor = bmp->palette.peRed;
bmp->palette.peRed= bmp->palette.peBlue;<br>bmp->palette.peFlags = PC_NOCOLLAPSE;<br>}<br><br>to:<br>for(i=0; i<256; i++)<br>{<br>int changecolor = bmp->palette.peRed;<br>bmp->palette.peRed= bmp->palette.peBlue;<br>bmp->palette.peFlags = PC_NOCOLLAPSE;<br>}<br><br>Goodluck<br> </i>

This topic is closed to new replies.

Advertisement