mercredi 22 juin 2016

Cannot load Firebird embedded DLL using IBPP


A description of my project environment as it pertains to my problem:

OS: Win7-64;

Environment/compiler: Qt 5.6 with C:QtToolsmingw492_32bing++.exe (MinGW 4.9.2 32 bit compiler);

Firebird connectivity library: IBPP 2.5.3.1 (with setting: #define IBPP_WINDOWS);

Firebird embedded: V2.5.5.26952 32 bit (also tried V2.5.2.26540 32 bit and V2.5.5.26952 64 bit)

For setting up Firebird embedded, in my application directory, I have included these files:

MyLocalDatabase.fdb  (I created this Firebird database)
fbclient.dll (renamed from fbembed.dll)
firebird.log
firebird.msg
ib_util.dll
icudt30.dll
icuin30.dll
icuuc30.dll
isql.exe  (for testing MyLocalDatabase.fdb)
intlfbintl.conf
intlfbintl.dll
udf[6 files that came with zip file, unmodified]

Note: I did not include aliases.conf and firebird.conf because I am not using them.

I found it necessary to do significant hacking to IBPP to have it get along with the Windows API (for example, replacing calls to LoadLibrary() with LoadLibraryA() and numerous similar changes) and be able to compile successfully.

First, I was having problems with IBPP finding the target copy of fbclient.dll (I have several versions in several locations on my system for various purposes). To remove the possibility of these types of problems, I modified _ibpp.cpp by commenting out the section that searches Windows paths (approximately lines 100-200) and replacing with one simple line to direct IBPP to the target fbclient.dll:

mHandle = LoadLibraryA("C:\Path\To\My\Application\fbclient.dll");

Then I added an exception catch to get more info about what is happening. The whole section in _ibpp.cpp looks like this:

#ifdef IBPP_WINDOWS
    mHandle = LoadLibraryA("C:\Path\To\My\Application\fbclient.dll");
    char LastSysErr[256];
    sprintf(LastSysErr, "%lu",GetLastError());
    if (mHandle == 0) {
        throw LogicExceptionImpl("mHandle is zero",_(LastSysErr));
    }
#endif

When I run this test from main code:

IBPP::Database db = IBPP::DatabaseFactory("", "C:\Path\To\My\Application\MyLocalDatabase.fdb", "sysdba", "password");

The contrived exception is always thrown as:

*** IBPP::LogicException ***
Context: mHandle is zero
Message: 193

where 193 corresponds to "ERROR_BAD_EXE_FORMAT, %1 is not a valid Win32 application" according to MSDN.

Now, if I run the isql.exe that is in my application directory, I am able to use the fbclient.dll in the application directory to successfully connect to MyLocalDatabase.fdb (if I remove fbclient.dll from the application directory, isql will not run properly; this is my "proof" that the target fbclient.dll is being used).

Stuck: I cannot get a valid mHandle such that IBPP can move on to establishing entry points for the fbclient DLL.

Note: I also tried using FlameRobin to connect to MyLocalDatabase.fdb without success most likely due to the IBPP in FlameRobin picking an incorrect instance of fbclient.dll on my system.

I suspect I'm somehow getting caught up in a 32 versus 64 bit tangle, so I'm trying to keep everything to 32 bit, but not really sure if I've achieved this from end to end.


Aucun commentaire:

Enregistrer un commentaire