Hi,
I am working on a C++ Windows native application where we #import the Acedao.dll dynamic library in order to read and edit .accdb and .mdb files.
As the users of the application can have different Acedao configurations, we recently added some initialisation code that checks the version of the registered Acedao.dll library by calling the function DAO::_DBEngine::GetVersion. We tested this on a machine where the "Microsoft Access Database Engine 2016 Redistributable" had been installed and GetVersion returned "16.0". We found that with the older 2010 redistributable the return value was "14.0". So far, so good.
The problem arises when the user has a full installation of Office, rather than the redistributable engine. Even if the user has installed the redistributable (v. 16.0.4492.1000; 591 kB), any Office updates will change the registered version of the DLL to the latest Office one (as of January 2021, v. 16.0.13530.20062; 795 kB). This behaviour was mentioned in a thread in the old MSDN forums: AceDao - problem with requery. But when calling GetVersion with this latest version of Office a _com_error is thrown with a null description.
The following minimal C++ program displays the problem. The "C:\acedao_test\ACEDAO.DLL" file can be either the redistributable one or the latest Office one; it doesn't matter. But the behaviour will be different depending on which version is the one registered on the host system.
#include <objbase.h>
#include <iostream>
#import <C:/acedao_test/ACEDAO.DLL> rename("EOF", "AdoNSEOF")
int main()
{
CoInitializeEx(0, COINIT_APARTMENTTHREADED);
DAO::_DBEngine* daoEngine = nullptr;
HRESULT hResult = CoCreateInstance(__uuidof(DAO::DBEngine), nullptr, CLSCTX_ALL, IID_IDispatch, reinterpret_cast<LPVOID*>(&daoEngine));
if (daoEngine == nullptr)
{
std::wcout << L"Failed to find the Access Database engine" << std::endl;
}
else
{
try
{
_bstr_t version = daoEngine->GetVersion();
std::wcout << L"Found Access Database engine with version " << version.GetBSTR() << L"." << std::endl;
}
catch (const _com_error& comError)
{
_bstr_t comErrorDescription = comError.Description();
std::wcout << L"Error calling DAO::_DBEngine::GetVersion; description: " << (comErrorDescription.length() > 0 ? comErrorDescription.GetBSTR() : L"NULL") << std::endl;
}
}
CoUninitialize();
}
With v. 16.0.4492.1000 (redistributable), the output is:
"Found Access Database engine with version 16.0."
And with v. 16.0.13530.20062 (Office update), the output is:
"Error calling DAO::_DBEngine::GetVersion; description: NULL"
Is there any rationale for this change in behaviour? Or is our attempt to use GetVersion wrong for some reason?
Note: Since the MSDN forum has been migrated to this new Q&A site, there doesn't seem to be any appropriate "Access development" tag. The closest I've found is "office-addins-dev", although my question is not actually about add-ins.