在参数传递中无法将'const char*'转换为'WCHAR*'

DTD*_*est 7 c++ char wchar

我有文件写的用户名,IP和密码必须是const char*,当我把变量输入const char,我收到此错误信息.

这是我的代码:

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <windows.h>

using namespace std;

typedef int (__cdecl *MYPROC)(LPWSTR);

int main()
{
    HINSTANCE hinstDLL;
    MYPROC ProcAdd;   
    hinstDLL = LoadLibrary("LmServerAPI.dll");
    if(hinstDLL != NULL){
        ProcAdd = (MYPROC) GetProcAddress(hinstDLL,"LmServer_Login");            
        if(ProcAdd != NULL){
            const char* IP = "xxx.177.xxx.23";
            const char* name = "username";
            const char* pass = "password";
            int port = 888;
            ProcAdd(IP,port,name,pass);
            system ("pause");          
        }          
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

const char*' to在参数传递中无法转换WCHAR*'

我必须使用哪种变量用于这些参数以及如何使用?

the*_*ine 14

您最有可能使用其中一个Visual Studio编译器,其中Project Settings有一个Character set选项.从中选择:

  • Unicode字符集(UTF-16),默认
  • 多字节字符集(UTF-8)
  • 没有设置

调用接受Unicode设置中的字符串的函数需要您创建Unicode字符串文字:

"hello"
Run Code Online (Sandbox Code Playgroud)

属于类型const char*,而:

L"hello"
Run Code Online (Sandbox Code Playgroud)

是类型的const wchar_t*.因此,要么将配置更改为Not set或将字符串文字更改为宽文字.