Just to make the difference clear:
If I understood you right, your initial question was whether it is possible
to use gcroot to call a managed object from unmanaged code.
If this was your initial question, then the answer is still no.
Your observation is a different one: You are calling a managed object from a
managed function of an unmanaged class. So in the end you are calling a
managed object from managed code.
Marcus
"Thorsten" <TK777@gmx.de> wrote in message
news:uGBAz5oxFHA.3856@tk2msftngp13.phx.gbl...[color=blue]
> HI Marcus
>
> thanks for your help!
>
> But the thing with gcroot<> actually works. I have a Class like this:
> __nogc class CSampleGrabberCallback : public ISampleGrabberCB
> {
> public:
> gcroot< DirectX::TK::Video*> m_pVideo;
> }
>
> After I set the m_pVideo variable I can call out of the
> CSampleGrabberCallback any function out of the managed class Video.
>
> Cheers
> Thorsten
>
> <- C# is heaven compare to managed/unmanaged C++ ;-) ->
>
> "Marcus Heege" <NOSPAM@heege.net> wrote in message
> news:OI7GajoxFHA.4032@TK2MSFTNGP15.phx.gbl...[color=green][color=darkred]
>>> 1) I have two classes defined in two header files, it is possible to
>>> have a member from the other class? My problem is that as soon as I
>>> include the other header file I get linking errors. See example below.[/color]
>>
>> If you are just declaring pointers of a class, there is no need to
>> include it. A forward reference is enough:
>> <code>
>> class CUnmanaged;
>>
>> #pragma once
>>
>> // #include "Unmanaged.h" <- no need to include unmanaged.h here
>>
>> namespace Test
>> {
>> public __gc class CManaged
>> {
>> CUnmanaged* m_Unmanaged;
>> public:
>> CManaged();
>> void DoSomeThing();
>> };
>> }
>> </code>
>>[color=darkred]
>>> 2) It is possible to call from unmanaged code a managed instance of a
>>> class? I can use GCHandle class to extract a fixed pointer to the
>>> managed class but how do I cast this pointer in my unmanaged class to a
>>> "managed" class instance? Or it is better to use the template
>>> gcroot<ManagedClass*>?[/color]
>>
>> Neither GCHandle nor gcroot can be used to call from unmanaged code to an
>> instance of a managed class. They allow you to have a member variable of
>> an umanaged class that refers to an instance of a managed object.
>>
>> To achieve what you want, have a look at other recent threads [1], [2] in
>> this newsgroup for details.
>>
>> [1]http://groups.google.com/group/microsoft.public.dotnet.languages.vc/browse_thread/thread/6014ee0a87a1a61b/1da4e633322dda9d#1da4e633322dda9d
>> [2]
>>
http://groups.google.com/group/micro...439de50486887f
>>
>>[/color]
>
>[/color]