gamerfunkie
Erfahrenes Mitglied
Hallo,
ich habe folgenden Code um WindowsHooks in einer DLL zu benutzen:
dll.cpp:
dll.h
Das sieht aus als hätte er ein Problem mit dem SHARED.
Aber das braucht man ja ...
KAnn mir jemand helfen?
ich habe folgenden Code um WindowsHooks in einer DLL zu benutzen:
dll.cpp:
Code:
#include "dll.h"
// Globale Variablen
HHOOK g_hMouseHook SHARED = NULL; // Handle unseres Hooks (als "shared" Deklariert)
HINSTANCE g_hInst SHARED = NULL; // Handle der DLL selbst
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
g_hInst = hInst;
return TRUE;
}
DLLIMPORT BOOL InstallHook()
{
if(g_hMouseHook != NULL)
return TRUE;
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInst, 0);
if(g_hMouseHook == NULL)
return FALSE;
return TRUE;
}
DLLIMPORT BOOL UninstallHook()
{
if(g_hMouseHook != NULL)
{
UnhookWindowsHookEx(g_hMouseHook);
g_hMouseHook = NULL;
}
return TRUE;
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
if(nCode == HC_ACTION)
{
if ( (wParam == WM_LBUTTONDOWN)||(wParam == WM_NCLBUTTONDOWN) )
{
MOUSEHOOKSTRUCT *mhs = (MOUSEHOOKSTRUCT*)lParam;
HWND caller = FindWindow("Pipette", NULL);
if(caller != NULL)
PostMessage(caller, WM_USER+123, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
}
}
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
dll.h
Code:
#ifndef _DLL_H_
#define _DLL_H_
#include <windows.h>
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
// zur Deklaration von Variablen innerhalb eines "shared data segment"
#define SHARED __attribute__((section(".shr"), shared))
DLLIMPORT BOOL InstallHook();
DLLIMPORT BOOL UninstallHook();
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
#endif /* _DLL_H_ */
Code:
Wenn ich das ganze kompiliere kommt aber folgender Fehler:
1>------ Build started: Project: hook_dll, Configuration: Debug Win32 ------
1>Compiling...
1>dll.cpp
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C2146: syntax error : missing ';' before identifier '__attribute__'
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C2065: 'shared' : undeclared identifier
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C3861: 'section': identifier not found
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C2143: syntax error : missing ';' before '='
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : error C2513: 'int' : no variable declared before '='
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C2146: syntax error : missing ';' before identifier '__attribute__'
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C3861: 'section': identifier not found
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C2374: '__attribute__' : redefinition; multiple initialization
1> d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(5) : see declaration of '__attribute__'
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C2143: syntax error : missing ';' before '='
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(6) : error C2513: 'int' : no variable declared before '='
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(17) : error C2491: 'InstallHook' : definition of dllimport function not allowed
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(29) : error C2491: 'UninstallHook' : definition of dllimport function not allowed
1>d:\programmieren\c++\ws_hack\hook_dll\dll.cpp(48) : error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [8]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://d:\Programmieren\C++\ws_hack\hook_dll\Debug\BuildLog.htm"
1>hook_dll - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Das sieht aus als hätte er ein Problem mit dem SHARED.
Aber das braucht man ja ...
KAnn mir jemand helfen?