Jump to content

Some Compiler Error ('...need explicit cast to convert...')

- - - - -

  • Please log in to reply
1 reply to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
I got this C++ compilation error on line 63.

The code in that area:
hFile= OpenFile(mainbg_file, &ofs, OF_READ); 

	if (((int)hFile == 0) | ((int)hFile == -1)){ 

		if (MessageBox((HWND)NULL, (LPCSTR)"Error:  The background image file was not found. \r\n\r\nContinue without loading background? ", 

			(LPCSTR)ApplicationName, 

			(UINT)MB_YESNO) == IDYES){ 

			use_mainbg= false; 

		} else { 

			return 1; 

		} 

	} else { 

		a= GetBitmapW(hFile); 

		b= GetBitmapH(hFile); 

		CloseHandle(hFile); 

	} 

The compiler said this:
        hFile= OpenFile(mainbg_file, &ofs, OF_READ);

                                                   ^

main.cpp(63) : Error: need explicit cast to convert

from: int __import

to  : void *

--- errorlevel 1

Here are some variables, if that helps:

char mainbg_file[]= "mainbg.bmp"; 


OFSTRUCT ofs; 


HANDLE hFile; 

I don't know what my compiler is talking about; anyone understand what's going on?

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
I got the answer now.

It's the function-call-style cast, I think.

hFile= HANDLE(OpenFile(mainbg_file, &ofs, OF_READ)); 

	if (((int)hFile == 0) | ((int)hFile == -1)){ 

		if (MessageBox((HWND)NULL, (LPCSTR)"Error:  The background image file was not found. \r\n\r\nContinue without loading background? ", 

			(LPCSTR)ApplicationName, 

			(UINT)MB_YESNO) == IDYES){ 

			use_mainbg= false; 

		} else { 

			return 1; 

		} 

	} else { 

		a= GetBitmapW(hFile); 

		b= GetBitmapH(hFile); 

		CloseHandle(hFile); 

	} 

	

	if (use_mainbg){ 

		bgbitmap= LoadImage(hThisInstance, (LPCSTR)mainbg_file, IMAGE_BITMAP, a, b, LR_LOADFROMFILE); 

		bgbrush= CreatePatternBrush(bgbitmap); 

	} else { 

		bgbrush= (HBRUSH)COLOR_WINDOW; 

	} 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users