C # uses the export function in the dynamic link library. It can only be displayed and called in the program according to the dllatri.pdf, and cannot be dynamically loaded in the running stage, however, we can use the loadlibrary and freelibrary of Win32 API to achieve the goal. The problem is that the address of the export function obtained based on the getprocaddress () function cannot be used in C, many methods on the Internet use function call stack operations to operate in C. in fact, if the export function does not return a value, you can use another API function to dynamically bind the DLL Library:
Lresult callwindowproc (wndproc lpprevwndfunc,
Hwnd,
Uint MSG,
Wparam,
Lparam
);
If the exported function does not return any values, you can directly call callwindowproc (functionname,). If you need to pass a simple parameter to the exported function, you can also customize a message, encapsulate real parameters with messages. [Dllimport ("Kernel32")]
Public extern static int loadlibrary (string lplibfilename); [dllimport ("Kernel32")]
Public extern static bool freelibrary (INT hlibmodule); [dllimport ("Kernel32", charset = charset. ANSI)]
Public extern static int getprocaddress (INT hmodule, string lpprocname); [dllimport ("USER32", entrypoint = "callwindowproc")]
Public static extern int callwindowproc (INT lpprevwndfunc, int hwnd, int MSG, int wparam, int lparam); Private void button#click (Object sender, system. eventargs E)
{
Int hmod = loadlibrary ("*****. dll ");
Int pfname = getprocaddress (hmod ,"*****");
Callwindowproc (pfname, 0, 0 );
Freelibrary (hmod );
}