0

I have a program that calls a DLL stored in the same folder that the program is stored in. When I run the calling code, either from the IDE or the program directly, it finds the DLL and gives no errors. But, when the client runs the program, it gives the error "Unable To Load DllSendOrder2018.dll". This behavior just started. On old versions of the code, it loads with no errors (other than another problem I need to fix).

procedure TFrmMain.BtnSendOrderClick(Sender: TObject);
var
  SendOrders : procedure; stdcall;
begin
  DLLHandleSend := LoadLibrary('DllSendOrder2018.dll');
  if DLLHandleSend <> 0 then
  begin
    @SendOrders := GetProcAddress(DLLHandleSend,'SendOrders');
    try
      SendOrders;
    except
      on E: Exception do
        ShowMessage(E.Message);
     end;
     FreeLibrary(DLLHandleSend);
  end
  else
    MessageDlg('Unable To Load DllSendOrder2018.dll',mtError,[mbOk],0);
  FldLookup.SetFocus;
end;

Is there a better place to put the DLL?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
S bossen
  • 87
  • 1
  • 5
  • What does `GetLastError()` report when `LoadLibrary()` fails? When using a relative path, `LoadLibrary()` always searches the folder of the calling EXE first, per the [Dynamic-Link Library Search Order](https://learn.microsoft.com/en-us/windows/desktop/Dlls/dynamic-link-library-search-order). Have you tried using an absolute path instead of a relative path? `LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'DllSendOrder2018.dll'));` – Remy Lebeau Feb 02 '19 at 02:44
  • 1
    If the dll is in the same directory as the executable then it will be found. So the logical conclusions are that either it isn't there, or its dependencies cannot be found. Start with the error checking that Remy described. – David Heffernan Feb 02 '19 at 08:44
  • Recently I've encountered some pretty agressive virus scanners that remove the DLL seconds after you put it somewhere. Doublechecking if it's still there might solve your problem... – Bigman74066 Feb 02 '19 at 14:42
  • Thanks Remy GetLastError() is not even executed. I put debug code around LoadLibrary now not only does it not open the DLL but the program crashes on the user machine. On my machine is says LoadLibrary Because of Error Code The operation completed successfully – S bossen Feb 05 '19 at 23:17

0 Answers0