我是新來的Windows編程(我知道一點關於c和c + +)。我正在試圖創建Windows DLL註冊windows鍵鉤鍵盤。我用MinGW(因爲我不想使用Visual Studio)使用Eclipse CDT來創建dll.I能夠創建以下程序(copied from here)的dll,但是當我嘗試從另一個程序加載它,它掛起沒有任何錯誤信息。需要幫助創建窗口dll
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include<windef.h>
#ifdef __MINGW32__
# define __in
# define __in_z
# define __in_z_opt
#endif
#define WIN32_LEAN_AND_MEAN
#include <d3d9.h>
HINSTANCE hinst;
HHOOK hhk;
LRESULT CALLBACK wireKeyboardProc(int code,WPARAM wParam,LPARAM lParam) {
FILE * fileLog = fopen("C:\\try.txt", "a+");
fprintf(fileLog,"OK");
CallNextHookEx(hhk,code,wParam,lParam);
fclose(fileLog);
return 0;
}
extern "C" __declspec(dllexport) void install() {
hhk = SetWindowsHookEx(WH_KEYBOARD, wireKeyboardProc, hinst, NULL);
}
extern "C" __declspec(dllexport) void uninstall() {
UnhookWindowsHookEx(hhk);
}
BOOL WINAPI DllMain( __in HINSTANCE hinstDLL,
__in DWORD fdwReason,
__in LPVOID lpvReserved
) {
hinst = hinstDLL;
return TRUE;
}
這是MinGW的問題嗎?任何幫助表示讚賞。謝謝。 下面是加載dll的測試程序。
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include<windef.h>
#define WIN32_LEAN_AND_MEAN
#include <d3d9.h>
int main()
{
HINSTANCE hinst = LoadLibrary("libTestHook.dll");
if (hinst == NULL)
{
printf("null hinst");
}
typedef void (*Install)();
typedef void (*Uninstall)();
Install install = (Install) GetProcAddress(hinst, "install");
Uninstall uninstall = (Uninstall) GetProcAddress(hinst, "uninstall");
install();
int foo;
std::cin >> foo;
uninstall();
return 0;
}
libTestHook.dll是創建DLL
我加入節目 – hnm 2011-04-10 08:51:38