|
Well my question lies in how to specify the handle or the process id of one the processes i have created to shut it down or suspend it that particular process. Pliz give me a segment code if you have.
<br />
<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 />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
int menu(void)<br />
{<br />
int choice;<br />
<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t=");<br />
printf ("\n=\t 2: Suspend the process\t=");<br />
printf ("\n=\t 3: Resume the process\t=");
printf ("\n=\t 4: System Information\t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
<br />
printf("\nEnter choice (1-4): ");<br />
scanf("%d", &choice);<br />
return choice; <br />
}<br />
<br />
int main(int argc, char **argv) <br />
{<br />
<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess;<br />
HANDLE hThread = 0;<br />
DWORD NumberOfBytesRead = 0;<br />
DWORD baseaddr = 0;<br />
DWORD lpAddr = 0;<br />
PMEMORY_BASIC_INFORMATION lpBuffer = 0;<br />
DWORD dwLength = 200000;<br />
DWORD flNewProtect =0;<br />
PDWORD lpflOldProtect = 0;<br />
DWORD dwSize =0;<br />
LPCVOID lpBaseAddress = 0;<br />
DWORD nSize = 0;<br />
LPDWORD lpNumberOfBytesWritten = 0;<br />
TCHAR lpApplicationName[_MAX_PATH]="";<br />
SYSTEM_INFO sinfo;<br />
LPDWORD lpExitCode = 0;<br />
HWND hWnd = 0;<br />
DWORD dwProcessID = 0;<br />
UINT GetBase();<br />
LPCONTEXT lpContext = 0;<br />
int nRet = 0;<br />
unsigned int regnum = 0;<br />
<br />
<br />
char* ans="";<br />
int choice;<br />
<br />
while((choice = menu())!=5)<br />
{<br />
switch (choice)<br />
{<br />
<br />
case 1: <br />
<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());
<br />
CreateProcess(NULL, <br />
lpApplicationName, <br />
NULL, <br />
NULL, <br />
FALSE, <br />
CREATE_NEW_CONSOLE, <br />
NULL, <br />
NULL, <br />
&si, <br />
&pi <br />
); <br />
hProcess = pi.hProcess;<br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
printf("has started \n"); <br />
break;<br />
<br />
case 2:<br />
<br />
SuspendThread(pi.hThread);
<br />
printf("\nThe thread of ID: %d",pi.dwProcessId);<br />
printf(" has been suspended!\n");<br />
GetLastError();<br />
<br />
break;<br />
<br />
case 3:<br />
<br />
ResumeThread(pi.hThread);
GetLastError();<br />
break;<br />
<br />
case 4:<br />
printf("\nSystem Info: ",&sinfo);
break;<br />
<br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
<br />
return (0);<br />
}<br />
|
|
|
|
|
You code looks fine, your passing the handles of the process and thread from the PROCESS_INFORMATION structure that gets filled out when you call CreateProcess(). Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.
|
|
|
|
|
Mark Petrik Sosa wrote:
Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.
I don't have any idea about MFC arrays because i am using C unless if they can work in c code. But i have no idea with MFC or CList nor STL vector. You can give me a go ahead or segment code to handle it
-oam-
|
|
|
|
|
I’m going to save and load an XML-file in an SQL server. I really like suggestions on how to tackle the problem. My application is an MFC C++ project.
_____________________________
...and justice for all
APe
|
|
|
|
|
I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range.
Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters?
Or is there anyway to limit user to only type in integers?
|
|
|
|
|
Anonymous wrote:
Or is there anyway to limit user to only type in integers?
edit controls have a "number only" property. check for it in the resource editor / property viewre.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
One good way to parse your strings is to use _stscanf like so:
int a;
CString mytext = _T("123Hello");
if(_stscanf(mytext, _T("%d"), &a) != 1)
{
}
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|
|
U can use _ttoi() .
keep smilling.....b'coz smile is the shortest distance between people....
|
|
|
|
|
hey everyone
i have this project i need to do that uses setwindowshookex to set a message hook on a given process ID and for each keydown that that screen gets i replace the key with the char from a given text file
so like
the procces ID is notepad and the file is Omri.txt witch has
"Hello World" in it
so if i type in notepad "asdasdasd" it will type "Hello Wor"
anyway, thats the project
so what i did is make a DLL with the functions
open file
close file
get char
set hook
unhook
and getkeys
getkeys is the function windows calles when a key is pressed
so my problem is, when windows calles the function it cant access the opened file becuse it gets a difrent data field
i tryed puting the fstream var in shared memory but it didnt help
anyone here got any idea on how i shold do this?
If You Can't Beat Omri, Join Omri.
Four out of Five Dentists Recommend Omri.
Plop, Plop, Fizz, Fizz, Oh, What an Omri it is!
Silly Rabbit, Omri is for Kids.
Gee, Your Omri Smells Terrific.
The Coolest Omri on Ice.
At 29p an Omri, It's Not a Stress on Your Pocket.
Every Kiss Begins With Omri.
I am Stuck on Omri, 'Cause Omri's Stuck on Me.
Doing It Right Before Your Omri.
|
|
|
|
|
Hi, everybody,
I develop a browser helper object. I need to update the address in the address bar to a different address after user navigates to it. I tried to handle the NavigateComplete event but failed to make change to the address. Any change that makes to the address causes crash in IE. How can I solve this problem?
Thanks.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
|
Could you show me an example?
Thanks.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
hello friends
plz tell me the function to get size of file using filename.
|
|
|
|
|
How about GetFileSize() ?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
but in this i have to pass handle of file, i want to use name of file to get size.
or i can use handle of file if i get to know handle of file(is there any function from which i get handle of file)
bye
|
|
|
|
|
You can use the FindFirstFile API to get this info!
Don't try it, just do it!
|
|
|
|
|
smarty12 wrote:
is there any function from which i get handle of file
Yes, CreateFile() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Visual C++ 6.0, SP/5
I'm trying to use a binary resource in my executable, but I'm not having any luck.
I've looked all over MSDN and the web, and I've found nothing that gives clear instructions on how to do this.
Anyone got any hints/tips?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote:
I'm trying to use a binary resource in my executable, but I'm not having any luck.
If by binary you mean RT_RCTYPE , check out this article.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Found the following on CodeGuru. I adapted it to my needs and all is well.
<br />
For each file you want to include, add a line to resource.h as follows:<br />
<br />
#define IDR_MYFILE 103<br />
<br />
Remember to give each file a unique resource ID.<br />
<br />
Close all resource files and open your .rc file as "text." Add the line<br />
<br />
IDR_MYFILE RCDATA DISCARDABLE "res\\myfile.ext"<br />
<br />
A good place to add this line is immediately after the line which defines the IDR_MAINFRAME icon. If you haven't placed "myfile.ext" in your "res" subdirectory, adjust the path accordingly. Save the .rc file. Close it and open ResourceView. You should see something like this:<br />
<br />
There are more convenient ways of inserting a custom data resource, but they either embed the file as raw hex data in the .rc file, inflating it to several times the size of the included file, or neglect to define the resource ID in resource.h so that ResourceView shows the ID in inverted commas.<br />
<br />
To turn a resource back into a file, load it into memory using LoadResource(). This returns a BYTE pointer that CFile can use to write that file to disc.<br />
<br />
// Load the resource and save its total size.<br />
HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_MYFILE),RT_RCDATA); <br />
DWORD dwSize = SizeofResource(NULL , hRes);<br />
HGLOBAL MemoryHandle = LoadResource(NULL, hRes);<br />
if(MemoryHandle != NULL)<br />
{<br />
// LockResource returns a BYTE pointer to the raw data in<br />
// the resource<br />
BYTE *MemPtr = (BYTE *)LockResource(MemoryHandle);<br />
CFile file("C:\_my_path_to_file\myfile.ext", CFile::modeCreate | CFile::modeWrite);<br />
file.Write(MemoryHandle,dwSize);<br />
}<br />
FreeResource((HANDLE)hRes);<br />
<br />
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Your mod begs a CP article!
[edit]
Just saw David's article.
[/edit]
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi Bhavnani wrote:
Your mod begs a CP article!
Why, when I've already created one?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
I am using MFC with Explorer style. Basically the Left panel split has it's own class and own file. How would I get LeftView to get/pass information to? I have never actually done get/pass class info which isn't declare in the other one.
Would it be similar to
inline CClassDoc* CClassView::GetDocument() const
{ return reinterpret_cast<cclassdoc*>(m_pDocument); }
Thanks
|
|
|
|
|
You could do something like this, inside your frame that created the split.
CLeftView* CMyChildFrame::GetLeftPane()
{
CWnd* pWnd = m_wndSplitter.GetPane(0, 0);
CLeftView* pView = DYNAMIC_DOWNCAST(CLeftView, pWnd);
return pView;
}
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|