StartProch代码如下:#pragma once#include pchh#include windowsh#include winuserh #include shellapihint main;void OpenProgramconst char path;StartProccpp代码如下:#include StartProchvoid OpenProgramconst char pat
要解决这个错误,你可以将路径的类型更改为LPCWSTR(宽字符字符串类型)。你可以使用MultiByteToWideChar函数将const char*转换为LPCWSTR类型。以下是修改后的代码示例:
#include "StartProc.h"
void OpenProgram(const char* path) { // 将const char转换为LPCWSTR int size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); wchar_t wpath = new wchar_t[size]; MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, size);
ShellExecute(NULL, L"open", wpath, NULL, NULL, SW_SHOWDEFAULT);
// 释放内存
delete[] wpath;
}
int main() { const char* path = "path_to_exe_program.exe"; OpenProgram(path); return 0; }
请注意,为了正确地进行转换,必须确保输入的const char*字符串是UTF-8编码。如果不是UTF-8编码,请相应地更改第一个MultiByteToWideChar函数中的CP_UTF8参数
原文地址: http://www.cveoy.top/t/topic/hL7O 著作权归作者所有。请勿转载和采集!