المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Using void* to keep track of an external object.



C++ Programming
09-10-2009, 06:25 PM
Here is a void* problem to challenge you. I have a very large application A. Sometimes it needs to use a little application B. B instantiates an external dll I didn't write, we can call it G. B uses DllExport to export some functions I can call with DllImport. Whenever I call B it makes a new G and deletes it again. Fine.

Now they changed the rules. I can only have one G. Easy, I think. Add an Init function to B's external interface, call it to instantiate my single instance of G. Return a void* to B, so whenever I want to call it it reuses the instance of B and thus of G. A is not allowed to know what happens in B, so the void* is perfect. I keep void* mPointerToB as a member of A.

B has some internal classes, we can call one ClassM. So B contains a member ClassM mM. When I hop into B it runs for a while until it tries to call mM.function. Then I get a buffer overrun.

So I googled and found this statement. "A void pointer cannot point to a class member in C++." Is my void pointer to B losing its internal objects along the way? Where can I find out more? Am I doing this in the wrong way?

This is C++ in Visual Studio 2008. I use void* in other places to access pointers to things in Ada functions in the same way, so it should work, I think.

-------------
Ave computer! Hackitura te salutat!
(I just made this up. Just to show you can hack Latin as well as C++.)