Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
A user named Andrew Brock has been helping me out immensely with a problem I am having with calling from DLLs to EXEs Calling to an EXE function from inside a DLL[^]

However, I am trying to implement it. But, no matter how much I try, I keep getting strange errors in the worst timings! So, I decided to open a new thread. I badly need to understand how callback operates before I can go ahead and apply it!

What I cannot understand is the following:
* The original problem that callback functions are supposed to fix enabling another function to call some other function that is out of its reach, right?
funcA()--X-->funcC()
so
funcA()--funcB()-->funcC()
funcA calls to funcB while passing funcC as a function pointer parameter. Hence, funcA can call to funcC.
Am I OK so far?

What I cannot understand is this:
funcA doesn't know the address of funcC, right? (at least in my case it doesn't since funcA is in the DLL and funcC is in the EXE.).

So my question is how on earth can funcA pass the address of funcC that it doesn't know of??? GGHHHHAAAAAAAAAAAA!!!! this is bending my mind.......!!!!!!!
Posted
Updated 10-Feb-11 1:37am
v2

But if your idea starts of with funcA in the dll without the callback you are too late because, as you mention yourself, the dll cannot reach functions in the exe at compile time. This means that you have to give the function address as a parameter along with the others in funcA.

So funcA in the dll can callback to the given function of funcB because you supply it with the address of that function when calling it from the exe.
void funcA(funcB_callback funcB, ...)
{
  funcB(...);
}


So it can work because the function definition (or signature) is known in both exe and dll and you provide the dll with the runtime function pointer at runtime so the dll can actually call it.

It is just like using the EnumWindows winapi where you also provide it a callback function pointer that is called for each window.
http://msdn.microsoft.com/en-us/library/ms633497%28v=vs.85%29.aspx[^]

Good luck!
 
Share this answer
 
v2
funcA doesn't know the address of funcC

Sounds like a pretty clear answer to your problem. If I told you to deliver a parcel to my house how would you find it without knowing the address?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900