|
In the vein of my CreateProcess() question in a parallel thread today I'm facing the problem
of letting the called subprocess doing some tidying up work before really following the termination signal.
Would that be possible? Or would it be better to send the process a different signal
(in UNIX that would have been a USR signal) and wait a time period for receiving the termination event and if that does not occur in time, then terminating it brute force?
Is the TerminateProcess an unconditional signal that cannot be intercepted by the process
under termination itself? Hope I expressed myself clearly enough
--
Christoph
|
|
|
|
|
Have you control about the subprocess?
If so why not use named events?
HANDLE hEvent = CreateEvent(NULL, true, false, "some_silly_name_you_can_refer_to_in_your_processes");
You can use this in your service and your subprocess.
If an event with this name does not exists in the system it will be created, if
it exists, you get the same handle as the first application who called CreateEvent with this
name. Now you can interact with your subprocesses.
Greetings
Covean
|
|
|
|
|
Covean wrote: Have you control about the subprocess?
If so why not use named events?
HANDLE hEvent = CreateEvent(NULL, true, false, "some_silly_name_you_can_refer_to_in_your_processes");
Thanks. Yes, I have control of the process' source code. Will try something in that vein.
--
Christoph
|
|
|
|
|
In general I do not post my own code but doing some IPC-stuff is not such a secret.
Here is a dll I wrote to communicate between 2 apps.
The one site calls
GetFaceDetectionStatusChangedEventHandle(),
CreateFaceDetectionStatusMapFile(),
and GetCurrentFaceDetectionStatus() and closes it if it doesnt need it anymore.
the other site calls SetFaceDetectionStatus() instead of GetCurrentFaceDetectionStatus().
This code shows how to wait in one app for another and how to transfer
data from one app to the other by using shared memory.
Note: I left the german comments in for you.
------------------------------------------------------------------------------------------
fdinterop.h
#pragma once
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_WINDOWS 0x0410
#define _WIN32_IE 0x0600
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
TCHAR szEventName[]=TEXT("FDInteropDllFaceDetectionStatusChanged");
TCHAR szMapFileName[]=TEXT("FDInterOpDLLFaceDetectionMapFile");
typedef struct _fdsObject
{
DWORD dwTimeStamp;
BOOL bFaceDetected;
INT nX1;
INT nY1;
INT nX2;
INT nY2;
} FDS_OBJECT, *PFDS_OBJECT, NEAR *NPFDS_OBJECT, FAR *LPFDS_OBJECT;
HANDLE _declspec(dllexport) __stdcall GetFaceDetectionStatusChangedEventHandle();
void _declspec(dllexport) __stdcall CloseFaceDetectionStatusChangedEventHandle(HANDLE hFaceDetectionStatusChangedEventHandle);
HANDLE _declspec(dllexport) __stdcall CreateFaceDetectionStatusMapFile();
void _declspec(dllexport) __stdcall CloseFaceDetectionStatusMapFile(HANDLE hFaceDetectionStatusMapFile);
BOOL _declspec(dllexport) __stdcall GetCurrentFaceDetectionStatus(HANDLE hFaceDetectionStatusMapFile, LPFDS_OBJECT pFDSObject);
void _declspec(dllexport) __stdcall SetFaceDetectionStatus(INT bFaceDetected, INT nX1, INT nY1, INT nX2, INT nY2);
------------------------------------------------------------------------------------------
fdinterop.c
#include "fdinterop.h"
BOOL __stdcall DllMain(HANDLE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
switch(dwReasonForCall)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
HANDLE __stdcall GetFaceDetectionStatusChangedEventHandle()
{
return CreateEvent(NULL, TRUE, FALSE, szEventName);
}
void __stdcall CloseFaceDetectionStatusChangedEventHandle(HANDLE hFaceDetectionStatusChangedEventHandle)
{
CloseHandle(hFaceDetectionStatusChangedEventHandle);
}
HANDLE __stdcall CreateFaceDetectionStatusMapFile()
{
return CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(FDS_OBJECT), szMapFileName);
}
void __stdcall CloseFaceDetectionStatusMapFile(HANDLE hFaceDetectionStatusMapFile)
{
CloseHandle(hFaceDetectionStatusMapFile);
}
BOOL __stdcall GetCurrentFaceDetectionStatus(HANDLE hFaceDetectionStatusMapFile, LPFDS_OBJECT pFDSObject)
{
LPFDS_OBJECT pFDSBuffer = NULL;
if((hFaceDetectionStatusMapFile == NULL) || (pFDSObject == NULL))
return FALSE;
pFDSBuffer = (LPFDS_OBJECT)MapViewOfFile(hFaceDetectionStatusMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(FDS_OBJECT));
if(pFDSBuffer == NULL)
return FALSE;
memcpy(pFDSObject, pFDSBuffer, sizeof(FDS_OBJECT));
UnmapViewOfFile(pFDSBuffer);
return TRUE;
}
void __stdcall SetFaceDetectionStatus(INT bFaceDetected, INT nX1, INT nY1, INT nX2, INT nY2)
{
FDS_OBJECT fdsObject;
LPFDS_OBJECT pFDSObject;
HANDLE hFaceDetectionStatusMapFile = NULL;
HANDLE hFaceDetectionStatusChangedEvent = NULL;
fdsObject.dwTimeStamp = GetTickCount();
fdsObject.bFaceDetected = (bFaceDetected==0) ? FALSE : TRUE;
fdsObject.nX1 = nX1;
fdsObject.nY1 = nY1;
fdsObject.nX2 = nX2;
fdsObject.nY2 = nY2;
hFaceDetectionStatusMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, szMapFileName);
if (hFaceDetectionStatusMapFile != NULL)
{
pFDSObject = MapViewOfFile(hFaceDetectionStatusMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(FDS_OBJECT));
if(pFDSObject != NULL)
{
memcpy(pFDSObject, &fdsObject, sizeof(FDS_OBJECT));
UnmapViewOfFile(pFDSObject);
CloseHandle(hFaceDetectionStatusMapFile);
}
}
hFaceDetectionStatusChangedEvent = GetFaceDetectionStatusChangedEventHandle();
SetEvent(hFaceDetectionStatusChangedEvent);
CloseFaceDetectionStatusChangedEventHandle(hFaceDetectionStatusChangedEvent);
} ;
I hope this gives you a clue how to do this.
But be aware of the data transfer between the two apps, cause I do not lock the memory
for writing or reading (I didn't needed it, functions were only call in cylce of 40 ms).
Greetings
Covean
|
|
|
|
|
Thanks a lot. I will look into it.
--
Christoph
|
|
|
|
|
Hi,
I want a notification for the usb device connection and disconnection in vc++ DLL.
I am implementing J2534 DLL in that i want a notification for usb device connect and disconnect.
I read about WM_DEVICECHANGE notification and RegisterDeviceNotification.
but RegisterDeviceNotification will give error "undeclared identifier".
and both will use window handle.
if i use these functions in my DLL i wont get the window handle.
so anybody give me the solution to implement the same.
and one more thing i have found one example code to achieve the same.
this code uses AtUsbHid.dll to detect usb connect and removal.
but to use these dll functions also i need to pass window handle which is not possible in DLL.so if anybody knows the solution to use same dll without window handle.
Thanks in advance
|
|
|
|
|
Why can't you just create a hidden window that can receive the WM_DEVICECHANGE notification?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Its a really bad practice to open hidden windows in dlls, cause you never can use these dlls
in services on vista or later.
Greetings
Covean
|
|
|
|
|
If you are creating a service, then you can use RegisterDeviceNotification() to receive notification.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yes you are right about this Register function, I only meant, not to open a hidden window
in a dll if you do not know if it can be used later in the context of a service.
Greetings
Covean
|
|
|
|
|
yes u r right creating hidden window in a dll is a bad habit.
but what ever i am implementing its not a service also.
so please suggest me some alternative solution to achieve this.
i found hid dll and i am checking that now.
anybody have idea about HID dll.can i use this dll to implement my reuirement.
|
|
|
|
|
So if you are sure not to use it in service the easiest way really will be to open a hidden window.
If you wanna try your luck with the hid.dll, then I would be pleased to hear how you solved the problem,
cause this is an interesting issue.
Greetings
Covean
|
|
|
|
|
still i have check with HID.dll i am not sure.
meanwhile if anybody suggest some other way to solve this problem then i will be very thank full to them.
|
|
|
|
|
Hi
How can I identify the version of WTL i am having in my machine.
There are major changes done in AtlDlgs.h between WTL 7.1 version and WTL 7.5 version.
modified on Wednesday, November 11, 2009 9:48 AM
|
|
|
|
|
Hi,
I believe the WTL version is defined in the atlapp.h header as _WTL_VER
Best Wishes,
-David Delaune
|
|
|
|
|
/* Program for multiplication of two matrices */
# include <stdio.h>
# include <conio.h>
# define ROW 3
# define COL 3
void main()
{
int mat1[ROW][COL],mat2[ROW][COL],mat3[ROW][COL];
int i,j,k;
clrscr();
printf("\n Enter matrix mat1(%dx%d)row-wise:\n ",ROW,COL);
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
{
scanf("%d",&mat1[i][j]);
}
printf("\n Matrix 1 is %d \n",mat1[i][j]);
printf("\n Enter matrix mat2(%dx%d)row-wise:\n ",ROW,COL);
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
scanf("%d",&mat2[i][j]);
}
printf("\n Matrix 2 is %d \n",mat2[i][j]);
}
//Multiplication
for(i=0;i<ROW;i++)
for(j=0;j<COL;j++)
{
mat3[i][j]=0;
for(k=0;k<COL;k++)
mat3[i][j]+=mat3[i][j]+mat1[i][k] * mat2[k][j];
}
// End of multiplication
printf("\n The Resultant matrix mat3 is: \n");
for(i=0;i<ROW;i++)
for(j=0;j<COL;j++)
printf("\n %d",mat3[i][j]);
printf("\n");
getch();
}
main yeh program ka code run kara raha hoo par ismein kuch logical error hai
jo main remove nahi kar paa raha hoo.plzzzzzzzz help me..
|
|
|
|
|
ok, what's the question ?
you have compilation errors ? logic errors ?
did you run this with the debugger ?
did you try using a pen and paper to simulate your algorithm ?
This signature was proudly tested on animals.
|
|
|
|
|
I think you gotta check your for loop bracing.
Please put your question in English.
Also a bit prettier printing would help yourself in understanding your code.
You might want to put it in a code block after running it through "indent".
--
Christoph
|
|
|
|
|
|
I write some code, but can't get result.
Bitmap* pBitmap = new Bitmap(L"bitmap1.bmp");<br />
<br />
TextureBrush* pTextureBrush = new TextureBrush(pBitmap);<br />
<br />
graphics.FillRectangle(pTextureBrush, 50,300,200,80);
or
CString str = _T("N00.bmp");
int strLen = 0;
strLen =str.GetLength();
WCHAR* ch = new WCHAR[strLen];
wcscpy(ch, CT2CW(str));
Bitmap* pBitmap = new Bitmap(ch);
TextureBrush* pTextureBrush = new TextureBrush(pBitmap);
graphics.FillRectangle(pTextureBrush, 50,300,200,80);
|
|
|
|
|
kk_Kevin wrote: ...but can't get result.
Why not? What is failing? What does FillRectangle() return?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I also don't know why, and it can not show nothing?
mybe the "bitmap::FromResource(..)" is wrong, and I do not know.
I try any way I can think out to resolve it, but, I can't
|
|
|
|
|
kk_Kevin wrote: mybe the "bitmap::FromResource(..)" is wrong, and I do not know.
Does it return a non-NULL value?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
first, the bmp pic "**.bmp" is in the res file of my project.
second, if I use Bitmap* pBitmap = Bitmap::FromFile(..); , the rectange can be filled. and use Bitmap::FromResource(..) can not.
thrid, I use ::FindResource(..) , but can not find the bmp
hInstResource = AfxGetApp()->m_hInstance;
src = _T("N00.bmp");
int strLen = 0;
strLen =src.GetLength();
WCHAR* ch = new WCHAR[strLen];
wcscpy(ch, CT2CW(src));
Bitmap* pBitmap = Bitmap::FromResource(hInstResource , CT2CW(src));
graphics.DrawImage(pBitmap, 75,35);
TextureBrush* pTextureBrush = new TextureBrush(pBitmap, WrapModeTileFlipY);
graphics.FillRectangle(pTextureBrush, 50,300,200,80);
Color m_penColor(233,100,54);
Pen pen1(m_penColor, 1);
graphics.DrawRectangle(&pen1, 50,300,200,80);
modified on Thursday, November 12, 2009 6:59 AM
|
|
|
|
|
kk_Kevin wrote: thrid, I use ::FindResource(..), but can not find the bmp
What does it return?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|