Dll显式运行时链接
选自《程序员的自我修养》
#include<windows.h> #include<stdio.h> typedef double(*Func)(double, double); int main(int argc, char** argv) { Func func; double result; //Load dll HINSTANCE hinstlib = LoadLibrary("Math.dll"); if (hinstlib == NULL) { printf("Error: unable to load dll\n"); return 1; } //Get function address func = (Func)GetProcAddress(hinstlib, "Add"); if (func == NULL) { printf("Error: unable to find dll function\n"); FreeLibrary(hinstlib); return 1; } //Invoke function result = func(1.0, 2.0); //Unload dll file FreeLibrary(hinstlib); //Display result printf("Result = %f\n", result); return 0; }