Is possible to have a managed method within a Native(un-managed) class within a \clr project
E.g.
class myClass
{
public:
#pragma managed
void myMethod(void);
};
I get an error when attempting to compile above about #pragma managed must be used at global scope! Is there some way to achieve this
If not, why not
Thanks in advance.

Managed method in native class
Drir Sinan
But this would be a mountain of work because of header dependencies etc.
I really require the inverse of this...
I need to iterate through a large collection of MFC derived objects via a common interface, something like:
void Convert2DotNet( DotNetConversionContext& );
For each MFC class implementing this method, this method will be compiled managed, all the other methods will remain native.
In this method i will reference native member data and create new managed classes, these new classes will eventually be serialized in .NET format.
If its not possible then i know i have to come up with some horrid functional solution - which is alot of work also, much of it messy.
If its not currently possible, i dont see why this cannot be made available as it would be the most expressive for me.
Thanks.
underdog
Its interesting to note that given
//myClass.h
class myClass
{
public:
void myMethod(void);
// myClass.cpp
#pragma unmanaged
void myClass::myMethod(void)
{
errors.
But if i compile the module unmanaged with a \clr project and then
// myClass.cpp
#pragma managed
void myClass::myMethod(void)
{
Why cannot this be made to work
Please help...
Daniel.K
I have since resolved this problem, exactly as you have stated.
Thanks.
Deforge
If I understand C++/CLR correctly, classes must be either managed or unmanaged, they can't be mixed. If you want to mix them, you require the use of external helper functions or maybe you can mix managed and unmanaged in managed classes, I'm not too sure on this point though.
DRD
If you want a particular member function to be managed, you can define it outside of the class with #pragma managed, as you've already shown. If other parts of the file should not contain managed code, I'd suggest moving that function to another file that can be compiled with /clr.