0
votes

I'm loading a DLL using LoadLibrary from my Delphi project like so:

DLLHandle := LoadLibrary('my.dll');
if (DLLHandle = 0) then ShowMessage(SysErrorMessage(GetLastError));

The directory where the DLL resides is included in the Windows PATH environment variable. When I execute this project from within Delphi, the DLL doesn't load. However, when the same code is exectued directly from Windows, the DLL loads perfectly.

What am I missing here? I've tried to explicitly tell Delphi to look in the directory of the DLL by adding the directory to the Tools->Options, Environment Options->Delphi Options->Library - Win32->Library Path. (It feels like an utter PEBKAC. I'm anticipating embarrasment for myself in the near future :) ...)

Thanks in advance!

1
(1) Please show the code, and (2) Library path is the path for code libraries, it has nothing to do with DLLsEugene Mayevski 'Callback
Maybe Delphi is started with a different environment where the path is not included in %PATH%?Lars Truijens
@Eugene: 1) I've updated my question to show the actual code (although I don't think it's a problem with the code), and 2) thanks! I've had a peek in the documentation, and you're absolutely right. Don't know why I put it there in the first place. :)conciliator
@conciliator use GetLastError() function to narrow down the problem.Eugene Mayevski 'Callback
What error GetLastOSError throws?user160694

1 Answers

2
votes

Most of the time, when I have a similar problem(works from windows, not from debugger), it's because of "user overrides"

("Project->Options" menu, "Debugger->Environment block")

You might have an user override for the "Windows Path" which is why it doesn't work when ran from the debugger.