I'm building a plugin system with Delphi (some of you have been helping me with this task).
To search for the DLL files, I'm using a TSearchRec, which search's in the exe path for dll files, and then I'm using LoadLibrary to access them. Then, if a certain function is exposed (using GetProcAddress), I load it as a plugin. If not, FreeLibrary is executed, and moves on for the next file.
While testing, I noticed that when the TSearchRec found the "borlndmm.dll", which happened to be in that path, it loads, and searches for my plugin function, which of course is not found, but when if executes FreeLibrary, I get an Access Violation.
Other no-plugin dll's in the same path, like libmariadb.dll, are freed securely without errors.
Of course this is easily fixed, by having my plugin dll's in its own path, without any other dll files, which will be better even for performance reasons, as it doesn't have to load any library that it's not supposed to.
But I would like to understand why it happens. Any ideas?
Thank you Nuno Picado
LoadLibrary
onborlndmm.dll
and then callsFreeLibrary
, does this still happen? If so, please post the code used. If not, it's a problem isolated to your app itself. (I agree with @DavidHeffernan, BTW; loading random DLLs into your process is a terrible idea.) – Ken White