ShellExecuteW函数用法
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
wchar_t* string_2_LPCWSTR(string orig)
{
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t* wcstring = (wchar_t*)malloc(sizeof(wchar_t) * (orig.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
return wcstring;
}
int main(int argc,char *argv[])
{
string path = "test.exe";
string argv1 = "1", argv2 = "2";
HINSTANCE x;
x = ShellExecuteW(
NULL,
string_2_LPCWSTR("open"),
string_2_LPCWSTR(path),
string_2_LPCWSTR(argv1 + " " + argv2),
NULL,
SW_SHOW);
if ((INT_PTR)x < 32) cout << GetLastError() << endl;
return 0;
}
|