Load Dynamic DLL (Bemafi32) in Delphi

Asked

Viewed 939 times

2

I need help loading the DLL BemaFI32.dll dynamically in the Delphi.

My code is like this:

function _Bematech_FI_NumeroSerie(NumeroSerie: AnsiString): Integer;
var
  xBematech_FI_NumeroSerie : function ( NumeroSerie: AnsiString ): Integer; stdcall;
  lHandle : THandle;
begin
  lHandle := LoadLibrary('bemafi32.dll');
  @xBematech_FI_NumeroSerie := GetProcAddress(lHandle, PChar('Bematech_FI_NumeroSerie'));

  if @xBematech_FI_NumeroSerie = nil then
    raise Exception.Create('Entrypoint Bematech_FI_NumeroSerie não encontrado na Dll');

  Result := xBematech_FI_NumeroSerie(NumeroSerie);
end;

The return of the function is always -4, indicating that the file does not exist BemaFI32.ini. But the file exists.

I’ve tried to perform the functions Bematech_FI_ReloadINIFile and Bematech_FI_AbrePortaSerial before, but always returns the same error.

I am developing in Delphi XE2, in Windows 10 64 bits. However I have also tested with Windows 7 and the same problem occurs.

The version of Bemafi32.dll is 7.0.4.32.

Has anyone ever had a similar problem?

  • The archive BemaFI32.ini has to be in the Windows system directory. Are you sure that it is there?

  • @zekk, thanks for the help. A dll and ini are in the same executable folder. I did a test now with those file in Windows folder and it also didn’t work. If I use the dll statically, the function runs smoothly.

  • Maybe it could be a problem with the UAC, have you tried running the application as an administrator? read on: https://msdn.microsoft.com/pt-br/library/windows/desktop/aa384187(v=vs.85). aspx

  • 1

    @zekk, Following your initial tip, I put the files in the Syswow64 folder. Ai worked perfectly! I really appreciate your help.

  • Ronaldo, if you want to post this as an answer, it would help others!

2 answers

2

Following the @zekk tip, I put the Bemafi32.ini file in the C: WINDOWS Syswow64 folder.

This way the communication with the DLL worked.

0

I did the same thing put in the folder Syswow64, it seems that only happens with Windows 64bit. puts all dlls in the folder Syswow64 q of right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.