|
VC6.0
Hello,
i have a question, how can i terminate a process from an another process? Ich my Situation i want start program b.exe from a.exe. But b.exe should start once a time! I do it with that:
1) First start b.exe:
PROCESS_INFORMATION ProcInfo;
STARTUPINFO startupInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
CreateProcess(NULL, // lpApplicationName
"C:\\b.exe", // lpCommandLine
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
NULL, // bInheritHandles
NULL, // dwCreationFlags
NULL, // lpEnvironment
NULL, // lpCurrentDirectory
&startupInfo, // lpStartupInfo
ProcInfo); // lpProcessInformation
2) Second i check, wheter program is still activ
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pProcInfo->dwProcessId);
if (handle!=NULL)
{
... if programm b.exe activ terminate b.exe ...
}
else
{
... start b.exe ...
}
3) If programm b.exe active i terminate it and restart it
I do it with this code:
TerminateProcess(m_pProcInfo->hProcess, 0);
Now i got back to step 1:
This works fine in w2k, but in xp step 2 doesn't work. The handle is always not NULL.
What is wrong? Give's a better way to do that?
Thanks
Chris
Student
|
|
|
|
|
From the top of my head: maybe instead of PROCESS_ALL_ACCESS you should use PROCESS_TERMINATE?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello Tomasz,
thank you for your tip. I changed PROCESS_ALL_ACCESS to PROCESS_TERMINATE in OpenProcess(...). But i have the same effect as before.
When i alredy had terminated the programm b.exe and it doesn't exist in the tast-manager. I do step 2 and the handle is alawy not NULL. But i see this effect only in XP. W2k show me NULL and I can start b.exe with createprocess.
What do i wrong!
Thanks
Chris
ceuba@gmx.net
Student
|
|
|
|
|
ceuba wrote:
When i alredy had terminated the programm b.exe and it doesn't exist in the tast-manager. I do step 2 and the handle is alawy not NULL. But i see this effect only in XP. W2k show me NULL and I can start b.exe with createprocess.
The process ID may be reused, so maybe you're getting the handle for other process? Anyway, since you're calling CreateProcess yourself, why don't you use another thread and WaitForSingleObject?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I need to convert CString string to unsigned long. Exammple
Need CString strPacket = "FFFFF400" to unsigned long
Also any idea how to add a value to strPacket. What I mean is
strPacket = "FFFFF400" + "4" = "FFFFF404";
|
|
|
|
|
sscanf((LPCTSTR)strPacket, "%ul", &myulVar);
simple, rustik.... assuming that your string is a valid unsigned long value...
TOXCCT >>> GEII power
|
|
|
|
|
Caoimh wrote:
I need to convert CString string to unsigned long.
Use strtoul() for this.
Caoimh wrote:
Also any idea how to add a value to strPacket. What I mean is
strPacket = "FFFFF400" + "4" = "FFFFF404";
Assuming that strPacket is a CString object, this is perfectly valid:
strPacket = "FFFFF400";
strPacket += "4";
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
(cough)
Actually, I think they meant
unsigned long x;
unsigned long y;
x = strtoul(str,NULL,16);
y = strtoul(str2, NULL,16);
strPacket.Format("%08lx", x+y);
Steve S
|
|
|
|
|
I usually use
<pre lang="c++"> _wtol(cstringvar)
- Michael Haephrati מיכאל האפרתי
|
|
|
|
|
I'm thinking about porting a time-critical code from VC++6.0 to VC++7.0, did anyone make something like that and could observe peformance gains ? Probably I'll waste some time doing it...
Tx for any information
GuimaSun
www.nexsun.com.br
|
|
|
|
|
You could theoretically get some perf boost from Whole Program Optimization introduced in 7.0. Of course, it greatly depends on specifics of your code. Did you actually profile it, anyway?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I am getting an value like this
a+(b<<9)+(c<<17)=value
how can i recalculate a,b and c if i only have the value c is a fix value (512) and can also be obtained by
c= value>>17
how can i resolve a and b
|
|
|
|
|
Mathematically not possible to solve a equation with 3 unknown and one equation.
You have to assume any three values and find the other.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
<br />
a = value & 0x1FF;<br />
b = (value >> 9) & 0x1FF;<br />
where I assume, that a and b are from interval (0, 511)
Robert-Antonio
"CRAY is the only computer, which runs an endless loop in just 4 hours"
|
|
|
|
|
perfect stranger wrote:
how can i recalculate a,b and c if i only have the value c is a fix value (512)...
If you already know the value of 'c', then there is no need to calculate its value. You are simply left with a problem of solving an equation with two unknowns. There are plenty of algebra/high school math sites that show how to do this.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi All,
Iam trying to Draw a Bitmap to screen using the DeviceContext function StretchBlt.
//These are my parameters in LogicalUnits
int xCord;
int yCord,
int bitmapwidth,bitmapheight
StretchBlt(xCord,ycord,bitmapwidth,bitmapheight,...
I want the first 4 parameters of the StretchBlt to be converted to deviceCo-ordinates(Pixels).How Could I do that.
I found the function "LPtoDp" in Msdn,But this function doesnt return me anything to pass the converted valuesto the stretchBlt function.
Help!
Thanks...
|
|
|
|
|
POINT pt = {10, 20};
LPtoDP(&pt, 1);
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
|
I am a novice in VC++ ( MFC) I need to build an application which allows me to store my visual represention craeted in the view and also retrieve it at alater point of time. Basically similar to opening, saving and closing a file as done in any windows application. I don't know which topic to look into and how to do the same.
Please can somebody guide me.....
Thanks for the same.
|
|
|
|
|
I am a novice in VC++ ( MFC) I need to build an application which allows me to store my visual represention craeted in the view and also retrieve it at alater point of time. Basically similar to opening, saving and closing a file as done in any windows application. I don't know which topic to look into and how to do the same.
Please can somebody guide me.....
Thanks for the same.
Even the word impossible says I aM POSSIBLE
|
|
|
|
|
Sounds like you need to read a chapter on serialization. Go through MSDN's Scribble tutorial.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
How To Copy the Desktop image to BMP file???
I'd appreshiate any help and especially for the clear WinAPI code without using any classes.
|
|
|
|
|
GetScreenDC, CreateCompatibleDC, CreateDIBSection, [edit] SelectObject the DIB into the compatible DC [/edit], BitBlt from the screen DC to your compatible DC, then work out how to fill in the BITMAPFILEHEADER and BITMAPINFOHEADER structures.
See Charles Petzold's Programming Windows, Fifth Edition for information on working with bitmaps.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I stell can't understand some moments.
I do this and get nothing, What am i doing wrong?:
char* data = new char[GetSystemMetrics(SM_CXSCREEN)*GetSystemMetrics(SM_CYSCREEN)*3];
BITMAPINFO BitmapInfo;
BITMAPFILEHEADER BFH;
memset(&BFH,0,sizeof(BITMAPFILEHEADER));
BFH.bfType = 'MB';
BFH.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+GetSystemMetrics(SM_CXSCREEN)*GetSystemMetrics(SM_CYSCREEN)*3;
BFH.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
BITMAPINFOHEADER bitmapinfoheader;
bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfoheader.biWidth = GetSystemMetrics(SM_CXSCREEN);
bitmapinfoheader.biHeight = GetSystemMetrics(SM_CYSCREEN);
bitmapinfoheader.biPlanes = bitmapinfoheader.biBitCount = 24;
bitmapinfoheader.biCompression = 0;
bitmapinfoheader.biSizeImage = GetSystemMetrics(SM_CXSCREEN)*GetSystemMetrics(SM_CYSCREEN)*3;
bitmapinfoheader.biXPelsPerMeter = bitmapinfoheader.biYPelsPerMeter = bitmapinfoheader.biClrUsed =bitmapinfoheader.biClrImportant = 0;
HDC hDC = ::GetDC(NULL);
HDC hCompatibleDC = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap =::CreateDIBSection(hCompatibleDC,&BitmapInfo,DIB_RGB_COLORS,(void**)data,NULL,NULL);
BitBlt(hDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),hCompatibleDC,0,0,SRCCOPY);
CFile file;
file.Open("New.bmp",CFile::modeWrite|CFile::modeCreate);
file.Write(&BFH,sizeof(BITMAPFILEHEADER));
file.Write(&bitmapinfoheader,sizeof(BITMAPINFOHEADER));
RGBQUAD rgb;
file.Write(&rgb,sizeof(RGBQUAD));
file.Write(data,GetSystemMetrics(SM_CXSCREEN)*GetSystemMetrics(SM_CYSCREEN)*3);
file.Close();
|
|
|
|
|
Firstly I'd pull out every use of GetSystemMetrics(SM_CXSCREEN) and GSM(SM_CYSCREEN) and store them in variables instead - this will make the code clearer.
The value of a two-character literal is undefined. Set BFH.bfType to 0x4D42.
The documentation for BITMAPINFOHEADER indicates that biPlanes should be set to 1. I think you can get away with setting biClrUsed to zero; if you do this, you should not write any RGBQUAD structures after the BITMAPINFOHEADER.
biCompression should be set to BI_RGB. You should probably set biXPelsPerMeter and biYPelsPerMeter: you can either compute them from GetDeviceCaps( hDC, LOGPIXELSX ) or simply write in the appropriate value for 96dpi: 3780.
A line of a DIB is always an exact multiple of 4 bytes long. If the number of bytes per pixel multiplied by the number of pixels per line is not a multiple of 4, you must round up to the next multiple. This also affects your original block allocation.
I seem to remember that there are also some odd alignment requirements for a BMP file, but I can't remember them off-hand.
If other programs render your bitmap upside down, you may need to set biHeight to a negative value (e.g. -480 for a 480-pixel high image).
If none of this helps, step through the code and see which line fails, and what the Windows error value is.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|