I have c# console application (Net framework 4.5, visual studio 2010 express). I can run this app by using cmd and its work normally. But with some very important reason I need run this app from other app that write on the c++. I have tried to run c# app by using ShellExecute, CreateProcess, WinExec. It’s always crash and don’t run at the same machine where I launched it before by using cmd. Is there still are any ways to start this c# app. Or need I compile/assemble this c# app with some special way?
Uppdate
example:
METHOD 1
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\PATH\\To\\THE\\APP.exe";
ShExecInfo.lpParameters = szParameters;
ShExecInfo.lpDirectory = NULL;
ShExecInfoFlash.hInstApp = NULL;
ShellExecuteEx(&ShExecInfoFlash);
WaitForSingleObject(ShExecInfoFlash.hProcess,INFINITE);
Method 2
PROCESS_INFORMATION pi;
char bff[512];
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
if(!CreateProcess(NULL,szParameters,NULL,NULL,0,0,NULL,NULL,&si,&pi))
{ return TS_METHOD_ABORTED;}
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
And it’s crashed always with the same way. It’s told me that something unexpected happened and propose me to send report to the MS.
I haven’t done what you are trying to do in c++ in a long time, but I did it recently in c#. I know this is half an answer, so sorry in advance for that. Does ShellExecute in c++ (or any of the other methods) give you the ability to set the working directory of the program you are launching? I’ve found that sometimes without setting this, the program being launched will think that it is running in a system folder, and as a result it may be unable to load resources because the relative paths are wrong.
Hope it helps.
Edit:
It appears ShellExecute does have what you are looking for.
Now that an example was posted, from above:
First, I recommend trying to launch another program you KNOW should work, like notepad.exe.
Next, like I said originally, set the working directory to match the exe.