VC7 - Warning C4669 - mixing unmanaged an managed classes

  • Thread starter Thread starter Morten Overgaard
  • Start date Start date
M

Morten Overgaard

Hi

I'm getting the following warning

warning C4669: 'reinterpret_cast' : unsafe conversion: 'CMFCShellDoc' is a
managed type object

CMFCShellDoc is derived from COleServerDoc which is NOT managed. The
CMFCShellDoc does have properties which is of type gcroot<managedClass*>.

My app works as expected - but do I have to take these warnings serious or
is it a bug??

I saw another posting about this but no usable reply was posted by MS

http://groups.google.com/groups?hl=...&ie=UTF-8&oe=UTF-8&q=unsafe+conversion+%2FCLR

Regards Morten
 
Hi Morten,

Thanks for your focus on VC.NET,

My opinion is if you don't use the managed property of type
gcroot<managedClass*>, just take the warning message as helpful(probably)
reminder better than nothing.

By the way, I don't think its a bug, the CMFCShellDoc does really have one
managed property,

However, let's wait the community members' valuable ideas...


Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Hi Gary

So - we meet again :-)

I do use the gcroot<managedClass*> in my CMFCDoc class since this is the
only way as I can keep references to managed objects from unmanaged objects
besides using com interop.
So are you saying that the gcroot class template should not be used -
because it has some nasty side effects??

Regards morten
 
Hi Gary

Can you please send me the project that you have developed - I would like to
see it work with my own eyes :-)

Regards Morten
 
Hi Morten,

Thanks for your quickly response!
So are you saying that the gcroot class template should not be used -
because it has some nasty side effects??

What I mean is if you don't use the gcroot class template feature in your
program, you can ignore the warning message.

And mean time, I also consult a VC design engineer with your problem, his
opinion is:

"This warning should fire if the managed class(destination or source type
in the cast) has gc pointers (managed members) , It should not fire for a
class that only has a gcroot¡­since then the class is still unmanaged..

The original warning intends to inform the user that casting a class with
managed members is dangerous since no runtime check is being done..Well
anyways, u always better know what you are doing if you are reinterpret
casting instead of dynamic/static cast"

Hope that helps!


Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top