Click here to Skip to main content
15,915,093 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CArray Pin
brdavid7-Jun-04 11:41
brdavid7-Jun-04 11:41 
Generalselect a single file right click menu Pin
skoizumi291107-Jun-04 9:20
sussskoizumi291107-Jun-04 9:20 
GeneralRe: select a single file right click menu Pin
David Crow7-Jun-04 10:07
David Crow7-Jun-04 10:07 
GeneralRe: select a single file right click menu Pin
skoizumi291107-Jun-04 10:20
sussskoizumi291107-Jun-04 10:20 
GeneralRe: select a single file right click menu Pin
David Crow11-Jun-04 2:04
David Crow11-Jun-04 2:04 
GeneralRe: select a single file right click menu Pin
skoizumi2911013-Jun-04 15:34
sussskoizumi2911013-Jun-04 15:34 
GeneralRe: select a single file right click menu Pin
David Crow14-Jun-04 2:32
David Crow14-Jun-04 2:32 
GeneralCreateThread and Hooks Pin
Spiritofamerica7-Jun-04 8:29
Spiritofamerica7-Jun-04 8:29 
hello. I am trying to make a program that sets a system whide CBT hook withouth the use of

a dll that is attached to all the processes.I am using tyhe CreateThred function to

achieve this.I have already made a program that sets a system whide Keyboard hook and it

works so I know that this method has potential.

I do like this:

this is the main function:

[code]

WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
int c;
MSG msg;



Module = GetModuleHandle(NULL);
CBTlogfile="e:\\zama.txt";



DWORD CBTTID=0;

/* Already installed CBT we have */

if (dejaCBT)
{
MessageBox(GetDesktopWindow(),"CBT deja pornit","oaleao",MB_OK);
}

/* Create thread */


CBTCapThread = CreateThread(NULL,0, CBTThread,NULL, 0, &CBTTID);
if(CBTCapThread == NULL)
{
MessageBox(GetDesktopWindow(),"nu se poate sa se porneasca

CBTul","oaleao",MB_OK);
}






do
{
GetMessage(&msg,0,0,0);

TranslateMessage(&msg);
DispatchMessage(&msg);
}
while((msg.message!=WM_QUIT||msg.message!=WM_DESTROY||msg.message!=WM_CLOSE)!=0);
}

[/code]

This is my thread function:

[code]

DWORD WINAPI CBTThread(LPVOID param)
{

MSG msg;
int i;

/* We are now recieving from CBT*/
dejaCBT = 1;
MessageBox(GetDesktopWindow(),"am ajuns shi aici","sunt ciumeg",MB_OK);
/* Make sure we have a writable file ready */
fd = _open(keylogfile, _O_WRONLY|_O_CREAT|_O_EXCL, _S_IWRITE);
_close(fd);

/* Open the file again for appending */
if ((fd = _open(keylogfile, _O_WRONLY|_O_APPEND)) == -1)
{
MessageBox(GetDesktopWindow(),"nu pot sa deschid fishieru pt

append","oaleao",MB_OK);
return (1);
}

CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, Module, 0);

/* Loop forever and read from CBT */
while (Logging) {
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg,NULL,0,0);
DispatchMessage(&msg);
}
Sleep(1);
}

UnhookWindowsHookEx(CBT);
CBTCapThread = NULL;
_close(fd);
return (0);
}

[/code]

and this is my hook function:

[code]

LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{



if(code==HCBT_ACTIVATE)
{

//at the time there is nothing written here and still it doesn't work
//whatever I write here results are the same so let's just say this does nothing


}
return CallNextHookEx(CBT, code, wParam, lParam);
}

[/code]

Now, this program compiles and links flawlessly but when I run it it shut's down the

program it is first run in, for exemple windows explorer or Visual Studio and then it

doesn't do anything. it just sits there.

Please help. Also if you have a better way of doing this I am open to suggestions.
GeneralRe: CreateThread and Hooks Pin
David Crow7-Jun-04 8:59
David Crow7-Jun-04 8:59 
GeneralRe: CreateThread and Hooks Pin
Blake V. Miller7-Jun-04 15:34
Blake V. Miller7-Jun-04 15:34 
GeneralRe: CreateThread and Hooks Pin
Ryan Binns7-Jun-04 18:22
Ryan Binns7-Jun-04 18:22 
GeneralRe: CreateThread and Hooks Pin
Spiritofamerica7-Jun-04 19:48
Spiritofamerica7-Jun-04 19:48 
GeneralHtml Context Help in CView Pin
MikeF_7-Jun-04 7:06
MikeF_7-Jun-04 7:06 
GeneralExpert's opinions pz Pin
peachieboy7-Jun-04 7:06
peachieboy7-Jun-04 7:06 
GeneralRe: Expert's opinions pz Pin
David Crow7-Jun-04 7:14
David Crow7-Jun-04 7:14 
GeneralRe: Expert's opinions pz Pin
Henry miller7-Jun-04 10:00
Henry miller7-Jun-04 10:00 
GeneralClass Question Pin
Tom Wright7-Jun-04 7:01
Tom Wright7-Jun-04 7:01 
GeneralRe: Class Question Pin
David Crow7-Jun-04 7:11
David Crow7-Jun-04 7:11 
GeneralRe: Class Question Pin
Tom Wright7-Jun-04 7:25
Tom Wright7-Jun-04 7:25 
GeneralRe: Class Question Pin
David Crow7-Jun-04 7:43
David Crow7-Jun-04 7:43 
GeneralRe: Class Question Pin
jmkhael7-Jun-04 7:19
jmkhael7-Jun-04 7:19 
GeneralRe: Class Question Pin
Tom Wright7-Jun-04 7:54
Tom Wright7-Jun-04 7:54 
GeneralRe: Class Question Pin
David Crow7-Jun-04 9:04
David Crow7-Jun-04 9:04 
GeneralGetting what's been clicked on a listbox Pin
kfaday7-Jun-04 6:33
kfaday7-Jun-04 6:33 
GeneralRe: Getting what's been clicked on a listbox Pin
David Crow7-Jun-04 7:08
David Crow7-Jun-04 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.