I have been tasked with getting some legacy code to build. It needs to be built using C++ Builder XE3, due to dependencies elsewhere in the business. It comprises a main executable that has the ability to load DLL's specified by the user at run time. We know existing installations of the software work, yet any version we've attempted to build has run into a problem loading the DLLs.
At the point of loading the DLL an exception is generated either reporting...
"Error 126: The specified module could not be found."
or "Error 1114: A dynamic link library (DLL) routine failed.".
We've managed to consistently reproduce the latter using a very simple DLL as shown below:
#pragma hdrstop
#pragma argsused
#include <vcl.h>
extern "C" int _libmain(unsigned long reason)
{
return 1;
}
extern "C" __declspec(dllexport) void OnLoad(AnsiString text)
{
}
The relevant part of the calling function is:
HINSTANCE FDLLHandle = LoadLibrary("Test.dll");
if(!FDLLHandle)
{
// Call to throw exception using GetLastError() return value
}
We've done enough investigation/testing to identify that the AnsiString is either the cause of the problem or significantly contributing to the problem because if we remove the AnsiString the problem goes away. Unfortunately we can't do that for all the user DLLs, only our simple test one.
Strangely we got this the test DLL to work when it was built using C++ Builder 2007 (whilst the calling application was still built using XE3) but again this is not a viable long term solution.
Would appreciate any insight anyone may have.
When you create a new dll from scratch using C++ builder you get this comment about memory management for String types (which will apply equally to AnsiString types).