ShellExecute Unknown issue

closed account (S864GNh0)
I'm having trouble with ShellExecute().

when i directly type the program name, it works fine

code:

int nRet = (int)ShellExecute(0, L"open", L"notepad++.exe 0, 0, SW_SHOWNORMAL);
return 0;


but when i convert a string to LPCTSTR it just opens the file explorer ._.

code:

std::string Prog4 = "notepadd++.exe";
std::wstring Program;
Prog4.assign(Program.begin(), Program.end());
LPCTSTR appl = Program.c_str();

int nRet = (int)ShellExecute(0, L"open", appl, 0, 0, SW_SHOWNORMAL);
return 0;

any suggestions or answers would help a lot.
closed account (S864GNh0)
nvm i fixed the issue.

it was a conversion error.

here is the new code that turns a string to a std::wstring then const wchar_t*

code:

Prog4 = "notepad++.exe";

std::wstring Program(Prog4.length(), L' '); // Make room for characters
// Copy string to wstring.
std::copy(Prog4.begin(), Prog4.end(), Program.begin());

std::wcout << "wwww = " << Program << endl; //check wstring

const wchar_t* appl = Program.c_str(); //copy to const wchar_t*
std::cout << "appl = "<< appl << endl;

ShellExecute(NULL, L"open", appl, NULL, NULL, SW_SHOWNORMAL); //opens notpad++.exe :D
Topic archived. No new replies allowed.