How to execute another application
-
I use Windows Forms Application and i would execute an another application like a Word file, i try ShellExecute; But there are errors, i write :
ShellExecute(0,'OPEN','C:\Documents and Settings\abbd\Bureau\App2.0\Ids 0.0\Ids 0.0\az.doc',Nil,Nil, SW_SHOW);
error C2015: too many characters in constant error C2065: 'Nil' : undeclared identifier error C2065: 'SW_SHOW' : undeclared identifier error C3861: 'ShellExecute': identifier not found Please help to execute this file, thank you. -
I use Windows Forms Application and i would execute an another application like a Word file, i try ShellExecute; But there are errors, i write :
ShellExecute(0,'OPEN','C:\Documents and Settings\abbd\Bureau\App2.0\Ids 0.0\Ids 0.0\az.doc',Nil,Nil, SW_SHOW);
error C2015: too many characters in constant error C2065: 'Nil' : undeclared identifier error C2065: 'SW_SHOW' : undeclared identifier error C3861: 'ShellExecute': identifier not found Please help to execute this file, thank you.Since you are using .NET, you should use Process::Start
Regards, Nish
Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*) -
I use Windows Forms Application and i would execute an another application like a Word file, i try ShellExecute; But there are errors, i write :
ShellExecute(0,'OPEN','C:\Documents and Settings\abbd\Bureau\App2.0\Ids 0.0\Ids 0.0\az.doc',Nil,Nil, SW_SHOW);
error C2015: too many characters in constant error C2065: 'Nil' : undeclared identifier error C2065: 'SW_SHOW' : undeclared identifier error C3861: 'ShellExecute': identifier not found Please help to execute this file, thank you.abbd wrote:
error C3861: 'ShellExecute': identifier not found
That error indicates you don't know how to #include header files for C++ development. The fact that you don't know that indicates that you need to step back to student mode and learn some prerequisite programming topics before you try to write working windows applications.
led mike
-
I use Windows Forms Application and i would execute an another application like a Word file, i try ShellExecute; But there are errors, i write :
ShellExecute(0,'OPEN','C:\Documents and Settings\abbd\Bureau\App2.0\Ids 0.0\Ids 0.0\az.doc',Nil,Nil, SW_SHOW);
error C2015: too many characters in constant error C2065: 'Nil' : undeclared identifier error C2065: 'SW_SHOW' : undeclared identifier error C3861: 'ShellExecute': identifier not found Please help to execute this file, thank you.first of all the type of formas application you need is.... CLR Windows Forms Aplication create a process outside the namespace.. and use these headers.. #include string #include windows.h #include process.h using namespace std; unsigned __stdcall execplz(void *params); string cl; somewhere in your program you need to place the following line to execute the command;
unsigned sID; (HANDLE)_beginthreadex( NULL, 0, execplz, NULL, 0, &sID);
and keep in mind the command line string is std::string cl; which i have set as global string at top so you can use anywhere.. the process below will create a process invisibly to yours ok.. so to change that you need to remove... si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE;unsigned __stdcall execplz(void *params){ string fnn; int nLen = cl.length(); bl=cl; std::string::size_type idx; idx=bl.rfind("\\"); bl=bl.substr(idx, string::npos); cl=cl.substr(0, idx-1); int nLeng = bl.length(); LPWSTR szCmdLine = new WCHAR[nLen+1]; MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,cl.c_str(),nLen,szCmdLine,nLen); szCmdLine[nLen] = '\0'; LPWSTR fnonly = new WCHAR[nLeng+1]; MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,bl.c_str(),nLeng,fnonly,nLeng); fnonly[nLeng]='\0'; STARTUPINFO si; PROCESS_INFORMATION pi; GetStartupInfo(&si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); if( !CreateProcess( szCmdLine, fnonly, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); } return 0; }
ok so the reason why i have this a separate process.. is because its using threads.. you can use this at anytime even when soemthing else is going on..multiple times at once if wished.. good for creating webservers and such... -- modified at 5:26 Saturday 10th March, 2007