问题描述:

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

网友答案:

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.

相关阅读:
Top