I\'m new to C++. I have been told using a \"callback\" with C++ is the best solution for this. Here is my situation.
I have a DLL written in C++
this DLL has
A callback is simply a particular use of a delegate. The normal model looks something like this:
public class MyCaller
{
public OtherClass otherClassInstance;
public void CallbackMethod() {...}
public void UsesTheCallback()
{
//The callback method itself is being passed
otherClassInstance.MethodWithCallback(CallbackMethod);
}
}
public class OtherClass
{
public delegate void CallbackDelegate()
public void MethodWithCallback(CallbackDelegate callback)
{
//do some work, then...
callback(); //invoke the delegate, "calling back" to MyCaller.CallbackMethod()
}
}
The beauty of this model is that any method with the defined "signature" (parameters and return type) can be used as the callback. It's a form of "loose coupling", where code isn't dependent on knowing what an object IS, only what it DOES, so that object can be swapped out for another object without the code knowing the difference.
The above example is all in C#. When you're using extern functions from a C++ DLL, you'll probably be dealing with an IntPtr type that is a simple pointer to the method. You should be able to "marshal" this pointer as a delegate when defining the C# interface to that extern method, so the method will look like a normal C# method.