无法将参数1从“char *”转换为“LPCWSTR” [英] cannot convert parameter 1 from 'char *' to 'LPCWSTR'

查看:2748
本文介绍了无法将参数1从“char *”转换为“LPCWSTR”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在载入BMP档案

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
}

m现在得到错误


错误C2664:'auxDIBImageLoadW':无法将参数1从'char *'转换为'LPCWSTR'

error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'

如何解决?

推荐答案

您正在使用字符集设置为UNICODE(项目设置 - >配置选项 - >常规)来编译应用程序。 Windows头文件使用#defines将函数名称映射到nameA(对于多字节字符串)或nameW(对于unicode字符串)。

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

这意味着头文件中会有一个#define就像这样

That means somewhere in a header file there will be a #define like this

#define auxDIBImageLoad auxDIBImageLoadW

所以你实际上不是调用 auxDIBImageLoad (没有那个名字的函数)重新调用 auxDIBImageLoadW auxDIBImageLoadW 需要一个unicode字符串( wchar_t const * )。您正在传递多字节字符串( char const * )。

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 替换为 auxDIBImageLoadA

  • 来调用函数的多字节版本>更改 LoadBMP 函数接受unicode字符串本身
  • 将字符串转换为unicode LoadBMP

  • 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

我建议您更改 LoadBMP 一个unicode字符串本身或直接调用 auxDIBImageLoadA (按顺序)。
如果不破坏很多其他代码,更改项目设置可能是OK。
我会建议转换字符串,虽然,因为它是不必要的。直接调用 auxDIBImageLoadA 更容易,结果是一样的。

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.

这篇关于无法将参数1从“char *”转换为“LPCWSTR”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆