3

From what I've read here one can compare two pointers to member functions for equality. However the article seems to cover only the case of a single executable without DLLs involved.

Is it possible to check if two functions are equal with DLLs? Let's say we have

class DLL A
{
public:
  virtual bool aaa();
};

and have a variable in DLL

bool DLL (A::*dllpointer)() = &A::aaa;

We also have a variable in executable

bool (A::*exepointer)() = &A::aaa;

When I try to compare the two like that

if (dllpointer == exepointer)

it works as if the two are not equal. Likely that's an expected behaviour, but I want to know if it's possible to overcome this limitation so that the comparison returns true

Community
  • 1
  • 1
Alex G
  • 307
  • 3
  • 7
  • A DLL is not a separate executable, it's just a library of functions. – Roger Rowland Apr 29 '13 at 13:22
  • I understand it. The exe links with the dll, but I'm asking why the pointers are not comparable for equality and how to overcome this – Alex G Apr 29 '13 at 13:24
  • While a DLL is not a separate executable, it will be mapped to another part of the address space of the executable. This explains why the pointers are not equal. How to overcome this however is out of my knowledge. Maybe by using some dynamic type information could you validate if both pointers points to a function with the same definition. – woodleg.as Apr 29 '13 at 13:28

1 Answers1

1

Comparing pointers (whether they are to member functions, member variables or anything else) will only tell you if the pointer points to the same thing or not - not if they are pointing at "different instances of the same thing that have the same properties". Since a member function of the "EXE's" class A can not possibly be the same function as the "DLL's" class A, since they are different implementations of a class called the same name, you can't expect the pointers to be the same. And no, there is no real way that you can solve that. You could compare the "contents" of the function, and see if the code is the same, but that requires knowing the length of the function, which is not an easy feat.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227