|
Hi,
I have a console program (.exe) that i want to call from a C++ program. How do I pass the parameters to the console program from my C++ program.
Thank you in advance!!
BAC
|
|
|
|
|
 Use this function which does CreateProcess with the parameter u want
size_t ExecuteProcess(std::wstring FullPathToExe, std::wstring Parameters, size_t SecondsToWait)
{
size_t iMyCounter = 0, iReturnVal = 0, iPos = 0;
DWORD dwExitCode = 0;
std::wstring sTempStr = L"";
if (Parameters.size() != 0)
{
if (Parameters[0] != L' ')
{
Parameters.insert(0,L" ");
}
}
sTempStr = FullPathToExe;
iPos = sTempStr.find_last_of(L"\\");
sTempStr.erase(0, iPos +1);
Parameters = sTempStr.append(Parameters);
wchar_t * pwszParam = new wchar_t[Parameters.size() + 1];
if (pwszParam == 0)
{
return 1;
}
const wchar_t* pchrTemp = Parameters.c_str();
wcscpy_s(pwszParam, Parameters.size() + 1, pchrTemp);
STARTUPINFOW siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if (CreateProcessW(const_cast<LPCWSTR>(FullPathToExe.c_str()),
pwszParam, 0, 0, false,
CREATE_DEFAULT_ERROR_MODE, 0, 0,
&siStartupInfo, &piProcessInfo) != false)
{
dwExitCode = WaitForSingleObject(piProcessInfo.hProcess, (SecondsToWait * 1000));
}
else
{
iReturnVal = GetLastError();
}
delete[]pwszParam;
pwszParam = 0;
CloseHandle(piProcessInfo.hProcess);
CloseHandle(piProcessInfo.hThread);
return iReturnVal;
}
|
|
|
|
|
Reading CreateProcess function documentation [^] may help.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello Friends
I created a .exe and when I try to run that It shows a MessageBox that Displays
"The Application failed to initialize properly(0Xc0150002).Click on OK to terminate the application"
Any Ideas?????
Thanks
Yogesh
|
|
|
|
|
yogeshs wrote: I created a .exe
How?
yogeshs wrote: Any Ideas?????
Yes, click on OK to terminate the application.
|
|
|
|
|
very funny 
|
|
|
|
|
Ever looked in your windows event log for this error?
Greetings
Covean
|
|
|
|
|
Use the debugger.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
|
Thanks for your help but it is still showing that message Box.
|
|
|
|
|
Is it a normal exe or MFC ? can u detail more about what debugging techniques are yu using .. have u seen event viewer of your computer to see if an exception was thrown by ur aplication ??
|
|
|
|
|
Actually,we are using a third party exe.So I cant debug and nothing.I just want to run it on my machine and it is running there with third party.
|
|
|
|
|
Check ur file system and the filesystem n their machine normally this happens if there are filesystem differences FAT or NTFS . Or check with which Service pack they are running and what is you service pack of OS. also might be the case it requires Dotnet framework which you machhine doesnot have. Please see your event log and let me know cause of crash in your application .
|
|
|
|
|
yogeshs wrote: Actually,we are using a third party exe
In your original post you said you created the .exe. 
|
|
|
|
|
|
Did you try using depends.exe to see if all the required files are present in the machine you are trying to run this application?
modified on Thursday, July 8, 2010 11:58 PM
|
|
|
|
|
I tried that too but no success.
|
|
|
|
|
|
Hi,
khomeyni wrote: indeed i want to use member virtualization .does c++ has something like virtual member?
Virtualization (see, for instance [^]) has nothing to do with C++ virtual member functions.
And yes, using C++ language, you may define virtual member functions: surprisingly enough, you may find this info in the documentation [^] (and in every C++ book).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks
but i know that there is a virtual member function but i dont want function i want member virtualization as
virtual int x;
in a class ,please see the link that i said.
valhamdolelah.
|
|
|
|
|
khomeyni wrote: virtual int x;
You know, that make no sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
My TCP/IP (socket) has completed, but the client/server have some problem from CSocket, I may change from CSocket to raw win32 socket.
Before doing changes, I need your comments:
1. my develop OS is win2k, but MSDN says server functions (i.e. listen and accept) need OS-server to support, must I change my OS by OS-server for using server-functions?
2. Is it no good if I keep CSocket for server side and use raw socket for client side? - because server side has no problem.
|
|
|
|
|
includeh10 wrote: 1. my develop OS is win2k, but MSDN says server functions (i.e. listen and accept) need OS-server to support, must I change my OS by OS-server for using server-functions?
No. I have successfully used Winsock in Windows XP. Haven't used them in win2k though. But It should not be a problem.
includeh10 wrote: 2. Is it no good if I keep CSocket for server side and use raw socket for client side? - because server side has no problem.
If CSocket is badly designed as you said earlier, then remove it and use raw socket for both of them; it will be consistent too.
|
|
|
|
|
includeh10 wrote:
1. my develop OS is win2k, but MSDN says server functions (i.e. listen and accept) need OS-server to support, must I change my OS by OS-server for using server-functions?
I can't believe that. Where did you find it? I cannot find myself inside the page you linked.
includeh10 wrote: 2. Is it no good if I keep CSocket for server side and use raw socket for client side? - because server side has no problem.
No problems (of course) other than poor developer having to deal with two different API s.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
includeh10 wrote: 1. my develop OS is win2k, but MSDN says server functions (i.e. listen and accept) need OS-server to support, must I change my OS by OS-server for using server-functions?
I think you misread something, this has never been a requirement. If it was then most Windows PCs would not work.
includeh10 wrote: 2. Is it no good if I keep CSocket for server side and use raw socket for client side? - because server side has no problem.
CSocket is just an MFC wrapper around raw sockets, It is much more likely that there is a bug in your code rather than something wrong with CSocket.
|
|
|
|