Click here to Skip to main content
15,919,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help me to kill running bugs .... Pin
Sreekanth Muralidharan10-Apr-05 21:31
Sreekanth Muralidharan10-Apr-05 21:31 
GeneralRe: Help me to kill running bugs .... Pin
ThatsAlok10-Apr-05 20:29
ThatsAlok10-Apr-05 20:29 
GeneralRe: Help me to kill running bugs .... Pin
Sreekanth Muralidharan10-Apr-05 21:33
Sreekanth Muralidharan10-Apr-05 21:33 
GeneralShellApi Pin
emilie560210-Apr-05 18:35
emilie560210-Apr-05 18:35 
QuestionHow to Convert BYTE * to byte[] Pin
DeepToot10-Apr-05 18:08
DeepToot10-Apr-05 18:08 
AnswerRe: How to Convert BYTE * to byte[] Pin
DeepToot12-Apr-05 8:53
DeepToot12-Apr-05 8:53 
GeneralCSliderCtrl + dblclick Pin
Chris Losinger10-Apr-05 15:39
professionalChris Losinger10-Apr-05 15:39 
Generalmenu and sub menu Pin
mpapeo10-Apr-05 12:31
mpapeo10-Apr-05 12:31 
I want to create a submenu which uses the case statements. So my problem is the program crushes and i can't get the logic how i can arrange the case statements. Please help me, i am already under pressure because of time.
I want the program run such that if i enter option 1 it create a process and then produce which i can now suspend the process from there or shut it down in the submenu
Here is my code
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <windef.h><br />
#include <winbase.h><br />
#include <imagehlp.h><br />
#include <stdlib.h><br />
#include <ctype.h><br />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
<br />
int menu(void)<br />
{<br />
char iobuf[80];<br />
int choice;<br />
int i,len,valid;<br />
//HANDLE hProcess;<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t\t=");<br />
printf ("\n=\t 2: Quit the system\t\t=");<br />
printf ("\n=========================================\n");<br />
valid=0;<br />
printf("\nEnter choice (1-3): ");<br />
   <br />
   while( valid == 0)<br />
   {<br />
     fgets(iobuf,sizeof(iobuf),stdin);<br />
     // remove '\n' <br />
     len = strlen(iobuf)-1;<br />
     iobuf[len] = 0;<br />
     // validate data<br />
     valid = 1; // assume valid input<br />
     for(i = 0; i < len; i++)<br />
     {<br />
         if( !isdigit(iobuf[i]))<br />
         {<br />
           printf("\nPlese enter numeric digits only (1-5)\n");<br />
           valid = 0;<br />
         }<br />
      }<br />
   }<br />
  choice = atoi(iobuf);<br />
<br />
	return choice; <br />
 }<br />
<br />
int submenu(void)<br />
{<br />
char iobuf[80];<br />
int choice2;<br />
int i,len,valid;<br />
//HANDLE hProcess;<br />
<br />
PROCESS_INFORMATION pi;       /* filled in by CreateProcess */<br />
	STARTUPINFO si;               /* startup info for the new process*/<br />
	HANDLE hProcess;<br />
	DWORD lpAddr = 0;<br />
	TCHAR lpApplicationName[_MAX_PATH]="";	<br />
	int result;<br />
char ans [4]="";<br />
//int choice;<br />
<br />
printf ("\n*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Suspend the process\t\t=");<br />
printf ("\n=\t 2: Resume process \t=");<br />
printf ("\n=\t 3: Shutdown the process \t=");<br />
printf ("\n=\t 4: Exit the system \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
valid=0;<br />
printf("\nEnter choice (1-4): ");   <br />
   while( valid == 0)<br />
   {<br />
     fgets(iobuf,sizeof(iobuf),stdin);<br />
     // remove '\n' <br />
     len = strlen(iobuf)-1;<br />
     iobuf[len] = 0;<br />
     // validate data<br />
     valid = 1; // assume valid input<br />
     for(i = 0; i < len; i++)<br />
     {<br />
         if( !isdigit(iobuf[i]))<br />
         {<br />
           printf("\nPlese enter numeric digits only (1-4)\n");<br />
           valid = 0;<br />
         }<br />
      }<br />
   }<br />
while((choice2 = submenu())!=3)//int choice;<br />
{<br />
switch (choice2)<br />
{<br />
case 1:<br />
		SuspendThread(pi.hThread);// identifies thread to suspend	<br />
break;<br />
case 2:<br />
	ResumeThread(pi.hThread);		<br />
break;<br />
case 3:<br />
	printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");<br />
		scanf ("%s",ans);	<br />
		result = strcmp(ans,"y");<br />
		if (result==0)<br />
		{<br />
		TerminateProcess(pi.hThread, 0);//identifies the process to terminate<br />
		GetLastError();<br />
		}<br />
	break;<br />
default: printf("Invalid choice: ");<br />
<br />
 }}<br />
  choice2 = atoi(iobuf);<br />
	return choice2; <br />
valid = 0;<br />
}//submenu<br />
<br />
int main(int argc, char **argv) <br />
{<br />
	PROCESS_INFORMATION pi;    /* filled in by CreateProcess */<br />
	STARTUPINFO si;             /* startup info for the new process*/<br />
	HANDLE hProcess;<br />
	DWORD lpAddr = 0;<br />
	TCHAR lpApplicationName[_MAX_PATH]="";	<br />
	int result;<br />
char ans [4]="";<br />
int choice;<br />
while((choice = menu())!=6)//int choice;<br />
{<br />
switch (choice)<br />
{<br />
case 1: <br />
	GetStartupInfo(&si);<br />
lpAddr = 0;<br />
	ZeroMemory( &si, sizeof(si) );<br />
	si.cb = sizeof(si);<br />
	ZeroMemory( &pi, sizeof(pi) );<br />
printf("Enter process you want to execute: ",lpApplicationName);<br />
scanf ("%s",lpApplicationName);<br />
printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID<br />
<br />
CreateProcess(NULL, /* lpApplicationName */<br />
lpApplicationName, /* lpCommandLine assumes to use curent process directory*/<br />
NULL, /* lpsaProcess */<br />
NULL, /* lpsaThread */<br />
FALSE, /* bInheritHandles */<br />
CREATE_NEW_CONSOLE, /* dwCreationFlags */<br />
NULL, /* lpEnvironment */<br />
NULL, /* lpCurDir */<br />
&si, /* lpStartupInfo */<br />
&pi /* lpProcInfo */<br />
); <br />
hProcess = pi.hProcess;<br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
submenu();<br />
<br />
break;<br />
case 2:<br />
printf("\n\tAre you sure you want to quit the system!(y or n) ");<br />
scanf ("%s",ans);<br />
					<br />
result = strcmp(ans,"y");//comparing the input and y to quit<br />
				<br />
if (result==0)<br />
					<br />
{<br />
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate<br />
GetLastError();<br />
exit(EXIT_SUCCESS);		//exiting the console<br />
}GetLastError();	<br />
break;	<br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
return (0);<br />
}<br />

GeneralRe: menu and sub menu Pin
Christian Graus10-Apr-05 13:57
protectorChristian Graus10-Apr-05 13:57 
GeneralRe: menu and sub menu Pin
mpapeo10-Apr-05 15:17
mpapeo10-Apr-05 15:17 
GeneralRe: menu and sub menu Pin
Christian Graus10-Apr-05 15:22
protectorChristian Graus10-Apr-05 15:22 
GeneralRe: menu and sub menu Pin
mpapeo10-Apr-05 15:42
mpapeo10-Apr-05 15:42 
GeneralRe: menu and sub menu Pin
Christian Graus10-Apr-05 16:03
protectorChristian Graus10-Apr-05 16:03 
GeneralRe: menu and sub menu Pin
mpapeo10-Apr-05 16:16
mpapeo10-Apr-05 16:16 
GeneralRe: menu and sub menu Pin
Christian Graus10-Apr-05 16:28
protectorChristian Graus10-Apr-05 16:28 
GeneralRe: menu and sub menu Pin
mpapeo10-Apr-05 16:43
mpapeo10-Apr-05 16:43 
Generalrun my program from DOS Pin
includeh1010-Apr-05 10:45
includeh1010-Apr-05 10:45 
GeneralRe: run my program from DOS Pin
Ravi Bhavnani10-Apr-05 11:14
professionalRavi Bhavnani10-Apr-05 11:14 
GeneralTernary Operation Pin
Ganesh_Srim10-Apr-05 9:49
Ganesh_Srim10-Apr-05 9:49 
GeneralRe: Ternary Operation Pin
Joaquín M López Muñoz10-Apr-05 10:10
Joaquín M López Muñoz10-Apr-05 10:10 
GeneralRe: Ternary Operation Pin
Ganesh_Srim11-Apr-05 8:32
Ganesh_Srim11-Apr-05 8:32 
GeneralA regular expression needed Pin
John R. Shaw10-Apr-05 9:47
John R. Shaw10-Apr-05 9:47 
GeneralRe: A regular expression needed Pin
Michael Dunn10-Apr-05 10:25
sitebuilderMichael Dunn10-Apr-05 10:25 
GeneralRe: A regular expression needed Pin
John R. Shaw10-Apr-05 11:06
John R. Shaw10-Apr-05 11:06 
GeneralRe: A regular expression needed Pin
Michael Dunn10-Apr-05 12:05
sitebuilderMichael Dunn10-Apr-05 12:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.