Jump to content

Recommended Posts

Hello people, my name is Edisson Savio and I am interested in implementing DLL libraries in my code. I work with simulation of numerical methods applied to reentry physical problems. I have implemented my actual code in PASCAL language using Class variables as start point. I have sucess in such implementation. Now, I am interested in using DLL libraries and after a research in this topic, my unique idea was based on the work of Marco Cantù in "Bible Delphi 3" and I have implemented in such way. I have created the base unit and the implementation unity, as well as the DLL routine. When I put this one to run, my code doesn´t execute the first implementated routine. I would like to know if there is someone who can help me in this task? I wait for your help, best regards, Edisson Sávio.

Share this post


Link to post
Guest
3 minutes ago, Edisson Sávio Maciel said:

my code doesn´t execute the first implementated routine.

This is not clear, would you explain that in more details ? like what is the expected behaviour ?

 

Have you tried to build and use a simple DLL to understand the basic ?

 

I just searched the internet and there is plenty of examples explaining how to write and use a DLL with Delphi, like these

https://www.tutorialspoint.com/dll/dll_delphi_example.htm

http://etutorials.org/Programming/mastering+delphi+7/Part+II+Delphi+Object-Oriented+Architectures/Chapter+10+Libraries+and+Packages/Creating+a+DLL+in+Delphi/

Share this post


Link to post

Hello Kas Ob., when I try to execute the first routine of my code, the compiler gives the information of "Acess Violation" and finishes the execution. I am using Class variables and I only found this topic in the Marco Cantù "Bible Delphi 3". Can you hlep me?

Share this post


Link to post

I have read the two references you sent me, but in my code I am using Class variables and according to Marco Cantù book, I need to implement a base unit with the abstract Classes, a implementation unity with my routines and a DLL file with the CALLs to these routines. If there is something wrong please tell me? Best regards, Edisson Sávio.

Share this post


Link to post
Guest
6 minutes ago, Edisson Sávio Maciel said:

Can you hlep me?

Many here can, but..

 

Most likely you are doing something wrong and it is so simple we will not be abled to guess it, so please the following

Write the smallest project like like the ones in the links i pasted above.

Make sure your small project that at max 50 lines show the AV, so we can help you find what are missing.

Share this post


Link to post
Guest
6 minutes ago, Edisson Sávio Maciel said:

I have read the two references you sent me, but in my code I am using Class variables and according to Marco Cantù book, I need to implement a base unit with the abstract Classes, a implementation unity with my routines and a DLL file with the CALLs to these routines. If there is something wrong please tell me? Best regards, Edisson Sávio.

You did repeated the question and i want to point this

1) People here came from different languages (human languages)

2) The terms you are using can and might be interpreted in many different way which leads to guessing work from us and waste everyone time

3) You assumed we are familiar with the book, i am not !, even if i am, this will not help me understand the situation you are stuck at.

 

For that, a failing code will be more helpful and will save everyone time, and you will get an answer for every question you have.

Share this post


Link to post
1 hour ago, Edisson Sávio Maciel said:

the compiler gives the information of "Acess Violation" and finishes the execution.

That is not very clear. Are you sure it is the compiler which generate the Access Violation? I guess it is your program that generate it when running. Please show the EXACT error message. If it is at run time, please run your program and/or DLL under the debugger to know exactly where the error occurs (the debugger will popup when the Access Violation happens).

 

I have no idea how your code is built (I don't have the book you refer). But frequently, using a DLL involves call LoadLibrary to load the DLL and the GetProcAddress to get the pointer to the functions within the DLL. At each step you should check for error because an error could lead to a future access violation. A DLL may also be statically linked or automatically delay loaded.

Share this post


Link to post
Guest

First these doesn't compile to begin with, 

Second i am still not sure what are you trying to do, i can guess only, you want to use a class by DLL, like you already have a class and want to delegate some functionality to a DLL, right ?

 

Does this question and its answers help ?

https://stackoverflow.com/questions/38769411/create-a-delphi-class-with-external-dll-functions-in-it

or this

https://stackoverflow.com/questions/12954973/putting-classes-in-a-dll

 

If that is the case then you might workaround like this

unit Abstract_Classes;

interface

type
  TMaximum = class(TObject)
  public
    Numb1, Numb2: integer;
    function Test_Max(Numb1, Numb2: integer): integer; virtual; abstract;
  end;

function Test_Max_API(MaxClass: TMaximum; Numb1, Numb2: integer): integer;

implementation

function Test_Max_API(MaxClass: TMaximum; Numb1, Numb2: integer): integer;
begin
  MaxClass.Test_Max(Numb1, Numb2);
end;

end.

Now you can export your function like this

exports
  Test_Max_API name 'Test_Max_API';

Now i think you got the idea, also i think here others might help with different approach like the answers you can find by searching the internet.

Share this post


Link to post

Hello Kas Ob, I did some simple tests based on the scheme that you gave me and I am sending a version that compile and generate the executable file (.exe), but it didn't give the expected solution. Could you see and find the error in this implementation? Thank you for your help, best regards, Edisson Sávio.

Abstract_Classes_Test1.pas

DATAS1.dat

Test1.dpr

Test1_DLL_Exports.dpr

Share this post


Link to post
Guest
27 minutes ago, Edisson Sávio Maciel said:

Could you see and find the error in this implementation?

You missed the point, and i think you are missing few critical points in that book, (to be clear nothing to be afraid or panic about), all what you need is read again (the book should explained all of this) and apply the code right from the book, or refer for different book or resources, may be others here can suggest resources.

 

 

The problem

You completely missed my suggestion, the key was this 

function Test_Max_API(MaxClass: TMaximum; Numb1, Numb2: integer): integer;
begin
  MaxClass.Test_Max(Numb1, Numb2);
end;

here this is a global function and will be exported, means any application can load the DLL and call it, but here three parameters not two, the third parameter is MaxClass will call the DLL dependent class.

 

This is one approach i suggested, also there is different ways like COM, and may be for you it will be easier to implement.

 

 

Share this post


Link to post

Your code doesn't load a dll. You have an abstract virtual method that is never implemented. 

 

You are trying to run before you can walk. You aren't going to learn anything useful this way. You need to go back to the basics. 

Share this post


Link to post
1 hour ago, Edisson Sávio Maciel said:

This program compile and create the .exe, but it did not generate the solution.

You need two projects for your solution: one for the DLL and one for the EXE.

Did you read my previous answer? Is there something you don't understand in it?

As @David Heffernan and @Kas Ob. said, you need to learn more to understand what a DLL is, how to write one and how to write an application using that DLL. Kas Ob. pointed you to some tutorials and I'm sure Marco Cantù book explain the concepts.

 

Share this post


Link to post
Guest

Ok, i wrote something for you, but i strongly suggest that you should read the book and and stay away from what is now complicate for you for the future, as David said, learn to walk then run.

 

DllClassTest.zip

 

That was one way to do it, there is other ways, but all of them will be more or less complicated than that, read the book as i am sure (without reading it) it most likely does cover the stuff you looking for, and you may be better with COM and interfaces, they sound intimidating but waaaaay easier than OS specific API for libraries, there is also TMS plugins software just came to my mind, i remember learned few things from it but can't really remember what were these things now.

https://www.tmssoftware.com/site/tmsvclpluginframework.asp

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×