{"id":23686315,"url":"https://github.com/pchemguy/dlltools","last_synced_at":"2026-01-08T12:30:16.750Z","repository":{"id":225099417,"uuid":"433463873","full_name":"pchemguy/DllTools","owner":"pchemguy","description":"DllManager facilitates VBA function calls to non-system DLL libraries.","archived":false,"fork":false,"pushed_at":"2022-01-09T21:17:22.000Z","size":23485,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T21:19:34.489Z","etag":null,"topics":["dll","library","vba"],"latest_commit_sha":null,"homepage":"","language":"VBA","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pchemguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-30T14:33:23.000Z","updated_at":"2024-12-20T06:20:04.000Z","dependencies_parsed_at":"2024-02-29T08:55:30.776Z","dependency_job_id":null,"html_url":"https://github.com/pchemguy/DllTools","commit_stats":null,"previous_names":["pchemguy/dlltools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchemguy%2FDllTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchemguy%2FDllTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchemguy%2FDllTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchemguy%2FDllTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pchemguy","download_url":"https://codeload.github.com/pchemguy/DllTools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239742407,"owners_count":19689309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dll","library","vba"],"created_at":"2024-12-29T21:19:31.065Z","updated_at":"2026-01-08T12:30:16.707Z","avatar_url":"https://github.com/pchemguy.png","language":"VBA","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Summary of functionality\n\n\nThe DllManager class, the main component of DllTools, facilitates VBA calls to\n\n  * DLLs in non-standard locations,  \n  * CDECL routines from VBA-x32 hosts, and  \n  * DLLs with multiple non-system dependencies.  \n\n#### DLLs with dependencies in non-standard locations\n\nWhile the Declare statement is sufficient for making VBA-compatible DLL calls, this statement must include an absolute path to the library for non-standard locations, making the declarations ugly and the code fragile. The alternative approach involves explicit loading of DLLs via the LoadLibrary Windows API. Furthermore, Windows may sometimes fail to load dependencies automatically, raising obscure errors. In such a case, DllMnager can take an ordered sequence of DLL names for loading in the provided order.\n\n#### Proxying calls to CDECL routines from VBA-x32 hosts\n\nVBA-x32 only supports calls to DLL routines that follow the WINAPI/STDCALL calling convention. If a VBA-x32 application needs functionality provided by a DLL, a WINAPI version is always preferable. However, some libraries may only be available as CDECL binaries. Additionally, variadic functions must follow the CDECL calling convention and are not directly accessible from VBA-x32. DllManager wraps the DispCallFunc Windows API, which can act as a calling proxy in such cases.\n\n### Usage example\n\nDllManager is a predeclared class employing the Factory/Constructor (Create/Init) pattern. The DllManager factory takes the default DLL path as the first required argument. It can be blank for target DLLs located in a preset location within the project folder optionally checked by DllManager. The second optional argument specifies the names of the DLLs to be loaded, and, if not provided, Load/LoadMultiple methods can load the libraries after instantiation.\n\nThis demo, DllManagerDemo, is a standard module located in the DllTools.Manager.Demo folder in the RubberDuckVBA Code Explorer. It uses the *sqlite3_libversion_number* function to compare a conventional system call and a similar call to a DLL located in a user directory. Specifically, Windows 10 includes a system copy of the SQLite library named WinSQLite3.dll directly accessible via the Declare statement. Separately, this project provides a custom-compiled SQLite library file SQLite3.dll loaded via DllManager. A module-level attribute, *this.DllMan*, must keep a reference to the DllManager object. Otherwise, after exiting the *SQLiteLoadMultipleArray* Sub, VBA would destroy the DllManager instance, calling its *Class_Terminate* Sub, which, in turn, causes a call to the FreeLibrary API freeing the loaded library.\n\n#### DllManagerDemo\n\n```vb\nOption Explicit\n\n#If Win64 Then\nPrivate Const ARCH As String = \"x64\"\n#Else\nPrivate Const ARCH As String = \"x32\"\n#End If\n\nPrivate Const LIB_NAME As String = \"DllTools\"\nPrivate Const PATH_SEP As String = \"\\\"\nPrivate Const LIB_RPREFIX As String = \"Library\" \u0026 \"\\\" \u0026 LIB_NAME \u0026 \"\\dll\\\"\n\n#If VBA7 Then\nPrivate Declare PtrSafe Function winsqlite3_libversion_number Lib \"WinSQLite3\" Alias \"sqlite3_libversion_number\" () As Long\nPrivate Declare PtrSafe Function sqlite3_libversion_number Lib \"SQLite3\" () As Long\n#Else\nPrivate Declare Function winsqlite3_libversion_number Lib \"WinSQLite3\" Alias \"sqlite3_libversion_number\" () As Long\nPrivate Declare Function sqlite3_libversion_number Lib \"SQLite3\" () As Long\n#End If\n\nPrivate Type TModuleState\n    DllMan As DllManager\nEnd Type\nPrivate this As TModuleState\n\n\nPrivate Sub GetWinSQLite3VersionNumber()\n    Debug.Print winsqlite3_libversion_number()\nEnd Sub\n\nPrivate Sub GetSQLite3VersionNumber()\n    SQLiteLoadMultipleArray    \n    Debug.Print sqlite3_libversion_number()\n    Set this.DllMan = Nothing\nEnd Sub\n\nPrivate Sub SQLiteLoadMultipleArray()\n    Dim DllPath As String\n    DllPath = ThisWorkbook.Path \u0026 PATH_SEP \u0026 LIB_RPREFIX \u0026 ARCH\n    Dim DllNames As Variant\n    If ARCH = \"x64\" Then\n        DllNames = \"sqlite3.dll\"\n    Else\n        DllNames = Array( _\n            \"icudt68.dll\", \"icuuc68.dll\", \"icuin68.dll\", _\n            \"icuio68.dll\", \"icutu68.dll\", \"sqlite3.dll\" _\n        )\n    End If\n    Dim DllMan As DllManager\n    Set DllMan = DllManager.Create(DllPath)\n    Set this.DllMan = DllMan\n    DllMan.LoadMultiple DllNames\nEnd Sub\n```\n\nUsually, a DLL located in a user directory can still be accessed directly via the Declare statement by specifying the absolute path to the file. However, the automatic Windows DLL loading process may fail if the library has dependencies. For example, the target DLL may require a particular library version, which differs from the one installed on the system. Or perhaps, a custom dependency resides in a different non-system directory.\n\nIn this case, Windows could not load dependencies for the custom-compiled x32 SQLite copy automatically. As demonstrated in this example, the DllManager accepts multiple DLL names and loads them in the order provided, successfully overcoming this issue. Moreover, DllManager can load libraries from several non-standard locations via its Load method.\n\n---\n\nFurther documentation is available from GitHub Pages [site](https://pchemguy.github.io/DllTools/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchemguy%2Fdlltools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpchemguy%2Fdlltools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchemguy%2Fdlltools/lists"}