Delphi 10.4 32-bit debugger fails to load DLL

Using Delphi 10.4 Sydney

Previously my app was a Win32 app and now I have added Win64 as a target.

It consists of the main app plus a number of supporting DLLs

I have created two folders in my working folder, Win32 and Win64, and setup the project properties so that the compiled exe and dlls are stored in the appropriate folder.

If I run the app from File Explorer (ie outside the IDE) both versions run correctly and use the support DLLs.

Currently everything is compiled as Debug.

Now, in the IDE, if I set the target to Win64, and then either Run or Run without debugging, the app runs OK.

But, if I set the target to Win32, and then either Run or Run without debugging, the app fails.
The error is where I call SafeLoadLibrary('MyDLLName.dll')

The error code is 'File not found'

I have tried using the full path name but that made no difference.
I have tried both LoadLibrary and LoadLibraryEx and again, no difference.

Running outside the IDE works perfectly (both Win32 and Win64), running inside the IDE fails for Win32 but OK for Win64.

I had no problems using the previous versions of Delphi targeting 32-bit.

I have set the project options for debugger working directory and source path to the Win32 folder, although it doesn't make any difference if they are left blank.

So, any thoughts?

Parents
  • My original code looked like this. I only call the code when I actually need to use the ReadFile1308 function

    hDLL := SafeLoadLibrary('FileRead1308.dll');
    if hDLL > 0 then begin
    ReadFile1308 := GetProcAddress(hDLL,'FileRead1308');

    and it failed.

    But if I change to the following, and add it to the top of the implementation section (of the same file that has the SafeLoadLibrary call) and comment out the above code plus the code where the function was originally declared

    Function ReadFile1308(hFile:THandle; FileVersion:TModuleVersionNumber; var FileData1308:TFileData1308; Text:PChar):integer; stdcall; external 'FileRead1308.dll';

    then it all works. Both Win32 and Win64 in the IDE and from File Explorer.

    But that wasn't actually the problem.

    When I changed back to the original code, surprise, surprise, it still worked!

    But, when I first ran with the changed code, an error message popped up with 'rtl270.bpl not found'.
    FileRead1308.dll is compiled with run time packages, and needs both rtl270.bpl and vcl270.bpl.
    They were both missing from the Win32 folder.
    So I added them from the Embarcadero redist folder, and then ran from the IDE with success.

    So it would seem that the problem all along was the missing run time bpls that FileRead1308.dll needed.
    But the error message back from SafeLoadLibrary simply said 'file not found' which I assumed meant that FileRead1308.dll could not be found.
    But it was in fact not that FileRead1308 could not be found, but rather that a bpl that FileRead1308 needed could not be found.
    It would be nice if the 'file not found' message could actually include the name of the file.

    So, all OK. On to the next problem.

Reply
  • So it would seem that the problem all along was the missing run time bpls that FileRead1308.dll needed.
    But the error message back from SafeLoadLibrary simply said 'file not found' which I assumed meant that FileRead1308.dll could not be found.

    ... or any of its static dependencies.  When a DLL or one of its dependencies fails to load, Windows doesn't tell WHICH file failed.

    It would be nice if the 'file not found' message could actually include the name of the file.

    That is an OS error message, not an IDE error message.  And Windows does not include the filename in the error message (it can't - the error message is static text, context is gone by the time the error message is retreived after a load failure).

    The only way to know WHICH file failed is to use a tool like Process Monitor while loading your DLL, so you can see all of the files that are searched for.  That will tell you WHICH file was not found.

Children
No Data