|
I need a notification of the "new hardware Found " dialog inside my applications . I tried to use Windows Hooks but fail to get the notification .
Am I doing the correct thing by expecting to get a notification for the same ?
This is what I tried in my MFC dialog application
void CWinHookEgDlg::OnButton1()
{
hookid = SetWindowsHookEx(WH_SHELL , CBTProc , NULL ,GetCurrentThreadId());
}
LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode < 0) // do not process message
return CallNextHookEx(hookid, nCode, wParam,
lParam);
if(nCode == 4)
return CallNextHookEx(hookid,nCode , wParam , lParam) ;
if(nCode == HSHELL_WINDOWCREATED)
{
HANDLE handle = ( HANDLE ) wParam;
// CBT_CREATEWND *wnd = (CBT_CREATEWND * ) lParam ;
}
return CallNextHookEx(hookid,nCode , wParam , lParam) ;
}
Engineering is the effort !
|
|
|
|
|
Have you looked at the WM_DEVICECHANGE message?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
WM_DEVICECHANGE will not work in my case as it only reports
DBT_DEVNODES_CHANGED and will not report a device arrival until the device is configured (after its drivers have been installed ) . this is for a USB device .
i somehow need a notification of the new hardware found Dialog .
Engineering is the effort !
|
|
|
|
|
What about DBT_DEVICEARRIVAL ?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DBT_DEVICEARRIVAL arrives when the device is fully configured . I will not get this until the drivers (inF / sys) files for the device have been loaded . But i need to intercept the Hardware Found dialog .
Engineering is the effort !
|
|
|
|
|
I think you might have to place all this code into a DLL, since I don't think you can hook the messages from another process if your hook code is within your EXE. It needs to be in a DLL so the code can be called by windows from the context of the other process. Then maybe you will see the messages you expect.
|
|
|
|
|
I have a DLL that exposes a Call to create the Hook
Here is a sample
HHOOK hookid = 0;
*LRESULT CALLBACK ShellProc(int nCode,WPARAM wParam,LPARAM lParam)*
{
TRACE("Shell message rcvd nCode = %d wParam = %d lParam=%d \n",nCode,wParam,lParam);
if(nCode==HSHELL_WINDOWCREATED )
{
int a =1;
}
return CallNextHookEx(hookid, nCode, wParam, lParam);
}
HOOKPROC proc = ShellProc;
HOOK_EXPORT WinHookRegister()
{
hookid = SetWindowsHookEx(WH_SHELL , proc , NULL ,GetCurrentThreadId());
}
I fail to get notifications of the new hardware found dialog . Am i missing some core concept here ?
Engineering is the effort !
|
|
|
|
|
You need to create a global hook to get notified of window creation in other processes.
hookid = SetWindowsHookEx(WH_SHELL, proc , hMyDllInstance, 0);
|
|
|
|
|
I tried the same and still no luck .
Is it expected that I get a notification for an new explorer window ?
Also I placed hookid in a shared data segment .
Any clues ?
Engineering is the effort !
|
|
|
|
|
Hi,
I want to use Windows Media player ActiveX in my MFC app. but I can't If you have its files please send me.
Thanks
cheers
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
dSolariuM wrote: but I can't...
Why not?
dSolariuM wrote: If you have its files please send me
Look for wmp.dll .
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Google is your friend. Microsoft wants you to use the WMP control, which is why they offer a WMP SDK. You just need to go and download it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
good morning, all
Is there a way to locate certain memory address in app during the debug? say, I wanna find out 0x00FE55A0 is using by who?
the reason is memory leak, I kinda know which class is leaking, but I couldn't see where exactly it is, there is FE5420 is using by m_pValid, but it got deleted when it close down. so the FE55A0 should be somwhere near by, but I never really find it.
thanks for your time!
|
|
|
|
|
Hello,
You can use the Visual Leak Detector[^] to trace down those pesky bugs and then eliminate them!
Good hunt!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
You can set a breakpoint on a memory address such that the application will break when the data at the specified address changes. Then it will show you what line of code just caused that change.
You can do this by using the breakpoints dialog and then go to the data tab and enter your address in the edit block.
|
|
|
|
|
Thanks for your reply.
I have problem setting them up, it has message box says "Cannot set the breakpoint when "0x00FE55A0" (length: 1)changed". not sure why, It should be the valid adreee, because it's the leak report says 1305 bytes leak from. and I could see the 0x00FE54D0 in somewhere....thank you!
|
|
|
|
|
I would go with the other suggestion then.
I am not sure why that error would come up. I tried it myself on my platform and I was able to set the break point.
Since you have an idea where/when the code is changing, you could try to watch it in the memory window. Just press the memory button on the debug toolbar (when you are in debug) and then type the address of the memory location that you want to watch. You can then step through the code until your address changes.
|
|
|
|
|
|
I need to check the status of a socket on my client application before sending data....I was wondering if there was a way to tell whether the socket was connected to the server at any given point. I know there is WSAGetLastError, but doesn't that have to wait for the framework to alert that there is an error first?
Thanks for your help.
|
|
|
|
|
You can use select() to check if the socket is writable. If it is you know that the connection is established and you can send data.
|
|
|
|
|
can this be done with CAsyncSocket?
What is the return value...I don't see it in the MSDN library
|
|
|
|
|
If you are using CAsyncSocket it has that virtual method OnSend() which is called when the socket is connected and able to send data. You can override it in your derived class and set a member variable which you can later test before calling Send(). You can still use select() because CAsyncSocket has a member m_hSocket which stores the socket's descriptor.
|
|
|
|
|
NYTSX wrote: can this be done with CAsyncSocket?
Try CAsyncSocket::GetPeerName(...) if you are connected it will return with peername and port otherwise call GetLastError for WSAENOTCONN macro
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
i have been playing around with NTFS reparse points and junctions. I finally found the tutorial by Mike Nordell and managed to make my application work. I can now build a junction to a path like "C:\mydirectory".
My question is concerned with building junctions over the network. If i specify "\\ServerXYZ\mydirectory" as the target path, the DeviceIOControl() routine returns unsuccessfully and GetLastError() returns 4392, which means that the parameter structure must have an error. Something is wrong with the way i'm specifying the path!
Is it possible to use the DeviceIOControl() routine setting a junction point that is located on another computer?
Thanks in advance...
|
|
|
|
|
I believe junctions are only possible on the local computer and on only on ntfs.
John
|
|
|
|