Home > Software engineering >  Vc6.0 compiler, why DllMain didn't perform in the Dll file
Vc6.0 compiler, why DllMain didn't perform in the Dll file

Time:09-24

First-time DLL and HOOK, copying other people's code from the Internet to try and DllMain doesn't seem to run but couldn't find where the problem, please teach
In the DLL project notepadbook. CPP:
 # include "StdAfx. H" 
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; Windows. H>
# define DLL_EXPORT extern "C" __declspec (dllexport)
HHOOK hooker.
The HWND notepadhandle;
BOOL handled;
LRESULT extern "C" __declspec (dllexport) CALLBACK HookProc (int nCode, WPARAM WPARAM, LPARAM LPARAM);
Char * ConvertInttoChar (int I);
BOOL APIENTRY DllMain (HANDLE hModule, dwords ul_reason_for_call LPVOID lpReserved) {
Printf (" Notepad Not Found. \ n ");
If (ul_reason_for_call==DLL_PROCESS_ATTACH) {
Handled=FALSE;
Notepadhandle=FindWindow (" Notepad ", NULL);
If (notepadhandle==NULL) {
Printf (" Notepad Not Found. \ n ");
Return TRUE;
}
Hooker=SetWindowsHookEx (WH_GETMESSAGE HookProc, (HINSTANCE) hModule, GetWindowThreadProcessId (notepadhandle, NULL));
If (hooker) {
Printf (" Hook Successfully. \ nHookID: % d \ n ", hooker);
}
The else {
Printf (" hooks Failed. \ nError: % d \ n ", GetLastError ());
Return TRUE;
}
PostMessage (notepadhandle WM_CLOSE, 0, 0);
}
Return TRUE;
}

LRESULT extern "C" __declspec (dllexport) CALLBACK HookProc (int nCode, WPARAM WPARAM, LPARAM LPARAM) {
If (nCode<0)
Return CallNextHookEx (hooker, nCode wParam, lParam);
MSG tagMSG *;
MSG=(tagMSG *) lParam;
If (nCode==HC_ACTION & amp; & (MSG - & gt; Message==WM_CLOSE)) {
If (handled==FALSE)
Handled=TRUE;
UnhookWindowsHookEx (hooker);
MSG - & gt; Message=WM_NULL;
Return CallNextHookEx (hooker, nCode wParam, (LPARAM) MSG);
}
Return CallNextHookEx (hooker, nCode wParam, lParam);
}


Hook hook in the project. The CPP:
 # include & lt; Stdio. H> 
# include & lt; Windows. H>
Int main () {
LoadLibrary (" C: \ \ notepadbook DLL ");
DWORD a=GetLastError ();
Printf (" % d ", a);
getchar(); Getchar//here is to prevent the program exits, if a program quickly exit, hook might have no effect
return 1;
}


  • Related