|
Preeti9 wrote:
Can you please suggest me if hooking is a good approach to detect when a window starts and when it closes ?
Yes I do think so. It is actually the only way to detect in the background if a window starts or closes.
~RaGE();
|
|
|
|
|
Thanks for the reply...
What if I use IsWindow function and then use while loop and at the end give sleep of like 1/2 a second....
Here is my program:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CTouchScreenAPI* pTouch;
// HWND hCalWin;
// DWORD SYNCRONIZE;
// DWORD procId;
HANDLE hProcess;
DWORD dwWaitResult;
pTouch = CTouchScreenAPI::Create();
if (pTouch)
{
if (pTouch->Init())
pTouch->Recalibrate();
else
MessageBox(NULL, "Created touchscreen interface OK, but Init() failed", "Info", MB_OK);
HWND hCalWin = ::FindWindow(pszABSPOINT_WND_CLASS_NAME, NULL);
//GetWindowThreadProcessId(hCalWin, &procId);
// retrieves the identifier of the thread that created this window.
// hProcess = OpenProcess(SYNCHRONIZE, FALSE, procId); //returns a handle to an existing process object
// Create top window class
//WinClass wc(ID_MAIN, hInstance,MainWndProc);
//hCalWin = wc.GetRunningWindow ();
// Is there a running instance of this program?
if (hCalWin !=0)
{
if( IsWindow(hCalWin) )
GetWindow(hCalWin, nCmdShow ); // handle of original window // relationship flag
//hCalWin->ShowWindow(SW_SHOW);
ShowWindow (hCalWin, SW_RESTORE);
while (1)
{
Sleep (1000);
}
return 0;
}
while (1)
{
dwWaitResult = MsgWaitForMultipleObjects(1, &hProcess, FALSE, 30*1000, QS_ALLINPUT);
if (dwWaitResult == WAIT_OBJECT_0 + 1)
{
MSG xMsg;
while (PeekMessage(&xMsg, NULL, 0, 0, PM_REMOVE))
{
if (xMsg.message == WM_QUIT)
return 1;
TranslateMessage(&xMsg);
DispatchMessage(&xMsg);
}// end of PeekMessage while loop.
int i=1;
while (i<10000)
{
i=i++;
}
}
else if (dwWaitResult == WAIT_TIMEOUT)
{
SendMessage(hCalWin, WM_CLOSE, 0, 0);
//TerminateProcess(hProcess, 0);
break;
}
else dwWaitResult == WAIT_OBJECT_0;
{
//Calibration process completed;
break;
}
}
}
else
{
MessageBox(NULL, "Unable to get pointer to Touchscreen interface", "Info", MB_OK);
}
return 0;
}
Help
Thanks
Preeti9
|
|
|
|
|
Also, I am getting an error in this....unresolved external....
Do I need to make this application a console one ?
Thanks
Preeti9
|
|
|
|
|
morning, all
I am looking at this code
CB_DBF_NTX* const p = OpenDbfNtxHelper( szDbfName, szIndexName, szIndexKey );
the P has value 0XCCCCCCC, if I do F10, it goes to
CB_DBF_NTX* pDbf = new CB_DBF_NTX( const_cast<char*>( szDbfName ) );
pDbf also has value 0xCCCCCCC.
does it mean p and pDbf BOTH need to be initialized or just pDbf?
thanks!
|
|
|
|
|
0xCCCCCCCC indicates an uninitialized local variable. If OpenDbfNtxHelper() fails, does it return a NULL pointer?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
thanks for your reply.
it will be returned void. and the OpenDbfNtxHelper will returned the valid adress.
so "0xCCCCCCCC indicates an uninitialized local variable", means oxCCCCCCC doesn't necessary cause moemory leak? thanks again!
|
|
|
|
|
valerie99 wrote:
so "0xCCCCCCCC indicates an uninitialized local variable", means oxCCCCCCC doesn't necessary cause moemory leak? thanks again!
never make that assumption.
every time you declare a pointer assign NULL to it; then you will be in better position to debug those kind of problems ( for example by using ASSERT )
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
In this case
valerie99 wrote:
CB_DBF_NTX* const p = OpenDbfNtxHelper( szDbfName, szIndexName, szIndexKey );
the function probably fails and returns no pointer, but NULL .
In this case
valerie99 wrote:
CB_DBF_NTX* pDbf = new CB_DBF_NTX( const_cast( szDbfName ) );
pDbf should be a pointer on a new CB_DBF_NTX object, but the init also fails and returns NULL .
So the fact that both p and pDbf have a value of 0xCCCCCCC only shows that both pointers have the value NULL and are unititialized, but not that they are linked together in any way.
So the anwser to
valerie99 wrote:
does it mean p and pDbf BOTH need to be initialized or just pDbf?
is "Yes, both p and pDbf need to be initialized".
Check why your function OpenDbfNtxHelper and why the constructor CB_DBF_NTX fail (this has probably to do with szDbfName , which is common to both of the statements).
~RaGE();
|
|
|
|
|
remove the const, and do it in multiple instructions ( just for test ).
CB_DBF_NTX* p = NULL;
p = OpenDbfNtxHelper( szDbfName, szIndexName, szIndexKey );
ASSERT( p );
If p after the call to OpenDbfNtxHelper is still 0xffffffff check that the input to the function are valid.
Also, ALWAYS check that the pointers are valid, (before and) after an allocation with ASSERT .
usually, new will not fail.
are you certain you are running in DEBUG mode ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
valerie99 wrote:
I am looking at this code
CB_DBF_NTX* const p = OpenDbfNtxHelper( szDbfName, szIndexName, szIndexKey );
the P has value 0XCCCCCCC, if I do F10, it goes to
If you look at the value of p , while the instruction pointer is at this line, then you are seeing the value before this line has executed ; the value of p at this time is irrelevant. You need to look at the value of p after pressing F10
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
|
char szDescription[200];
BOOL bValid;
bValid= AfxIsValidString(szDescription, 400);
//bValid is TRUE, shouldn't it be FALSE?????????/
thanks
|
|
|
|
|
McGahanFL wrote:
...shouldn't it be FALSE?????????/
What makes you think so? This function tests the memory address to ensure that it is contained entirely within the program’s memory space.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
DavidCrow wrote:
This function tests the memory address to ensure that it is contained entirely within the program’s memory space.
I thought this was AfxIsValidAddress() , or maybe does AfsIsValidString call AfxIsValidAddress() ?
Anyway, I can understand that defining a string of 200 chars, and getting true when checking if it is valid for 400 chars is a bit disturbing, especially since the MSDN states :
Nonzero if the specified pointer points to a string of the specified size; otherwise 0.
~RaGE();
|
|
|
|
|
I hate it when that happens. I was looking at AfxIsValidString() on my local MSDN, but then somehow started looking at AfxIsValidAddress() on MSDN online. Thanks.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thank you for your effort.
|
|
|
|
|
Thank you for verifing what seems reasonable.
|
|
|
|
|
Well, what is IN the szDescription, since you did not initialize it to anything?
There might be at least one NUL byte within the 400 or so off the stack, in which case the 'length' of the string was less than or equal to 400 bytes. So the test passed, this time...
I would not ever use AfxIsValidSring unless you had actually placed (or at least suspected one had been) a zero-terminated string into the variable first.
|
|
|
|
|
Thank you for your reply.
The -1 parm looks for NULL terminated, otherwise it is documnented that it verifies the length.
In any event, there is no test set of data that will fail this test other than a NULL pointer.
|
|
|
|
|
AfxIsValidString can only verify that the string is readable. If you happen to pass in garbage that contains no \0 character, then it will return an error. However, in your case, even if there were no \0 characters in the first 200 bytes, the memory past the end of the string is probably readable and thus will not generate an error.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
thank you, that is a reasonable explanation
|
|
|
|
|
Hi!
I just created a control with the dialog designer in Visual Studio (added dialog resource and set the Control property to true - adds DS_CONTROL flag). How do I make this control part of a window that I create with CreateWindow()?
Thanks already in advance!
|
|
|
|
|
Create a new instance of the control that you created and give the parent window of the control as the one that you created with the createwindow.
-prakash
|
|
|
|
|
That's exactly what I'm already doing. I create a new HWND with CreateDialogParam() and specify my parent window handle as hWndParent. Yet the newly created HWND is NULL and GetLastError() returns 0 ( ).
Here is an exerpt of the .rc file:
IDD_PVIEWERPANE DIALOGEX 0, 0, 443, 154<br />
STYLE DS_CONTROL | WS_CHILD | WS_VISIBLE<br />
FONT 8, "MS Shell Dlg", 400, 0, 0x1<br />
BEGIN<br />
GROUPBOX "Photo information",IDC_STATIC,7,7,429,140<br />
LTEXT "Title:",IDC_STATIC,13,32,44,8<br />
LTEXT "Static",IDC_TITLE,61,32,98,8<br />
LTEXT "Time taken:",IDC_STATIC,191,32,62,8<br />
LTEXT "Static",IDC_TIMET,255,32,118,8<br />
LTEXT "Path:",IDC_STATIC,13,47,34,8<br />
LTEXT "Static",IDC_PATH,55,47,381,8,SS_ENDELLIPSIS<br />
LTEXT "Dimensions:",IDC_STATIC,13,61,67,8<br />
LTEXT "Static",IDC_DIMENSIONS,81,61,120,8<br />
LTEXT "Zoom factor:",IDC_STATIC,228,61,79,8<br />
LTEXT "Static",IDC_ZOOMF,315,61,98,8<br />
CONTROL "",IDC_RICHEDIT21,"RichEdit20A",ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP,7,78,429,69,WS_EX_CLIENTEDGE<br />
PUSHBUTTON "< Previous",IDC_BPREV,13,17,79,14<br />
PUSHBUTTON "Next >",IDC_BNEXT,357,17,79,14<br />
END<br />
<br />
...<br />
<br />
IDD_PVIEWERPANE, DIALOG<br />
BEGIN<br />
LEFTMARGIN, 7<br />
RIGHTMARGIN, 436<br />
VERTGUIDE, 13<br />
TOPMARGIN, 7<br />
BOTTOMMARGIN, 147<br />
HORZGUIDE, 17<br />
HORZGUIDE, 31<br />
HORZGUIDE, 40<br />
END<br />
...
... and here's my code:
HWnd = CreateWindow(C_PHOTOVIEWER, "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, PANEWIDTH, 500, NULL, NULL, hInst, NULL);<br />
SetWindowLongPtr(HWnd, GWLP_USERDATA, (LONG_PTR) this);<br />
hPane = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_PVIEWERPANE), HWnd, this->DlgProc, (LPARAM) this);<br />
ShowWindow(HWnd, SW_SHOW);<br />
|
|
|
|
|
I began to read serial communication in Win32 from MSDN. but it confused me.
It dispatched me to synchronization, threads, multithreading, ... ???!!!
the first problem I should ask is what is a thread? what is difference between thread and functions?
and can you give an example of what is the benefit of multithreading?
|
|
|
|
|