I have one unmanaged and one managed class in the same vc++ project. Managed
object creates one instance of unmanaged class and needs to pass a callback
reference so that unmanaged class can periodically call the managed class's
method (without holding the reference to the managed object).
Can anybody please provide me with a short example or a basic idea?
Thanks a lot,
Sasha
Hi Sasha Nikolic,
> I have one unmanaged and one managed class in the same vc++ project.
> Managed object creates one instance of unmanaged class and needs to
> pass a callback reference so that unmanaged class can periodically
> call the managed class's method (without holding the reference to the
> managed object).
How should the unmanaged class know with managed object to call if you do
not want to store the reference in the unmanaged object?
TO stare an managed object-reference in unmanaged code, you can use the
gcroot template.
See: Consuming Unmanaged C++ Class Libraries from .NET Clients
http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/
See: 16.3 __gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vcmxspec/html/vcManagedExtensionsSpec_16_3.asp

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Sasha Nikolic - 30 Nov 2004 08:06 GMT
Thanks Jochen, codeguru example is excellent! I needed very similar
solution.
> Hi Sasha Nikolic,
>
[quoted text clipped - 16 lines]
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/vcmxspec/html/vcManagedExtensionsSpec_16_3.asp