delphi - Dynamicly handle not defined functions in a dll in dlephi -


I have a DLL that defines a simple task to display the message:

 < code> library testdll; Uses SysUtils, Classes, Dialogues; {$ R * res} Process ShowDll; Stdcall; Start ShowMessage ('ShowDLL testdll.dll'); End; Export ShowDLL; The initial end   

and my main file calls this process dynamically:

I have defined a new type:

 < code> type testdll = process; Stdcall;   

Then click on my button Event:

  Process TForm1.Button1Click (Sender: Tubbed); Var dllHandle: Thandal; // Do not use cardinals; It is limited to 32-bit tests: testdll; Start dllHandle: = LoadLibrary ('testdll.dll'); If dllHandle & lt; & Gt; 0 then start @test: = GetProcAddress (dllHandle, 'ShowDLL'); If assigned (test) then ShowDLL and ShowMessage ('function not found'); End Show Message ('DLL Not Found'); End;   

This works but I do not know whether it is not possible to handle the task defined with my DLL. My purpose here is to call without any function, if it will be defined in my DLL. So let me tell you if the work is present or not, then tell me.

For example here I have only one ShowDLL process if I call any other method that does not exist then it will show 'no fault' from my main application. . But I will tell my Dell to me. Is this possible? If so, how can I achieve this?

EDIT: I can not modify the main function. This is only a test. Only DLL will be in my final version. So exporting all the functions in my main application is not possible here. This is the reason why I want to know the ID that DLL alone can handle it instead of doing it in my main application, which I can not do.

I do not have any records on the main app to modify any of its code. I only know which functions in this application will be used which I will later export to my DLS using the export statement, what I am trying to achieve, if it If possible, do not hold any defined function with dll.

Your code already shows how to detect the presence of an export i.e. To call GetProcAddress and compare the result with Zero .

You can reduce the amount of boiler plate code by loading the delay. This essentially generates the compiler code, which checks. This depends on the delayed keyword

  process testdll; Stdcall; External 'testdll.dll` is delayed;   

When you call this function, it can not be found, the exception has been raised. Actually, this behavior can be customized, as described in the document:

Update

In a comment on this reply, you say that Executable can not be changed. In that case, the message that you want to avoid will be shown that the function is unavailable. You will ask whether the missing export can be controlled by DLL, but this is not possible. When you call GetProcAddress , no code is executed inside the DLL. All processing is done by reading the PE metadata to the outside part of the DLL.

The obvious conclusion is that the DLL function should be exported. If the correct DLL does not do, then enter another DLL instead. Use an interpozzer DLL which exports the function. Apply the true function by handing it to DLL, if the right DLL exportes the function, otherwise do anything, whatever you please

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -