无法在参数传递中将'const char *'转换为'WCHAR *' [英] Cannot convert 'const char*' to 'WCHAR*' in argument passing
问题描述
我有文档记录用户名,IP和密码必须为const char*
,并且在将变量放入const char
时收到此错误消息.
I have documentation where written that username, IP and password must be const char*
and when I'm putting varaibles in const char
, I'm getting this error message.
这是我的代码:
#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");
}
}
}
我得到了这个错误:
无法在传递参数时转换
const char*' to
WCHAR *'
cannot convert
const char*' to
WCHAR*' in argument passing
这些参数必须使用哪种变量?如何使用?
Which kind of variable must I use for those arguments and how?
推荐答案
您最有可能使用Visual Studio编译器之一,在Project Settings
中有一个Character set
选择.选择:
You are most likely using one of the Visual Studio compilers, where in Project Settings
, there is a Character set
choice. Choose from:
- Unicode字符集(UTF-16),默认
- 多字节字符集(UTF-8)
- 未设置
调用接受Unicode设置中的字符串的函数需要您输入Unicode字符串文字:
Calling functions that accept strings in the Unicode setting requires you to make Unicode string literals:
"hello"
类型为const char*
,而:
L"hello"
的类型为const wchar_t*
.因此,要么将配置更改为Not set
,要么将字符串文字更改为宽字符串.
is of type const wchar_t*
. So either change your configuration to Not set
or change your string literals to wide ones.
这篇关于无法在参数传递中将'const char *'转换为'WCHAR *'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!