您的位置:首页 > 其它

dll编写3之LoadLibrary动态加载

2015-04-19 01:39 211 查看
 
_declspec(dllexport) int __cdecl add (int a,int b)
{
	return a+b;
}

_declspec(dllexport) int _stdcall sub (int a,int b)
{
	return a-b;
}




#include <stdio.h>
#include <windows.h>

int main (void)
{
    typedef int(_cdecl *Add)(int a,int b);
	typedef int(_stdcall *Sub)(int a,int b);

	HINSTANCE hInst=LoadLibrary(TEXT("dll3.dll"));
	if (hInst)
	{
		Add add=(Add)GetProcAddress(hInst,"add");
		Sub sub=(Sub)GetProcAddress(hInst,"sub");
		Sub subID=(Sub)GetProcAddress(hInst,MAKEINTRESOURCE(2));
		printf("%d\n",add(5,3));
		printf("%d\n",sub(5,3));
		printf("%d\n",subID(5,3));
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: