我有一個非常簡單的窗體表單程序,我想在按下按鈕時啓動notepad.exe。我收到了一些預期的錯誤。請幫忙。如何在VC++中正確啓動進程?
在我的代碼開始時,我有
#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);
}
注:我收到以下錯誤消息,如果我設置爲「使用Unicode字符集」下的屬性頁>配置屬性>常規(ALT-F7)
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
注:我得到的FO llowing錯誤消息,如果我設置爲「使用多字節字符集」下的屬性頁>配置屬性>常規(ALT-F7)
1>test000.obj : error LNK2028: unresolved token (0A000012) "extern "C" int __stdcall ShellExecuteExA(struct _SHELLEXECUTEINFOA *)" ([email protected]@[email protected]@@Z) referenced in function "private: void __clrcall test000::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@@Z)
1>test000.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ShellExecuteExA(struct _SHELLEXECUTEINFOA *)" ([email protected]@[email protected]@@Z) referenced in function "private: void __clrcall test000::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@@Z)
1>C:\Users\Marco\Desktop\New folder (2)\test000\Debug\test000.exe : fatal error LNK1120: 2 unresolved externals
This works。Thanks。 – user765168 2012-04-25 12:11:49
我非常喜歡這個,我可以打開Firefox並轉到只有一行代碼的網站。 – user765168 2012-04-25 18:17:05