|
This is what i have,
<code>
#include <windows.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <imagehlp.h>
#include <stdlib.h>
#include <ctype.h>
typedef struct _iobuf FILE;
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
int menu(void)
{
char iobuf[80];
int choice;
int i,len,valid;
printf ("\n");
printf ("*****************************************\n");
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");
printf ("=========================================");
printf ("\n=\t 1: Create a process \t\t=");
printf ("\n=\t 2: Suspend the process\t\t=");
printf ("\n=\t 3: Resume process \t=");
printf ("\n=\t 4: Shutdown the process \t=");
printf ("\n=========================================\n");
printf ("\n");
printf("\nEnter choice (1-4): ");
valid = 0;
while( valid == 0)
{
fgets(iobuf,sizeof(iobuf),stdin);
// remove '\n'
len = strlen(iobuf)-1;
iobuf[len] = 0;
// validate data
valid = 1; // assume valid input
for(i = 0; i < len; i++)
{
if( !isdigit(iobuf[i]))
{
printf("\nPlese enter numeric digits only (1-4)\n");
valid = 0;
}
}
}
choice = atoi(iobuf);
//scanf("%d", &choice);
return choice;
}
int main(int argc, char **argv)
{
PROCESS_INFORMATION pi; /* filled in by CreateProcess */
STARTUPINFO si; /* startup info for the new process*/
HANDLE hProcess;
DWORD lpAddr = 0;
TCHAR lpApplicationName[_MAX_PATH]="";
int result;
char ans [4]="";
int choice;
while((choice = menu())!=5)//int choice;
{
switch (choice)
{
case 1:
GetStartupInfo(&si);
lpAddr = 0;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
printf("Enter process you want to execute: ",lpApplicationName);
scanf ("%s",lpApplicationName);
printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID
CreateProcess(NULL, /* lpApplicationName */
lpApplicationName, /* lpCommandLine assumes to use curent process directory*/
NULL, /* lpsaProcess */
NULL, /* lpsaThread */
FALSE, /* bInheritHandles */
CREATE_NEW_CONSOLE, /* dwCreationFlags */
NULL, /* lpEnvironment */
NULL, /* lpCurDir */
&si, /* lpStartupInfo */
&pi /* lpProcInfo */
);
hProcess = pi.hProcess;
printf("New Process ID: %d ",pi.dwProcessId);
printf("has started \n");
break;
case 2:
SuspendThread(pi.hProcess);// identifies thread to suspend
break;
case 3:
ResumeThread(pi.hProcess);
break;
case 4:
printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");
scanf ("%s",ans);
result = strcmp(ans,"y");
if (result==0)
{
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate
GetLastError();
}
break;
default:
printf("\nInvalid choice: ");
}
}
return (0);
}
</code>
|
|
|
|
|
OK, so it IS a C program ? ( Not C++ )
If you want to put the menu into a seperate function ( not a bad idea ), then you need to pass in the hProcess variable, so you know if there's a process going or not.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
You mean passing it as an input?
-oam-
|
|
|
|
|
Yes, so you can check if it's NULL, and alter your options accordingly.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I stil have the program crushing, i might be missing something
<br />
printf("\nEnter choice (1-4): ");<br />
valid = 0;<br />
while( valid == 0)<br />
{<br />
fgets(iobuf,sizeof(iobuf),stdin);<br />
len = strlen(iobuf)-1;<br />
iobuf[len] = 0;<br />
valid = 1;
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 />
hProcess = atoi(iobuf);<br />
<br />
<br />
return hProcess;
}<br />
-oam-
|
|
|
|
|
mpapeo wrote:
I stil have the program crushing, i might be missing something
While it is a bad design, this code is syntactically correct. The "crush" your program is experiencing is in some other code. Why not single-step through the code until you get to the statement(s) in error?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Why comment out the scanf?
try this ...
<br />
int choice;<br />
while (true) {<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: Suspend the process\t\t=");<br />
printf ("\n=\t 3: Resume process \t=");<br />
printf ("\n=\t 4: Shutdown the process \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
printf ("\nEnter choice (1-4): ");<br />
<br />
scanf("%u", &choice);<br />
<br />
switch (choice) {<br />
case 1:<br />
case 2:<br />
case 3:<br />
case 4: return choice; break;<br />
default: printf("\nPlese enter numeric digits only (1-4)\n"); break;<br />
}<br />
}<br />
Now the while(true) { } loop is used, it should be used sparingly. That loop will keep iterating through the menu indefinitely. The only way to get out is to choose one of the valid options. The switch will catch options 1 through 4 and return them, anything else will show the error. The switch-case statement is very useful in this case because you can run code for each option and handle all other cases. If you choose say option 2, it'll enter at case 2 but then keep going through case 3 and then it will reach case 4, return the number 2 (stored in choice) and then break; (it's really unreachable code because the function will end at the return statement.
|
|
|
|
|
let me try chris method first
-oam-
seems as that im having slight problems
why does it takes default now after pass the hProcess
|
|
|
|
|
I still have the program crashing
-oam-
|
|
|
|
|
Hi, I was wondering if anyone knows how to emulate assembly commands in c++.
Like for instance, there is the command LDA# which is load directly into the accumulator at whatever the address specified is. The only problem is i have no idea how to do this in c++. So what i need help with is taking the LDA# and recreating it in c++(or any other command for that matter). If anyone knows how to do this could you please help me out.
Thanks
|
|
|
|
|
You can actually embed assembler in your C++ application.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I need to attach crystal reports to my project. Where can I get the tool from?
awasthy
Any work worth doing is worth doing well.
|
|
|
|
|
I'm afraid that you should have to buy it. I remember an older version of Crystal Reports was added to MS VC 4.0 CD for free.
|
|
|
|
|
A Workspace that runs perfectly on Windows XP at work, is producing an exception on XP Home (at home!!). It is in the InitInstance of the app attempting to execute ProcessShellCommand(CmdInfo). Its giving an exception (0XE06D7363). Have trawled the web - checked and double checked all my project setting, all to no avail. Am I being stupid and missing something obvious??????
|
|
|
|
|
Hey,
Me too facing the same problem... in ProcessShellCommand as u faced... did u get any soln on this .. plz let me know
regards
|
|
|
|
|
Hello,
I'm trying to create a menu (actually it is a modified toolbar) that looks like the IE or Mozilla menu bar.
I've read this article: http://www.codeproject.com/docking/sizablerebar.asp
Now I'm having problems in creating such a flat toolbar in WinXP using the WinAPI.
The final result should look like this:
http://user96.kundenserver9hsgbr.de/menu1.gif
And this is my current toolbar:
http://user96.kundenserver9hsgbr.de/menu2.gif
For the moment I am not interested in the background color (this comes from the rebar control I think)
I'm just interested in the hover effect which looks quite different. What should I change?
I'm using the TBSTYLE_FLAT style but I do no get the expected results.
|
|
|
|
|
Are you talking about hot tracking?
Check out the TB_SETHOTIMAGELIST message.
You need to use image lists for button images and create a list used for "hot" items.
|
|
|
|
|
Here is a program i need to do.. i would like some help..please contact me
here it is:
Write a program to read from an input file the salesperson’s id and their quarterly sales for the year. Compute the total yearly sales, avg sales and commission for each salesperson. You will also compute the company’s total sales. Create a report in this following tabular format:
-----------------Annual Sales Report ------------------
ID QT1 QT2 QT3 QT4 TOTAL AVG COMM
12345 $1,892.00 $4,000.00 $435.00 $1000.00 $7327.00 $1831.75 $2198.10
Total Sales for the Company: //(sum of all the salesperson’s yearly sales)
Requirements:
1. Read from the input file (salesperson_yrsales.dat) the salesperson’s record in the following format: Remember this file will contain several records.
salesperson’s ID#Qsales1#Qsales2#Qsales3#Qsales4
2. Create a structure with the following members.
Salesperson’s ID // salesperson ID number (int),
Qsales1 - // sales for quarter 1 (double)
Qsales2 - // sales for quarter 2 (double)
Qsales3 - // sales for quarter 3 (double)
Qsales4 - // sales for quarter 4 (double)
Yearly sales - // total sales for the year (double)
Avg sales - // the average sales for the year (double)
commission - // sales commission (double)
3. Compute the total yearly sales, average sales and commission amount (30%) for each salesperson.
4. Print a sales report as specified previously to display the sales information. Remember to use padright and padleft.
5. Use the following functions in your program:
a. readFile : This function reads the salesperson’s ID and quarterly sales from the input file and stores the information in the record structure.
b. totalSaleByPerson: This function computes each salesperson’s yearly sales amount,
c. avgSaleByPerson: This function computes each salesperson’s , average sales for the year.
d. commByPerson: This function computes each salesperson’s commission for the year.
e. totalSales: This function computes the company’s total sales by adding yearly sales amount from each salesperson.
f. printReport: This function prints the annual report in the specified format.
I would apreciate someone helping me.
|
|
|
|
|
diegomiami wrote:
i would like some help
Specifically, what kind of help? You'll likely get a useful response if you have a problem with a specific part of your code.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Im having problems loading the file..im not really sure whats the code for that.
|
|
|
|
|
Here's[^] a tutorial on reading a text file. It should get you started.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
There's more than one way to skin a cat. Are you supposed to use C streams (e.g., FILE*), STL streams (e.g., ifstream), MFC (e.g., CFile), or what?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want to disable the task manager for a user group or the entire machine. it don't work if I disable it with HKLM...
Cannot do it in the regedit under HKCU because it only disable the task manager for the current user not a user group.
Cant someone help me please
|
|
|
|
|
|
consider
char *buff[] = { "sec1",
"sec2",
"sec3",
"sec4",
"sec5"
};
I want to pass this to the client side from my COM server
Server side code
VARIANT msg ; <br />
char **buff ; <br />
buff = new char*[5];<br />
for(int i=0;i<5;i++){<br />
buff[i] = new char[32];<br />
memset(buff[i],0,32);<br />
char str[5];<br />
sprintf(str,"Sec%d",i);<br />
strcpy(buff[i],str);<br />
}<br />
SAFEARRAY sArray ;<br />
sArray.cDims=2 ; <br />
sArray.fFeatures=FADF_AUTO ;<br />
sArray.cbElements=1;<br />
sArray.cLocks=0;<br />
sArray.rgsabound[0].cElements=5;<br />
sArray.rgsabound[0].lLbound = 0;<br />
<br />
sArray.rgsabound[1].cElements=32;<br />
sArray.rgsabound[1].lLbound = 0;<br />
sArray.pvData=(void *)(buff);<br />
msg.parray=&sArray ;<br />
msg.vt=VT_ARRAY | VT_UI1;<br />
_bstr_t t("Dummy");<br />
dummy->Fire_ProjectEepromMsgEvent(t,msg);<br />
for(i=0;i<5;i++){<br />
delete [] buff[i];<br />
buff[i]=0;<br />
}<br />
delete [] buff ;
On the client side the handler has the following signature
static _ATL_FUNC_INFO MsgInfo = { CC_STDCALL, VT_EMPTY,2,{VT_BSTR,VT_VARIANT }<br />
<br />
HRESULT CClient::HandleMsgEvent(BSTR Name,VARIANT data )<br />
{<br />
SAFEARRAY *sa ;<br />
sa = data.parray;<br />
<br />
}
For some reason I am unable to get this value in the client .
Please help
Engineering is the effort !
|
|
|
|