J'ai un programme de formulaire de fenêtre très simple et je veux démarrer notepad.exe quand j'appuie sur un bouton. Je reçois des erreurs attendues. S'il vous plaît aider.Comment démarrer correctement un processus dans VC++?
Au début de mon code, je
#pragma once
#include <windows.h>
#include <Shellapi.h>
Dans le gestionnaire d'événements, je
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);
}
Note: Je reçois le texte suivant le message d'erreur si je me mis à « Utiliser Unicode Jeu de caractères » dans les pages de propriétés> Propriétés de configuration> général (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
note: je reçois le fo llowing le message d'erreur si je réglé sur « Utiliser multi-octets Jeu de caractères » dans les pages de propriétés> Propriétés de configuration> Général (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
Cela fonctionne.Merci – user765168
J'aime tellement ça.Je peux ouvrir Firefox et aller à un site web avec seulement 1 ligne de code. – user765168