DELPHI中动态调用DLL的载入片断代码
2009-03-17 09:58
375 查看
function LoadLibs: Boolean; var prefix : AnsiString; function connectProc(var ProcAdr:pointer;ProcName:AnsiString):boolean; begin ProcAdr := GetProcAddress(DLLHandle, PChar(prefix+ProcName)); if not Assigned(ProcAdr) then begin ShowMessage('Could not find method: '+prefix+ProcName); connectProc := False; end else connectProc := True; end; begin Result := False; DLLHandle := LoadLibrary(SQLITEDLL); if DLLHandle <> 0 then begin Result := true; //check if sqlite.dll was compiled with borland bcc (recomended!!!) if GetProcAddress(DLLHandle, PChar('_sqlite_open')) <> nil then prefix:='_' else prefix:=''; Result := Result and connectProc(@SQLite_Open, 'sqlite_open'); Result := Result and connectProc(@SQLite_Exec, 'sqlite_exec'); Result := Result and connectProc(@SQLite_Close, 'sqlite_close'); Result := Result and connectProc(@SQLite_Version,'sqlite_libversion'); Result := Result and connectProc(@SQLite_Encoding, 'sqlite_libencoding'); Result := Result and connectProc(@SQLite_ErrorString ,'sqlite_error_string'); Result := Result and connectProc(@SQLite_GetTable , 'sqlite_get_table'); Result := Result and connectProc(@SQLite_FreeTable ,'sqlite_free_table'); Result := Result and connectProc(@SQLite_FreeMem , 'sqlite_freemem'); Result := Result and connectProc(@SQLite_Complete , 'sqlite_complete'); Result := Result and connectProc(@SQLite_LastInsertRow ,'sqlite_last_insert_rowid'); Result := Result and connectProc(@SQLite_Cancel ,'sqlite_interrupt'); Result := Result and connectProc(@SQLite_BusyTimeout ,'sqlite_busy_timeout'); Result := Result and connectProc(@SQLite_BusyHandler ,'sqlite_busy_handler'); Result := Result and connectProc(@SQLite_Changes ,'sqlite_changes'); Result := Result and connectProc(@SQLite_Create_Function , 'sqlite_create_function'); Result := Result and connectProc(@SQLite_Set_Result_Double ,'sqlite_set_result_double'); Result := Result and connectProc(@SQLite_Set_Result_Int , 'sqlite_set_result_int'); Result := Result and connectProc(@SQLite_Set_Result_String ,'sqlite_set_result_string'); Result := Result and connectProc(@SQLite_Set_Result_Error , 'sqlite_set_result_error'); Result := Result and connectProc(@SQLite_Function_Type , 'sqlite_function_type'); end else ShowMessage('sqlite library not loaded!'); end;
自认为这段代码还是写得挺有意思的。局部函数的引用,减少了很多冗余代码的敲入。result结果的赋值,也看起来比较爽。阅读性还是不错的。
相关文章推荐
- Delphi中动态调用DLL中的窗体
- C#程序实现动态调用DLL的研究 (入门附代码)
- 编写S-Function,创建Simulink模型并生成C++代码,编译生成可调用的动态库dll(From Simulink model to DLL A tutorial)
- Delphi 类库(DLL)动态调用与静态调用示例讲解
- Delphi中如何把函数代码调出主程序,写到“DLL”中并调用
- Delphi调用C#动态链接库DLL(摘自网络)
- 在Delphi中动态调用C++的DLL
- dll函数动态调用工具1.0(Delphi+asm实现)
- Delphi 类库(DLL)动态调用与静态调用示例讲解
- C#用反射将Model类动态载入表单 利用Velocity传值 调用只需一句代码
- 在Delphi中动态调用C++的DLL
- Delphi 动态与静态调用DLL
- DLL_Delphi动态调用
- delphi动态调用DLL的方法与技巧
- delphi 动态调用DLL
- 非常不错的C#动态调用DLL代码
- Delphi 动态与静态调用DLL
- Delphi调用C++编写的动态链接库dll的方法
- 非常不错的C#动态调用DLL代码
- 调用外部DLL,如:DelphiC++Java的DLL的调用方法,给出代码片段?