|
Hi all,
some time ago, i had to write a program which starts other executeables (i did this with CreateProcess). Not a single process started was depending on the termination of another started one. Since then, the requirements changed and i have to include the execution of processes which depend on the termination of other processes. as i am not a programmer in general, i have no idea how this could be done. could someone please guide me how to do this?
CreateProcess A.exe --> A.exe is working without a dependency
CreateProcess B.exe --> Should be started when A.exe terminates
CreateProcess C.exe --> Should be started when B.exe terminates
Thanks in advance,
nmx
|
|
|
|
|
U can use the handle returned by CreateProcess as a parameter to WaitForSingleObject(..).. This will make your process wait for the process to exit and then continue.
<br />
In ur scenario it will be,<br />
HANDLE hprocessa = CreateProcess("a.exe", .. other parameters);<br />
WaitForSingleObject( hprocessa, INFINITE );<br />
HANDLE hprocessb = CreateProcess("b.exe", .. other parameters);<br />
WaitForSingleObject( hprocessb, INFINITE );<br />
CreateProcess("c.exe", .. other parameters);<br />
Chao!
|
|
|
|
|
Ciao nutkase. Thanks for your answer.
This is exactly the way i do it right now, but this is way too unflexbile. Lets say I want to start another Process D while Process A is running. Process B and C are waiting for the termination of Process A. If I use WaitForSingleObject(A, INFINITE) on Process A, i won't be able to execute another process (Process D) at the same time.
What i think about is having Events for the termination of a process.
Greets, nmx
|
|
|
|
|
Well, its just the matter of syncronization now. U will have to make a compromise on flexibility at some point. Events is a gr8 idea. best of luck
Unless lions have their historians, the tales of hunt will always glorify the hunters!
|
|
|
|
|
|
Your sig is looking a lot better ;0)
|
|
|
|
|
Thanks
|
|
|
|
|
Ok guys, i solved the problem using the processes HANDLE and PROCESS_INFORMATION
<br />
PROCESS_INFORMATION piProcessA;<br />
...<br />
DWORD dwExitCode;<br />
GetExitCodeProcess(piProcessA, &dwExitCode);<br />
while (dwExitCode == STILL_ACTIVE)<br />
{<br />
GetExitCodeProcess(process, &dwExitCode);<br />
Sleep(500);<br />
}<br />
Next challenge: How could it be done to have dynamic process dependencies. The configuration should be made in a header file (f.e. via #define)
There are a few processes: A,B,C and D
B depends on A and C --> #define B_DEPS "A,C"
Any ideas?
Ciao, nmx
|
|
|
|
|
Hi,
I want minimize,maximize,close icon in child window.How can i do this?
I tried lot of things but failed.
The problem is..I got these icons in my child window, when i minimized it has gone somewhere, so i cudn't maximize the window again..and also when i click restoreup in that three icon(middle one) it didn't minimized to small size..nothing get changed but three icons will disappeared.
One morething these three icons didnot display when the application opens, when i switch to another window in the same application then come back to this window then the three icons appear,
What can i do?
My requiremnt is same as vc++ coding environment(i.e., we can minimize,close and maximize the text editor in our vc++ complier)I need the same functionality..Pls help me out?
Anu
|
|
|
|
|
hi all i had made application that send() recv() through winsock API's not the MFC classes and winsock controll.
when i send one time it works fine and receives well but when i send more than once at a time
i.e
if((send(conn,"11",strlen("13"),0))==2)<br />
AfxMessageBox("11");<br />
if((send(conn,"12",strlen("13"),0))==2)<br />
AfxMessageBox("11");<br />
if((send(conn,"13",strlen("13"),0))==2)<br />
AfxMessageBox("13");<br />
and then closing the sockets<br />
other side cannot receive anything i mean it receive 0 bytes.i m using the receive side in for loop here is the code.
for (int i=0;i<3;i++)<br />
{<br />
int numbytes;<br />
char buf[5];<br />
if((numbytes=recv(new_fd,buf,strlen(buf),0))==0)<br />
AfxMessageBox("Conn Forcefully Rejected Receive Error");<br />
else<br />
{<br />
buf[(numbytes+1)] = '\0';<br />
AfxMessageBox(buf);<br />
} <br />
} and then it closes sockets also.
but it shows the conn forefully rejected receive error.
i dont why it is this.
Tasleem Arif
|
|
|
|
|
you just mention length '2'.
recv(new_fd,buf,strlen(buf),0)
instead use this
recv(new_fd,buf,2,0)
|
|
|
|
|
thanks it did worked.
Tasleem Arif
|
|
|
|
|
It seems that you find your answer but see an article about transfer file with socket on codeproject maybe it helpful for you.
|
|
|
|
|
In my opinion there could be many reasons for this code not working. The most important and in my opinion the one with the brightest chances is the connection not properly set up. post the full code then may be anybody would be able to help!
Unless lions have their historians, the tales of hunt will always glorify the hunters!
|
|
|
|
|
here is code for client that connected to server
WORD wVersionRequested;<br />
WSADATA wsaData;<br />
SOCKET conn;<br />
struct sockaddr_in server;<br />
<br />
wVersionRequested = MAKEWORD(2,0);<br />
if(WSAStartup( wVersionRequested, &wsaData)==0)<br />
{<br />
conn=socket(AF_INET,SOCK_STREAM,0);<br />
if(conn==INVALID_SOCKET)<br />
AfxMessageBox("Socket Created Fails");<br />
bool urlog=false; bool chatlog=false;<br />
bool blknet=false;bool blkusb=false;<br />
bool scrcap=false;<br />
<br />
CISFControllerDlg *obj=(CISFControllerDlg*)parame;<br />
server.sin_addr.s_addr=inet_addr((char*)(LPCTSTR)obj->m_strIp);<br />
server.sin_family=AF_INET;<br />
server.sin_port=htons(8085);<br />
if(connect(conn,(struct sockaddr*)&server,sizeof(server))==0)<br />
{<br />
HWND hCbox= GetDlgItem(obj->m_hWnd,IDC_CHKLOGURL);<br />
if(SendMessage(hCbox,BM_GETCHECK,0,0)==BST_CHECKED)<br />
{<br />
send(conn,"11",strlen("11"),0);<br />
AfxMessageBox("11");<br />
urlog=true;<br />
}<br />
else<br />
{<br />
send(conn,"12",strlen("12"),0);<br />
}<br />
hCbox= GetDlgItem(obj->m_hWnd,IDC_CHKLOGCHAT);<br />
if(SendMessage(hCbox,BM_GETCHECK,0,0)==BST_CHECKED)<br />
{<br />
send(conn,"21",strlen("21"),0);<br />
chatlog=true;<br />
}<br />
else<br />
{<br />
send(conn,"22",strlen("22"),0);<br />
}<br />
hCbox= GetDlgItem(obj->m_hWnd,IDC_CHKBLKNTWK);<br />
if(SendMessage(hCbox,BM_GETCHECK,0,0)==BST_CHECKED)<br />
{<br />
send(conn,"31",strlen("31"),0);<br />
blknet=true;<br />
}<br />
else<br />
{<br />
send(conn,"32",strlen("32"),0);<br />
}<br />
hCbox= GetDlgItem(obj->m_hWnd,IDC_CHKSRCCAP);<br />
if(SendMessage(hCbox,BM_GETCHECK,0,0)==BST_CHECKED)<br />
{<br />
send(conn,"41",strlen("41"),0);<br />
obj->m_SleepTime.TrimLeft();<br />
obj->m_SleepTime.TrimRight();<br />
t=(char*)(LPCTSTR)obj->m_SleepTime;<br />
send(conn,t,strlen(t),0);<br />
ShowWindow(GetDlgItem(obj->m_hWnd,IDC_EDSCTIME),false);<br />
ShowWindow(GetDlgItem(obj->m_hWnd,IDC_STATICTIME),false);<br />
scrcap=true;<br />
}<br />
else<br />
{<br />
send(conn,"42",strlen("42"),0);<br />
}<br />
hCbox= GetDlgItem(obj->m_hWnd,IDC_CHKUSB);<br />
if(SendMessage(hCbox,BM_GETCHECK,0,0)==BST_CHECKED)<br />
{<br />
send(conn,"51",strlen("51"),0);<br />
blkusb=true;<br />
}<br />
else<br />
{<br />
send(conn,"52",strlen("52"),0);<br />
}<br />
obj->m_LLobj.UpdateLinkList(obj->m_strIp,urlog,chatlog,blkusb,blknet,scrcap);<br />
}<br />
else<br />
AfxMessageBox("Connect Fails");<br />
closesocket(conn);<br />
shutdown(conn,2);<br />
}<br />
else<br />
AfxMessageBox("Start UP Fails");<br />
WSACleanup();<br />
return 0;<br />
}
here is the server portion both r in seperate thread.
WORD wVersionRequested;<br />
WSADATA wsaData;<br />
wVersionRequested = MAKEWORD(2,0);<br />
if(WSAStartup( wVersionRequested, &wsaData) == 0 )<br />
{<br />
while(bRunService)<br />
{<br />
int sockfd, new_fd;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int sin_size;<br />
char *yes="1";<br />
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) <br />
AfxMessageBox("Socket Creation Failed");<br />
if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,yes,sizeof(yes)) == -1) <br />
AfxMessageBox("set socket app");<br />
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(8085);
my_addr.sin_addr.s_addr =INADDR_ANY;
memset(&(my_addr.sin_zero), '\0', 8);
<br />
if(bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))== -1) <br />
AfxMessageBox("IP not binded");<br />
<br />
if (listen(sockfd, 5) == -1) <br />
AfxMessageBox("Listen Failed");<br />
<br />
sin_size = sizeof(struct sockaddr_in);<br />
if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr,&sin_size)) == -1)<br />
AfxMessageBox("accept failed");
<br />
AfxMessageBox("Accept");<br />
for (int i=0;i<4;i++){<br />
int numbytes;<br />
char buf[5];<br />
if((numbytes=recv(new_fd,buf,2,0))==0)<br />
AfxMessageBox("Conn Forcefully Rejected Receive Error");<br />
else<br />
{<br />
buf[(numbytes+1)] = '\0';<br />
AfxMessageBox(buf);<br />
int choice=atoi(buf);<br />
switch(choice)<br />
{<br />
case 11:
if(!bLogUrl)<br />
{<br />
bLogUrl=TRUE;<br />
RegisterBHO();<br />
}<br />
break;<br />
case 12:<br />
if(bLogUrl)<br />
{<br />
bLogUrl=FALSE;<br />
UnregisterBHO();<br />
}<br />
break;<br />
case 21:
if (!bLogChat) <br />
{<br />
bLogChat=TRUE;<br />
StartKeyloggerThread();<br />
}<br />
break;<br />
case 22:<br />
bLogChat=FALSE;<br />
break;<br />
case 31:
if (!bAddFilters)<br />
{<br />
bAddFilters=TRUE;<br />
AddSingleFilter();<br />
}<br />
break;<br />
case 32:
if (bAddFilters)<br />
{<br />
bAddFilters=FALSE;<br />
RemoveSingleFilter();<br />
}<br />
break;<br />
case 41:
if (!bScreenCap)<br />
{<br />
char temp[5];<br />
numbytes=recv(new_fd,temp,strlen(buf),0);<br />
bScreenCap=TRUE;<br />
temp[numbytes+1]='\0';<br />
AfxMessageBox(temp);<br />
SleepTime=atoi(temp);<br />
StartScreenCapThread();<br />
}<br />
break;<br />
case 42:<br />
bScreenCap=FALSE;<br />
break;<br />
case 51:
AfxMessageBox("51");<br />
break;<br />
case 52:<br />
AfxMessageBox("52");<br />
break;<br />
}}
}
closesocket(new_fd);<br />
closesocket(sockfd);<br />
shutdown(sockfd,2);<br />
shutdown(new_fd,2);<br />
}
}<br />
WSACleanup();<br />
return 0;
its too long but it is it.
Tasleem Arif
|
|
|
|
|
Hello friends,
I have an appication of recording a wave file.
But i want to specify the sound device through which only
the wave file should be recorded. That is if my machine has more than one sound card
then i want to select one (through Programmatically) and record sound from that one only.
How to do that.
Thanks in Advance.
Rahul Kulkarni
|
|
|
|
|
I am amidst developement of toolbar for a site on IE.
buttons have been added to it with help of TB_Insert.
I have to get now coordinate position of each button.
How to get the position. Can anyone help me. Only ATL no MFC.
|| ART OF LIVING ||
|
|
|
|
|
Sir,
Is there any difference between hardware interfacing and embedding systems.
Thanks
|
|
|
|
|
Hi,
I get the file size and I want to format it using the format (xxx,xxx,xxx), for example:
35456931 --> 35,456,931 bytes.
how can I do it??
Regards
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
Mohammad A Gdeisat wrote:
35456931 --> 35,456,931 bytes.
Like this:
CString strNum="123467890";
int len=strNum.GetLength ();
for(int i=len-3;i>0;i-=3)
{
strNum.Insert (i,',');
}
AfxMessageBox (strNum);
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Here is some code that will format a number using the current locale settings:
std::string format(unsigned int n)
{
std::stringstream strm;
strm.imbue(std::locale(""));
strm << n;
return strm.str();
}
Kicking squealing Gucci little piggy.
|
|
|
|
|
This version should handle any number (int, long, etc.):
template <typename T>
std::string format(T t)
{
std::stringstream strm;
strm.imbue(std::locale(""));
strm << t;
return strm.str();
}
Last modified: 11mins after originally posted --
Kicking squealing Gucci little piggy.
|
|
|
|
|
|
Exactly how does this add commas to the number?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I see he gets file size so I guess its better he uses from this function (for comma CString::Format )
|
|
|
|
|