动态调用 DLL 中的函数
来源:互联网 发布:c#数据库删除语句 编辑:程序博客网 时间:2024/04/29 05:32
By definition DLLs are dynamically loaded libraries of functions and sometimesdata. However, it's possible to either hard code the ability to "import"functions from DLLs or dynamically "bind" a DLL during the run time --which of course means that we don't necessarily need to know the name ofthe DLL nor the name of the function we're about to call (to a certain extent)during the time we code. Dynamically loading and unloading DLLs could notonly save memory, but also can help you write programs that are able to"adjust" itself if certain DLLs are missing.Following "LoadAndRunDLLProcedure()"function will let you pass the name of the DLL you want to connect to andthe name of the function you want to call. If everything goes well, it willload the DLL, call the function, and then unload the DLL.
function LoadAndRunDLLProcedure( sDLL, sFunc : string ) : boolean;type // define the type of "function" // we're calling TFunc_Start = procedure;var Func_Start : TFunc_Start; hDll : THandle; FuncPtr : TFarProc; sMsg : string;begin Result := False; hDll := LoadLibrary( PChar( sDLL ) ); if(hDll > 32)then begin FuncPtr := GetProcAddress( hDll, PChar( sFunc ) ); @Func_Start := FuncPtr; if(nil <> @Func_Start)then begin Func_Start; Result := True; end else begin sMsg := 'DLL entry point ' + sFunc + ' not found'; MessageBox( 0, PChar( sMsg ), 'Error', MB_OK ); end; FreeLibrary( hDll ); end else begin sMsg := 'File ' + sDLL + ' not found'; MessageBox( 0, PChar( sMsg ), 'Error', MB_OK ); end;end;For example, let's say you want to call a procedure called "HelloWorld()"in a DLL named "MyStuff.DLL:"LoadAndRunDLLProcedure( 'MyStuff.DLL', 'HelloWorld' );Please note that HelloWorld() must be a procedure, for example, declared as:procedure HelloWorld;or in C:void HelloWorld();
- 动态调用 DLL 中的函数
- C#动态调用DLL中的函数
- 动态调用dll函数
- 显式调用DLL中的函数(动态调用)
- 通过函数指针动态调用 dll 中的函数
- 【探索wireshark】 动态调用libwireshark.dll中的函数
- 在C++中调用DLL中的函数——静态调用和动态调用
- 调用外部 DLL 中的函数
- 如何调用DLL中的函数
- 如何调用 DLL 中的函数
- 如何调用DLL中的函数
- 如何调用DLL中的函数
- 如何调用 DLL 中的函数
- DLL导出函数方法以及动态调用
- C函数的DLL,C++动态调用。
- 如何动态调用DLL中的导出类
- 如何动态调用DLL中的导出类
- 在ActiveX控件中如何动态调用在资源中的DLL函数之"准"一体化方法
- 给Swing程序添加一个动态显示内存情况的状态条
- 上火原因与治疗
- JVM的内存管理和垃圾回收
- Delphi中动态链接库两种调用方式的比较
- 上火治疗
- 动态调用 DLL 中的函数
- 今天来过,但不知道写什么?
- Flash实现动画影片中图片缓冲放大和缩小效果
- delphi内存管理
- 认识callback函数
- Delta phase angle between two sinusoidal waves with different frequencies 不同频率下的相角差
- C++多线程-互锁
- GDB
- 毕业......