cannot convert parameter 1 from 'char *' to 'LPCWSTR'

前端 未结 5 886
北海茫月
北海茫月 2020-12-15 06:45

Im trying to load a BMP file

AUX_RGBImageRec *LoadBMP(char *Filename)  // Loads A Bitmap Image
{
    FILE *File=NULL;                      // File Handle

           


        
相关标签:
5条回答
  • 2020-12-15 06:53

    Convert the character array to a LPCWSTR. You can see this in the 2nd guys post here

    0 讨论(0)
  • 2020-12-15 06:54

    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'.

    0 讨论(0)
  • 2020-12-15 06:57

    Try using MultiByteToWideChar() the following way:

    void main(int argc, char* argv[])
    {
     ...
     wchar_t filename[4096] = {0};
     MultiByteToWideChar(0, 0, argv[1], strlen(argv[1]), filename, strlen(argv[1]));
    
     // RenderFile() requires LPCWSTR (or wchar_t*, respectively)
     hr = pGraph->RenderFile(filename, NULL);
     ...
    }
    
    0 讨论(0)
  • 2020-12-15 07:00

    You have a few options:

    • Change the 'character set' option in your project settings from 'Unicode' to 'Not Set'
    • Call auxDIBImageLoadA instead of auxDIBImageLoad
    • Change Filename's type from char* to wchar_t*
    • Use std::mbstowcs to convert Filename from a char* to a wchar_t*
    0 讨论(0)
  • 2020-12-15 07:03

    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

    • change your project to use multi-byte character set (-> project settings)
    • explicitly call the multi-byte version of the function by replacing auxDIBImageLoad with auxDIBImageLoadA
    • change your LoadBMP function to accept a unicode string itself
    • convert the string to unicode inside LoadBMP

    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.

    0 讨论(0)
提交回复
热议问题