Advertisement

C-style casting with OpenFile()... help please?

Started by July 26, 2000 06:36 PM
4 comments, last by Fredric 24 years, 5 months ago
Alright, here is a small part of my bmp loading function (it''s the only part where my troubles are):
    
 int Setup_Bitmap(BITMAP_FILE_PTR bitmap, UCHAR *filename)
{
	int filehandle; //handle to the file

	OFSTRUCT filedata; //the OFSTRUCT


	//open the file and save it in filehandle

	if(!(filehandle = OpenFile(filename, &filedata,OF_READ)))
	{
		return (0);
	}

    
It says that I need some sort of c-style cast with OpenFile(). I know what c-style casting is, as I have done it many times before, but for some reason, I can''t fix this problem. Here is the error description generated by the compiler;

 main.cpp(183) : error C2664: ''OpenFile'' : cannot convert parameter 1 from ''unsigned char *'' to ''const char *''
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 
Does anyone know how to rid my code of this problem? I have tried filehandle = (HFILE)OpenFile() as well as filehandle = (OFSTRUCT)OpenFile() (which I thought would work) but that does not work. I have tried many things but nothing seems to crack this. Can anyone give me a hand? There are three types of people in the world; those who can count, and those who can't.
3D Math- The type of mathematics that'll put hair on your chest!
I may be wrong, but try OpenFile((char*)filename, &file_data, OF_READ)

"Everything is relative." -- Even in the world of computers.
everything is relative. -- even in the world of computers... so PUSH BEYOND THE LIMITS OF SANITY!
Advertisement
or make parameter filename of you Setup_Bitmap func char* instead of UCHAR*. It should have the same result.

"Everything is relative." -- Even in the world of computers.
everything is relative. -- even in the world of computers... so PUSH BEYOND THE LIMITS OF SANITY!
Ionut Costica :
I have tried the following method already:
    if(!(filehandle = OpenFile((UCHAR *)filename,&filedata,OF_READ)))	{		return (0);	}    


... but that does not work, unfortunately.

I didn''t try the (char *) instead of UCHAR, because I assumed it does not maky any difference, however, I tried it anyways, and as I assumed, it did not make any difference whatsoever. Thanks for your efforts though, I appreciate them!

Anyone else have a potential solution?

There are three types of people in the world; those who can count, and those who can't.
3D Math- The type of mathematics that'll put hair on your chest!
I tryed to put your code in a MS VC project.
I came to the conclusion that the following code will link ok:
    int Setup_Bitmap(BITMAP_FILE_PTR bitmap, char *filename){	int filehandle; //handle to the file	OFSTRUCT filedata; //the OFSTRUCT			//open the file and save it in filehandle	if(!(filehandle = OpenFile(filename, &filedata,OF_READ)))	{				return (0);	}    


"Everything is relative." -- Even in the world of computers.
everything is relative. -- even in the world of computers... so PUSH BEYOND THE LIMITS OF SANITY!
...Wow.. heh, I tried that solution when you mentioned it to me (before), but I guess I didn''t type it in correctly. It''s late

Thanks a lot Ionut Costica, I''m in your debt.

There are three types of people in the world; those who can count, and those who can't.
3D Math- The type of mathematics that'll put hair on your chest!

This topic is closed to new replies.

Advertisement