DLL active Delphi

Asked

Viewed 681 times

3

I have a DLL and it is activated like this:

Rundll32 MinhaDll.dll

Starts after command, does the process and is terminated.

I need it to continue in memory monitoring certain processes.

The only way I could keep her active was by doing:

repeat application.processmessage until false; 

But the processing is always 100%.

Is there another way to keep it active by doing a monitoring every 1 second?

In short, I need to load a DLL while starting Windows and download when it is turned off.

  • 4

    Welcome to [en.so]! The community closed the question because it was not possible to clearly understand the problem. I edited your question, adjusting the formatting and the text a little and adding your comment. She should get back in line for analysis. Remember that you can edit it at any time if it is not in accordance with what you wanted or to complement with more information. The question is yours, although there is in some sense a collaborative process here in [pt.so]. Thank you!

  • 2

    One way to solve this problem is to create an application and load the dll into that application. While the application is active the dll will also be.

1 answer

2

DLLS are dynamic link libraries, i.e., they are loaded at the moment a program or other DLL references it during execution.

From what I understand of the above problem, you need a program that runs a procedure every 1 second. The best way I know to do this in Windows is to create a service and register it in Service Control Manager.

There is this tutorial http://www.devmedia.com.br/criando-um-windows-service/7867

Services are programs without a graphical interface (as they run in the background) and are managed by Windows.

I believe you are using Delphi, in this case it is very simple to create services with Delphi. Go to the wizard menu of a new project and indicate that you want to create a Windows service project.

By the nature of a Windows service, you will need to implement 3 methods in your boot class - Start and Stop - they will be called by Windows to respectively start and stop the service. It’s up to you to implement what your service will do on startup.

As it requires a monitoring every 1 second, I would do something like this:

procedure TsrvPrincipal.ServiceExecute(Sender: TService);
begin
  while not self.Terminated do begin
    Sleep(1000); // Aguarda 1 segundo
    executeMonitoring();  // Realiza o monitoramento
  end;
end;

When compiling your service, Delphi will create an executable file. To run the service you must first register it in the Service Control Manager. To do so, call your program with the /INSTALL parameter.

From there, it will be available in the Service Control Manager, and you can start or stop it through the Control Panel -> Services.

I hope I’ve helped.

Browser other questions tagged

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