【发布时间】:2014-11-22 07:20:59
【问题描述】:
我的文档中写明用户名、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");
}
}
}
我得到了这个错误:
无法在参数传递中转换
const char*' toWCHAR*'
我必须为这些参数使用哪种变量以及如何使用?
【问题讨论】:
-
一个
LPWSTR又名wchar_t *? -
我是 C++ 新手,无法在参数中将 const char*' 转换为 WCHAR*',这是来自 dev++ 的错误
-
如果您要求(根据您的问题)
const char*,那么ProcAdd是否有某种原因需要LPWSTR,其中 const-ness 和字符宽度都不匹配?