Fortran Dll and Delphi Interface...

I have a program in Fortran and made an interface in delphi.
I changed my exe fortran program in a Dll.
But the Dll takes a long time to finish. How I do to cancel Dll and to return of the main program in Delphi?
Is a problem that I should solve in the delphi or in Fortran?

...Perhaps I am posting a subject in the wrong forum ^_^

Apologize my "translator English"...

Comments

  • Are you sure you are calling the subroutines correctly ?

    When you compiled the DLL file, did you ensure that all the links to the separate subroutines were compiled as well ?

    ---

    I've never tried to call a Fortran compiled DLL with delphi, but as far as I know, the arguments are read from left to right.




  • The fortran DLL was ok. The problem is that when the Dll works the main program in Delphi dont answer.
    See what I use:

    ---------------------
    procedure FERMENTMOD(var num: INTEGER); stdcall; external 'Ferment.dll';

    procedure TSimula.Simulacao( );
    var
    num: Integer;
    begin
    FERMENTMOD(num);
    end;
    ---------------------


    I need some direction for I continue my search for a solution. :(

    Thanks.
  • //This unit shows an example of how to load a procedure in a given library.
    //It contains simple error handling.

    unit abstract_example_unit;

    interface

    uses
    Windows,
    Dialogs,
    SysUtils;

    const
    ERROR_NOT_FOUND = $00000000;
    ERROR_INVALID_PROCEDURE = $00000001;

    type
    TSimula = class
    private
    function Simulacao: Integer;
    end;

    implementation

    function TSimula.Simulacao: Integer;
    type
    //Try to switch between these declarations ...

    TFermentMod = procedure (var Num: Integer);
    //TFermentMod = procedure (var Num: Integer); cdecl;
    //TFermentMod = procedure (var Num: Integer); stdcall;

    var
    Num: Integer;
    hLibrary: THandle;
    FermentMod: TFermentMod;

    begin
    //The dll file need to be in one of the library paths, ea. the execute directory.
    hLibrary := LoadLibrary(PChar('Ferment.dll'));

    if hLibrary <> 0 then
    try
    //The name of the procedure is case sensitive !
    @FermentMod := GetProcAddress(hLibrary,PChar('FERMENTMOD'));

    if @FermentMod <> nil then
    begin
    FermentMod(Num);
    Result := Num;
    end
    else
    Result := ERROR_INVALID_PROCEDURE;

    finally
    FreeLibrary(hLibrary);
    end
    else
    Result := ERROR_NOT_FOUND;

    end;

    var
    Num: Integer;
    Simula: TSimula;

    begin

    with TSimula.Create do
    try
    ShowMessage(IntToStr(Simulacao));
    finally
    Free;
    end;

    end.

    ---

    Please let me know if you encounter any problems.

    Verify that the DLL procedure name is correct and that the parameterlist is what you describe.

    ---

    Regards

    /Filip
    ---

    Regards

    /Filip

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories