A
Amit Dedhia
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for this, I want to use
it. Is it possible to call Managed class functions from Unmanaged
class? How to do it?
I did something like this.
I declared a managed class (in C++ CLI) called as MyManagedClass whose
public interface has functions to write application data in XML format.
It internally uses ADO.NET classes to achieve this. This class is
declared in a seperate dll compiled with '\clr' option.
Now I created an unmanaged wrapper class which wraps the managed class
(defined in the same dll as that of managed class). The unmanaged
wrapper, call it as MyUnmanagedWrapper, has a data member declared as
gcroot<Object^> handleToManagedClass;
This is declared in the top of the class. It has wrapper methods whose
implementation is something like this:
void MyUnmanagedWrapper::Method1()
{
(*this)->Method1();
}
and then I have...
class MyApplicationClass
{
MyUnmanagedWrapperInstance.Method1();
}
Everything complies well. However, when the above method is run, I get
Access Violation error. It does not even go inside the method.
Can anyone tell why there is access violation?
Best regards
Amit Dedhia
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for this, I want to use
it. Is it possible to call Managed class functions from Unmanaged
class? How to do it?
I did something like this.
I declared a managed class (in C++ CLI) called as MyManagedClass whose
public interface has functions to write application data in XML format.
It internally uses ADO.NET classes to achieve this. This class is
declared in a seperate dll compiled with '\clr' option.
Now I created an unmanaged wrapper class which wraps the managed class
(defined in the same dll as that of managed class). The unmanaged
wrapper, call it as MyUnmanagedWrapper, has a data member declared as
gcroot<Object^> handleToManagedClass;
This is declared in the top of the class. It has wrapper methods whose
implementation is something like this:
void MyUnmanagedWrapper::Method1()
{
(*this)->Method1();
}
and then I have...
class MyApplicationClass
{
MyUnmanagedWrapperInstance.Method1();
}
Everything complies well. However, when the above method is run, I get
Access Violation error. It does not even go inside the method.
Can anyone tell why there is access violation?
Best regards
Amit Dedhia