Losing pointers embedded into class objects defined in DLLs

DLL A creates and object O whose class is defined in DLL B.

A is a Rhino plug in, B is a third party DLL (extension DLL).

A asks to object O to do some stuff, which implies allocating new space, and storing a pointer “pointer” into O.

When A tries to access pointer doing something this is wrong:

O->pointer->DoSomething() // NO!! IT FAILS !!!

The “pointer” has a completely wrong value.

Instead you must define a wrapper into DLL B, like:

OBJ * GetPointer()
return pointer;

and inside A you will do as follows:

O->GetPointer()->DoSomething() // OK WORKS !!!

This stopped me for a whole day. I hope it will be useful to someone else. BTW, I was helped by this doc:


It was really a surprise for me to notice such behavior.


1 Like