Im trying to load a BMP file
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
this has come from an example however i'm now getting the error
error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
how could I correct this?
An LPCWSTR is a 32-bit pointer to a constant string of 16-bit Unicode characters, which MAY be null-terminated.
LPCTSTR is a pointer to a const TCHAR string, ( TCHAR being either a wide char or char depending on whether UNICODE is defined in your project)
You're compiling your application with Character-Set set to UNICODE (Project Settings -> Configuration Options -> General). Windows header files use #defines to "map" function names to either nameA (for multi-byte strings) or nameW (for unicode strings).
That means somewhere in a header file there will be a #define like this
#define auxDIBImageLoad auxDIBImageLoadW
So you're not actually calling auxDIBImageLoad
(there is no function with that name), you're calling auxDIBImageLoadW
. And auxDIBImageLoadW
expects a unicode string (wchar_t const*
). You're passing a multi-byte string (char const*
).
You can do one of the following
auxDIBImageLoad
with auxDIBImageLoadA
LoadBMP
function to accept a unicode string itselfLoadBMP
I'd recommend either changing LoadBMP
to accept a unicode string itself or calling auxDIBImageLoadA
directly (in that order).
Changing the project settings might be OK if it doesn't break a lot of other code.
I would not suggest converting the string though, since it's unnecessary. Calling auxDIBImageLoadA
directly is far easier, and the result is the same.
You have a few options:
auxDIBImageLoadA
instead of auxDIBImageLoad
Filename
's type from char*
to wchar_t*
std::mbstowcs
to convert Filename from a char*
to a wchar_t*
Looks like your trying to use two different character sets. 'char ' is the typical ANSI and LPCWSTR is the wide character (i.e. unicode). If you would like to use char change the 'Character Set' property in your project setting to 'No Set'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With