GiacomoLaw / Keylogger

A simple keylogger for Windows, Linux and Mac
https://simple-keylogger.github.io/
MIT License
2.09k stars 616 forks source link

Compiling klog_main.cpp errors #25

Closed wicked closed 7 years ago

wicked commented 7 years ago

I have tried compiling the source on Dev-C++ and Visual Studio 2016, resulting in various errors. Using latest on master windows.

On Dev-C++ 5.11

In function 'LRESULT HookCallback(int, WPARAM, LPARAM)':
31 [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
In function 'void SetHook()':
47 [Error] cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '2' to 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)'
114 [Error] '::main' must return 'int'

On Visual Studio 2015 Community Edition

argument of type "const wchar_t *" is incompatible with parameter of type "LPCSTR"  
'int MessageBoxA(HWND,LPCSTR,LPCSTR,UINT)': cannot convert argument 2 from 'const wchar_t [24]' to 'LPCSTR'
'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Very frustrating to compile and not simple anymore. The simplier choice would be version 2.0 but it takes up recurring 100% cpu usage.

GiacomoLaw commented 7 years ago

Apologies for this. Did you manage to compile it in the end?

wicked commented 7 years ago

No I couldn't compile any of the versions except version 2.0.

zochris commented 7 years ago

Try removing the L infront of the strings in MessageBox(...) (line 47) MessageBox(NULL, "Failed to install hook!", "Error", MB_ICONERROR);

In my case it would not compile without them, but your compiler may be different.

Edit: Technically you could just comment out that function, since it is only called incase the hook fails to install.

GiacomoLaw commented 7 years ago

@wicked Please do what @Z0ckerchris suggested, then report back.

@Z0ckerchris What do you use as a compiler? Thanks for helping out!

wicked commented 7 years ago

Using Dev-C++ 5.11, TDM-GCC 4.9.2 64-bit Release, removed L infront of the strings in MessageBox(...) (line 47)

MessageBox(NULL, "Failed to install hook!", "Error", MB_ICONERROR);

E:\Github\giacomolaw\windows\klog_main.cpp  In function 'LRESULT HookCallback(int, WPARAM, LPARAM)':
31  44  E:\Github\giacomolaw\windows\klog_main.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
E:\Github\giacomolaw\windows\klog_main.cpp  At global scope:
114 11  E:\Github\giacomolaw\windows\klog_main.cpp  [Error] '::main' must return 'int'

Using Visual Studio 2015, Visual C++ Empty Project, klog_main.cpp inside Source Files folder.

C4996   'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. 

Using fopen_s

C2660    'fopen_s': function does not take 2 arguments
62    a value of type "errno_t" cannot be assigned to an entity of type "FILE *"    
62    argument of type "char *" is incompatible with parameter of type "FILE **"    
62    too few arguments in function call
GiacomoLaw commented 7 years ago

@wicked

Can you see if the older Windows version worked?

https://github.com/GiacomoLaw/Keylogger/blob/c304e84f1636af453e42ba101501fb6988522b7b/windows/klog_invisible.cpp

Sorry for the issues

GiacomoLaw commented 7 years ago

Also, have you set whether the window is visible or not?

// defines whether the window is visible or not
// should be solved with makefile, not in this file
#define visible // (visible / invisible)
wicked commented 7 years ago

Using unmodified visible.

#define visible // (visible / invisible)

wicked commented 7 years ago

Using the older Windows version compiles, but with the following error on Dev-C++ 5.11, TDM-GCC 4.9.2 64-bit Release.

E:\Github\giacomolaw\windows\klog_main.cpp  In function 'int main()':
18  29  E:\Github\giacomolaw\windows\klog_main.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

klog_main.exe works well, but it on win10 it takes up recurring 50% cpu. On win7 it takes up 100%-97% cpu.

But on Visual Studio 2015, using the older version having similar problem on fopen and fopen_s.

GiacomoLaw commented 7 years ago

@wicked Ah, okay. Does the new version compile for you even though the errors and work?

Thanks, sorry for the issue and the questions.

wicked commented 7 years ago

The newest version doesn't compile. No problem @GiacomoLaw , just reporting issues so other users won't have any trouble compiling.

GiacomoLaw commented 7 years ago

Okay, thanks. Does anyone else have compilation issues? I don't get them on VS Community edition.

Thanks for reporting!

zochris commented 7 years ago

@GiacomoLaw I'm also using VS Community Edition

@wicked The fopen is just a warning, which VS ignores until you tell it to treat them as error. So it should compile if thats the only problem.

wicked commented 7 years ago

@GiacomoLaw is it possible to compile windows.cpp on linux gcc or g++?

GiacomoLaw commented 7 years ago

@wicked If they can compile C++, yes

wicked commented 7 years ago

Just compiled using the same version of Dev-C++, with two errors but compiles just fine. I may have messed up installation last time. Thanks @GiacomoLaw

In function 'LRESULT HookCallback(int, WPARAM, LPARAM)': [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

GiacomoLaw commented 7 years ago

No problem, glad to see it worked for you!