Dll 的創建 和調用

Dll的源碼

#include <stdio.h>
void test()
{
    printf("Hello world!\n");
}

int sum(int a,int b)
{
    return (a + b);
}

Dll-def的源碼

LIBRARY 
EXPORTS
test
sum

調用Dll的主程序源碼

#include <Windows.h>
#include <stdio.h>
typedef int(*Sum)(int,int);
void main() {
    HMODULE HDLL = LoadLibrary("Project1.dll");
    FARPROC test = GetProcAddress(HDLL, "test");
    test();
    Sum sum = (Sum)GetProcAddress(HDLL, "sum");
    printf("%d\n",sum(3,5));
    system("pause");
    FreeLibrary(HDLL);
}

運行結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章