windows系統下可執行程式呼叫lib靜態庫和dll動態庫的方法
阿新 • • 發佈:2019-01-04
#include <stdio.h>
#include <Windows.h>
int main()
{
HINSTANCE h=LoadLibraryA("newdll.dll");
typedef int (* FunPtr)(int a,int b);//定義函式指標
if(h == NULL)
{
FreeLibrary(h);
printf("load lib error\n");
}
else
{
FunPtr funPtr = (FunPtr)GetProcAddress(h,"add");
if(funPtr != NULL)
{
int result = funPtr(3, 3);
printf("3 + 3 = %d \n", result);
}
else
{
printf("get process error\n");
printf("%d",GetLastError());
}
FreeLibrary(h);
}
return 0;
}
#include <Windows.h>
int main()
{
HINSTANCE h=LoadLibraryA("newdll.dll");
typedef int (* FunPtr)(int a,int b);//定義函式指標
if(h == NULL)
{
FreeLibrary(h);
printf("load lib error\n");
}
else
{
FunPtr funPtr = (FunPtr)GetProcAddress(h,"add");
if(funPtr != NULL)
{
int result = funPtr(3, 3);
printf("3 + 3 = %d \n", result);
}
else
{
printf("get process error\n");
printf("%d",GetLastError());
}
FreeLibrary(h);
}
return 0;
}