Active DLL Delphi

3

I have a DLL and it is activated like this:

Rundll32 MinhaDll.dll

Starts after the command, processes, and exits.

I need it to continue in memory by monitoring certain processes.

The only way to keep it active I found was by doing:

repeat application.processmessage until false; 

But processing is always 100%.

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

In summary, I need to load a DLL when starting Windows and unloading when it is turned off.

    
asked by anonymous 13.09.2014 / 04:24

1 answer

2

DLLs are dynamic link libraries, that is, they are loaded the moment a program or another DLL references it during execution.

As I understand the above problem, you need a program that performs a procedure every 1 second. The best way I know of doing this in Windows is by creating a service and registering it in Service Control Manager.

There is this tutorial link

Services are programs without graphical interface (because 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 for 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 startup class - Start and Stop - They will be called by Windows to start and stop the service, respectively. It's up to you to implement what your service will do at startup.

As it requires 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 Service Control Manager. To do this, 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 have helped.

    
04.01.2015 / 18:36