不使用.h .lib文件使用DLL内的函数

#include <windows.h>
 
typedef int (*Func)(const char *fmt, ...);     //这里声明一个函数指针,typedef 关键字是必须的,好像要显示调用dll中的函数,都需要这样用函数指针给出声明
 
int main()
{
    HINSTANCE hDll;
    int a=2,b=3;
    char c='a';
    char str[10]="Sun";

    Func cprintf;
    hDll=LoadLibrary("TestDll.dll");
    if (hDll==NULL)
    {
       ;
    }
    else
    {
        cprintf=(Func)GetProcAddress(hDll,"cprintf");
        if (cprintf!=NULL)
        {
            cprintf("%d+%d=%d
",a,b,a+b);
            cprintf("%c的ASCII:%d
",c,c);
            cprintf("字符串格式化测试:%s
",str);
            cprintf("不用.lib .h 文件调用DLL内的函数...success!
");
        }
    }
    FreeLibrary(hDll);
    
    system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/qiangua/p/4006409.html