I am using SetWindowsHookEx(...) to set WH_CBT hook, but the problem is that it never get called in system context. But only works on my application's main window. Don't know whats wrong? May be i am missing a simple thing that is causing the hook to install as system wide.
Here is the piece of code i am using to install the hook
//Installs the hook
//g_hInstDll is set to hInstance in DllMain() g_hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)Dll_HookProc,(HMODULE)g_hInstDll,0);
Is there anything specific i need to do in order to install hook system wide?
well static can be or is unnecessary but exporting the Hook proc doesn't make any sense, coz the calling application can only set the hook or remove the hook, hook proc will be used internally, so i think need not to export the hook proc.
Anyway thanks a lot for the reply, if you have some suggestion like setting up my project (i am using VC++ 6 may be i am not setting up the project), then it might be helpful.
if you can send me the basic code for your hook dll (Only hook setup code), it can solve the issue.
My basic code is the same as yours apart from the definition of the hook function.
The DLL will be loaded into the adderess space of all the other application running on your system, they will call the hook function so exporting it could make a difference. Try it, it will only take a minute to test it.
I have solved my problem, infact there was no problem at all. What i was trying to do was to debug a system wide installed hook in the VC debugger, which is not possible as such, so all the events i got were from the application i was dubugging in context with. So if i run the program (not debug it), it works fine. Thanks a lot for your patience and help. Now the real problem is still there, how to debug my program (system wide hook)?
I switch the default desktop to mine,and i produce taskbar myself.So i want to receive some message when system shell is ready to launch an application and to terminate an application.
how can i do? hook? or other?
Well according to MSDN (If its wrong it's Microsoft to blame )
HSHELL_WINDOWCREATED will be called when "A top-level, unowned window has been created. The window exists when the system calls a ShellProc function."
and HCBT_CREATEWND will be called when "A window is about to be created. The system calls the hook procedure before sending the WM_CREATE or WM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; the CreateWindow function returns NULL, but the WM_DESTROY message is not sent to the window. If the hook procedure returns zero, the window is created normally."
I've got a tiny helper application that I've built that creates text files on a network/shared drive.
I'm presently just using CStdioFile to create the text files.
The problem that I am running into is username/password authentication. I don't really know where to start for this and would appreciate some pointers in the right direction. The network/shared drive is "\\S-CPU1\c\the_folder". If I open up IE, and go to \\S-CPU1\c\the_folder ... the first time I try it, IE asks for the username/password. I enter it in, it goes there. I can then close out of IE and it "remembers" the username/password combination (or keeps me logged in to it, or whatever) until I physically LOG OUT or switch users. So, if I do that one time, I can then run my helper app, and it creates the files over on that shared folder without a problem.
The problem is I would like to automate this, so that I/the user does not have to first bring up IE and go through that process (and I don't want to physically MAP a drive to that folder). I would like to be able to run my app, and if it realizes that it needs a user/password to access that folder, it will go ahead and bring up a prompt asking the user for that information. After that point, it'll just roll through and do it's thing.
I've searched for several phrases in the articles on this site, but can not seem to find anything that is doing what I want. If someone could point me in the right direction, I would greatly appreciate it.
lpLocalName :Points to a null-terminated string that specifies the name of a local device to redirect, such as "F:" or "LPT1". The string is treated in a case-insensitive manner.
If the string is empty, or if lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device.