我有一个非常简单的窗口窗体程序,我想在按下按钮时启动 notepad.exe。我得到一些预期的错误。请帮忙。
在我的代码的开头,我有
#pragma once
#include <windows.h>
#include <Shellapi.h>
在事件处理程序中,我有
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
ExecuteInfo.cbSize = sizeof(ExecuteInfo);
ExecuteInfo.fMask = NULL;
ExecuteInfo.hwnd = NULL;
ExecuteInfo.lpVerb = "open"; // Operation to perform
ExecuteInfo.lpFile = "C:\\Windows\\notepad.exe"; // Application name
ExecuteInfo.lpParameters = NULL; // Additional parameters
ExecuteInfo.lpDirectory = NULL; // Default directory
ExecuteInfo.nShow = SW_SHOW;
ExecuteInfo.hInstApp = NULL;
ShellExecuteEx(&ExecuteInfo);
}
注意:如果我在属性页>配置属性>常规(ALT-F7)下设置为“使用 Unicode 字符集”,我会收到以下错误消息
1>c:\users\marco\desktop\new folder (2)\test000\test000\Form1.h(140): error C2440: '=' : cannot convert from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\marco\desktop\new folder (2)\test000\test000\Form1.h(141): error C2440: '=' : cannot convert from 'const char [23]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
注意:如果我在属性页>配置属性>常规(ALT-F7)下设置为“使用多字节字符集”,我会收到以下错误消息
1>test000.obj : error LNK2028: unresolved token (0A000012) "extern "C" int __stdcall ShellExecuteExA(struct _SHELLEXECUTEINFOA *)" (?ShellExecuteExA@@$$J14YGHPAU_SHELLEXECUTEINFOA@@@Z) referenced in function "private: void __clrcall test000::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@test000@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>test000.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ShellExecuteExA(struct _SHELLEXECUTEINFOA *)" (?ShellExecuteExA@@$$J14YGHPAU_SHELLEXECUTEINFOA@@@Z) referenced in function "private: void __clrcall test000::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@test000@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>C:\Users\Marco\Desktop\New folder (2)\test000\Debug\test000.exe : fatal error LNK1120: 2 unresolved externals