Cannot convert 'const char*' to 'WCHAR*' in argument passing

DTDest

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.

This is my code:

#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");          
        }          
    }
}

And I got this error:

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

Which kind of variable must I use for those arguments and how?

the swine

You are most likely using one of the Visual Studio compilers, where in Project Settings, there is a Character set choice. Choose from:

  • Unicode character set (UTF-16), default
  • Multi-Byte character set (UTF-8)
  • Not Set

Calling functions that accept strings in the Unicode setting requires you to make Unicode string literals:

"hello"

Is of type const char*, whereas:

L"hello"

is of type const wchar_t*. So either change your configuration to Not set or change your string literals to wide ones.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'

cannot convert argument 1 from 'ATL::CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t>>>' to 'const char *'

Convert const char* to const wchar_t*

error: cannot convert const string to const char* for argument 1 to size_t strlen(const char*)

Cannot convert argument 1 from 'const char [11]' to 'LPCWSTR'

"cannot convert 'wchar_t*' to 'LPCSTR' {aka 'const char*'}gcc" when trying to use WriteConsoleOutputCharacter()

cannot convert argument 1 from wchar to lpcstr

Getting "error: cannot convert 'std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}' to 'const char*' error while passing a path as argument

QObject::connection(const QObject*, const char*, const char*, Qt::ConnectionType) "Cannot convert argument 3 from 'fileProcessor' to const QObject *"

cannot convert from const char* to const char *&

Argument type "WCHAR *" is incompatible with parameter of type "const char *"

win32 atoi issue which can't convert argument 1 from 'wchar_t [5]' to 'const char *

passing const char in argv main argument

error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'

C/C++ strcmp cannot convert argument 1 from 'char' to 'const char *'

GETTING THE ERROR IN VISUAL STUDIO: error C2664: '_chmod' : cannot convert parameter 1 from 'wchar_t [260]' to 'const char *'

Cannot convert 'TCHAR*' to 'const char*'

C++ --- error C2664: 'int scanf(const char *,...)' : cannot convert argument 1 from 'int' to 'const char *'

`Cannot convert 'char(*)[50]' to 'char**' for argument '1' to 'void prac(char**)'` when passing a 2D array to a function

Cannot convert argument from wchar_t[260] to LPSTR

'DWORD CHackProcess::GetModuleNamePointer(LPSTR,DWORD)': cannot convert argument 1 from 'const char [11]' to 'LPSTR'

Error C2664: MessageBoxW cannot convert argument 2 from 'const char ' to 'LPCWSTR'

error: cannot convert 'const char**' to 'const char (*)[64]'

Convert const wchar_t* into a WCHAR*

Error passing strings as pointers, cannot assign const char* to char*

Cannot convert const char to string constructing string

Cannot Convert string to 'char*' for argument error?

C2440: '=': cannot convert from 'const char [9]' to 'char*'

Cannot convert parameter 1 from char to const char for strcmp