Shellexecute error

HI,

string cmd = "";
cmd = " -l ";
cmd.append(user);
cmd.append(" -pw ");
cmd.append(pwd);
cmd.append(" ");
cmd.append(host);
ShellExecute(NULL,TEXT("open"),TEXT("putty.exe"),TEXT(cmd),NULL,SW_NORMAL);

I constructed a string that contains parameters for my .exe file. But when i try to insert the string into the ShellExecute command i got this:

error C2664: 'ShellExecuteW' : cannot convert parameter 4 from 'std::string' to 'LPCWSTR'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


note:
I cant just type fix parameters because i have to keep them variable


Answer this question

Shellexecute error

  • AndreasE

    This is correct if you are compiling with unicode.
    Use the wstring class! The string class is a MBCS string, the wstring class is a unicode string.
    I forgot. Don't use TEXT() for cmd!

  • miztaken


    If you need unicode than you have to


    wstring cmd;
    cmd.append(TEXT(" -l "));
    cmd.append(user);
    cmd.append(TEXT(" -pw "));
    cmd.append(pwd);

     


    The fields user and pwb must be of type unicode too!

    Learn more about unicode usage in C++ programs!



  • CLearlyDotNet

    mhh. doesnt work for me.. or i do something wrong
    that's it now:

    56: wstring cmd;
    57: cmd.append(" -l ");
    58: cmd.append(user);
    59: cmd.append(" -pw ");
    60: cmd.append(pwd);
    61: cmd.append(" ");
    62: cmd.append(host);

    69: ShellExecute(NULL,TEXT("open"),TEXT("putty.exe"),cmd,NULL,SW_NORMAL);


    and i get this errors:

    .\puttywarper.cpp(57) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::append(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'const char [5]' to 'const std::basic_string<_Elem,_Traits,_Ax> &'

    .\puttywarper.cpp(69) : error C2664: 'ShellExecuteW' : cannot convert parameter 4 from 'std::wstring' to 'LPCWSTR'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

     


  • Shellexecute error