现在的位置: 首页 > 综合 > 正文

How to invoke dll using C++ – C++ 如何调用DLL – 详解

2013年12月02日 ⁄ 综合 ⁄ 共 659字 ⁄ 字号 评论关闭

How to invoke dll using C++ - C++ 如何调用DLL - 详解

1、首先定义一个和“你想调用的函数”的原型相同的一个类型

typedef BOOL (WINAPI *SetLayeredWindowAttributesA)(HWND,COLORREF,BYTE,DWORD);

2、调用 LoadLibrary 函数加载 Dynamic Link Library (DLL)

HINSTANCE hInst = LoadLibrary("User32.dll");

3、定一个SetLayeredWindowAttributesA类型的变量

SetLayeredWindowAttributesA SetLayeredWindowAttributes;

4、调用 GetProcAddress 函数将 刚才定义的变量 指向 此DLL 中的函数,注意:要加:强制转换

SetLayeredWindowAttributes = (SetLayeredWindowAttributesA)GetProcAddress(hInst,"SetLayeredWindowAttributes");

5、使用此函数

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),128,2);

6、用 FreeLibrary 函数释放动态链接库实例句柄

FreeLibrary(hInst);

 

Besides:

I am sorry,以前的有错误,特此更改,这次对了。Thanks for visite.

The follow content is a sample from MSDN:

 

抱歉!评论已关闭.