Preface:
There are two ways to get around a DLL in a VC:
The first is to define a def file through a module , put the function interface to be exported, and the DEF file provides the linker with information about the program's everywhere, attributes, and so on.
The second type: Add __declspec (dllexport) to the function declaration;
Example of the first method:
First build a DLL project named: Mousehook_dll:
In the HookLoad.h species declaration two interface functions:
#pragma oncebool Starthookev (HWND hwnd); void stophookev (void);
To implement a function about an interface in HookLoad.cpp:
BOOL Starthookev (hwnd hwnd) { G_hwnd =hwnd;g_keyboradhook = SetWindowsHookEx (Wh_keyboard, Keyboardproc, Getmodulehandlea ("Mousehook_dll"), 0); return FALSE;} void Stophookev (void) { UnhookWindowsHookEx (g_keyboradhook);}
In the Mousehook_dll.def:
LIBRARY mousehook_dllexportsstarthookev@2stophookev@3
This makes it possible toThe two function interfaces in Mousehook_dll.dll are exported;
Example of the second method:
First build a DLL project named: Mousehook_dll:
In the HookLoad.h species declaration two interface functions:
#pragma once#ifndef dll_implement#define dll_api _declspec (dllexport) #else # define dll_api _declspec ( dllexport) #endifBOOL DLL_API Starthookev (HWND hwnd); void Dll_api stophookev (void);
In the implementation of HookLoad.cpp:
BOOL DLL_API Starthookev (hwnd hwnd) { G_hwnd =hwnd;g_keyboradhook = SetWindowsHookEx (Wh_keyboard, Keyboardproc, Getmodulehandlea ("Mousehook_dll"), 0); return FALSE;} void Dll_api stophookev (void) { UnhookWindowsHookEx (g_keyboradhook);}
This allows you to export Starthookev and Stophookevtwo functions, this way does not require a module-defined. def file.
Hope is useful to everyone.
Two methods of DLL programming export interface