1
votes

I have two applications in Delphi for which I don't have any code source:

I use an interface from application A to call an DLL file from application B. Example, I usually pass a service number, 200011, from interface A to call DLL file B for a value return. But, recently the application A have changed the variable. I have to add P00200011 to call DLL file B.

I have tried to create an DLL C#, but the DLL in B is created with the fastcall convention and I cannot change this DLL file.

What are others ways I can do it? I'm out of ideas.

2
This question is rather unintelligible. Pleas try to make it clear what you are asking. What I would say is that fastcall is an MSVC calling convention. Do you perhaps mean Delphi register convention? - David Heffernan

2 Answers

2
votes

You need to write a wrapper DLL. You build your DLL with the functions you want to intercept, and in your code you simply load and call the original DLL. Then you place your wrapper in the same directory of your application. All calls from the application will go to your wrapper DLL and from there to the original DLL.

Here is a simple example

supose you have this library (B.DLL)

library B;
function B_FUNCTION(value:integer): integer; export;
 begin
  result:=value+1;
 end;
exports B_FUNCTION;
end.

And this program that uses it

program A;
{$apptype console}
function B_FUNCTION(value:integer): integer; external 'b.dll';
var i:integer;
begin
  i:=B_FUNCTION(2010);
  writeln(i);
end.

Compile both programs and run them. The result printed is 2011.

Now, code your wrapper DLL

library w;
uses windows;
function B_FUNCTION(value:integer): integer; export;
 var 
  adll: Thandle;
  afunc: function(v:integer):integer;
 begin
  adll:=LoadLibrary('TRUE_B.DLL');
  afunc:= GetProcAddress(adll,'B_FUNCTION');
  result:=afunc(value+1);
  FreeLibrary(adll);
 end;
exports B_FUNCTION; 
end.

Build it, you'll have A.EXE, B.DLL and W.DLL. Replace them

REN B.DLL TRUE_B.DLL
REN W.DLL B.DLL

Execute A, now it will spit 2012.

0
votes

It's not entirely obvious to me which parts are yours and what calls what, but you should be able to create your own intermediate DLL in Delphi with an interface that uses fastcall and which forwards the call to the real DLL using another calling convention.