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

c – 在参数传递中无法将’const char *’转换为’WCHAR *’,第1张

概述我有文件,其中写的用户名,IP和密码必须是const char *,当我在const char中放置变量时,我收到此错误消息. 这是我的代码: #include <cstdlib>#include <iostream>#include <stdio.h>#include <windows.h>using namespace std;typedef int (__cdecl *MYPR @H_502_0@我有文件,其中写的用户名,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");                  }              }}

我收到了这个错误:

cannot convert const char*' toWCHAR*’ in argument passing

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

解决方法 您最有可能使用Visual Studio编译器之一,在“项目设置”中,有一个字符集选项.从中选择:

> Unicode字符集(UTF-16),默认
>多字节字符集(UTF-8)
>未设置

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

"hello"

是const char *类型,而:

L"hello"

是const wchar_t *类型.因此,要么将配置更改为“未设置”,要么将字符串文字更改为宽文字.

总结

以上是内存溢出为你收集整理的c – 在参数传递中无法将’const char *’转换为’WCHAR *’全部内容,希望文章能够帮你解决c – 在参数传递中无法将’const char *’转换为’WCHAR *’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1234597.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存