A potential implementation to avoid this is to:
- define a custom interface that returns a pointer to the Material Object (e.g. in a low and high integer part)
- implement this interface on the material object
- in CopyFromMaterial, query source for your custom interface
- if it is not there, return an error stating that you cannot copy from a foreign material object
- if obtained, get the pointer via your custom function
- use a C++ cast to cast it to your material object
- talk to the thing directly
A slightly simpler implementation is:
- QI source for ICapeInterface, this pointer is unique
- cast it using C++ machinery to your material object (have a look at the returned pointer from the debugger, you can probably directly figure out how to cast it from there)
Note that the second implementation does not guard against the potential pitfall of the object being casted is not actually your own material object implementation, which will subsequently surely lead to a crash, but under 'normal' conditions this should not happen.