Function from one DLL calling the function of the same name with another dll

I have a peculiar problem. I have two DLLs, call them DLL-A and DLL-B.

DLL-A has a function named f1() , and DLL-B also has a function with the same name, f1() . Now in dll-a f1() calls f1() dll-b like this.

Dll-a

 f1() { f1(); //this is DLL-B function, but having the same name } 

Now my question is, will it be a recursive call to f1() from DLL-A?

+6
source share
5 answers

f1() inside the body of the function calls itself, leading to infinite recursion, as you suspected. Some possible solutions:

  • Place the imported DLL function in a separate namespace so that you can distinguish its name.
  • Change the names of these functions to avoid a collision.
  • Import explicitly, not implicitly, using GetProcAddress . This allows you to call the imported function anything.
+7
source

You can change the function name in DLL-A to A_f1 .

 A_f1() { f1() //this calls DLL-B f1 } 

In your DEF file write

 EXPORTS f1 = A_f1 

This says: "A function internally called A_f1 must be exported under the name f1 to other components." That way, everyone who used DLL-A and calls f1 (expecting to get function A) will get A_f1 .

I assume that renaming exported functions is not possible. If possible, then this is a much cleaner solution. (I assume this is not possible because you are trying to hack a video game.)

+5
source

They, as you wrote, f1 inside f1 will not call DLL-B, but be infinite recursion. If you want to call the DLL-B function, you will need to use GetProcAddress

+3
source

You should get a compiler or linker error if you link two object files that export the same character. Something like "multiple definition for f1 () character".

This, of course, if you include in one dll a header that declares another function or binds two binaries together.

To eliminate this, put functions in namespaces.

+2
source

Perhaps you can change the name:

 #pragma comment(linker, "/export: MyFunc=_MyFunc@8 ") 
+2
source

Source: https://habr.com/ru/post/902949/


All Articles