C++项目开发中加载第三方动态库的方法
2014-03-20 16:23
661 查看
LoadLibrary
一、语法编辑Syntax(C++)
HMODULE WINAPI LoadLibrary( _In_ LPCTSTR lpFileName);
二、VB/VC声明
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
说明
载入指定的动态链接库,并将它映射到当前进程使用的地址空间。一旦载入,即可访问库内保存的资源
返回值
Long,成功则返回库模块的句柄,零表示失败。会设置GetLastError
参数 类型及说明
lpLibFileName String,指定要载入的动态链接库的名称。采用与CreateProcess函数的lpCommandLine参数指定的同样的搜索顺序
注解
一旦不需要,用FreeLibrary函数释放DLL
三、VB6实例
Create a new project and add this code to Form1
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Sub Form_Load()
On Error Resume Next
'KPD-Team 1999
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
Lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SetWindowTextA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub
四、相应FreeLibrary用法:
FreeLibrary(LoadLibrary时所创建的句柄)
(改编自百度百科:http://baike.baidu.com/view/1286902.htm)
一、语法编辑Syntax(C++)
HMODULE WINAPI LoadLibrary( _In_ LPCTSTR lpFileName);
二、VB/VC声明
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
说明
载入指定的动态链接库,并将它映射到当前进程使用的地址空间。一旦载入,即可访问库内保存的资源
返回值
Long,成功则返回库模块的句柄,零表示失败。会设置GetLastError
参数 类型及说明
lpLibFileName String,指定要载入的动态链接库的名称。采用与CreateProcess函数的lpCommandLine参数指定的同样的搜索顺序
注解
一旦不需要,用FreeLibrary函数释放DLL
三、VB6实例
Create a new project and add this code to Form1
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Sub Form_Load()
On Error Resume Next
'KPD-Team 1999
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
Lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SetWindowTextA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub
四、相应FreeLibrary用法:
FreeLibrary(LoadLibrary时所创建的句柄)
(改编自百度百科:http://baike.baidu.com/view/1286902.htm)
相关文章推荐
- 初次使用VS2010基于C++开发项目碰到的问题及解决方法
- 用C++面向对象的方式动态加载so的方法
- JAVAWEB开发之Servlet3.0新特性的使用以及注解的详细使用和自定义注解的方法、动态代理的使用、利用动态代理实现细粒度的权限控制以及类加载和泛型反射
- webpack开发vue2项目中的一些坑(1、跨域 2、打包后后端访问一片空白3、加载第三方库的字体文件出错4、加载背景图出错)
- C++动态加载DLL调用方法
- 基于动态表单技术的项目开发方法(一)
- Android开发中Listview动态加载数据的方法示例
- 最近项目要求开发一个echarts的小功能图表,需要动态加载数据,现在做完后把源码拷上来
- 初次使用VS2010基于C++开发项目碰到的问题及解决方法
- 在C/C++项目的开发中,防止头文件被重复加载的措施
- Ubuntu中c++项目引用第三方包库的方法
- 初次使用VS2010基于C++开发项目碰到的问题及解决方法
- 【项目实战】---为EasyUI DataGrid的某一动态加载数据列添加超链接,点击超链接触发Onclick方法
- 初次使用VS2010基于C++开发项目碰到的问题及解决方法
- 初次使用VS2010基于C++开发项目碰到的问题及解决方法
- Java之—— JAVA Web项目中DLL/SO文件动态加载方法
- Java之——Web项目中DLL文件动态加载方法
- Linux下C++动态加载so 调用方法
- C++开发中一个解决方案里,两个项目的相互引用,相互依赖的实现方法(解决方法)
- Java之——Web项目中DLL文件动态加载方法