Problem with unmanaged pointer in managed c++



Hello all from a newby!

I have a class written in unmanaged c++ that does exactly as i want it
to. I have a corresponding wrapper class in managed c++, and testing it
elsewhere within the managed code, the wrapper classes seem to function
correctly. However, when i create one of these classes in c#, i can use
the functions etc, but it blows up later on when it hits the delete
inside the finalize and gives me the following "Unhandled exception at
0x03c2aa13 in RD.exe: 0xC0000005: Access violation reading location
0xcdcdcdcd." Any ideas what could be causing this? The back end seems
to work properly, and the wrapper class seems to work also, but as soon
as it's brought into c#, it blows up!


using namespace RD::Utils_win;

/// <summary>Constructor</summary>
Category::Category(RD::Utils::Category* pCategory) :
m_pCategory(pCategory)
{
}

/// <summary>Constructor</summary>
Category::Category() :
m_pCategory(new RD::Utils::Category())
{
}

/// <summary>Destructor.</summary>
Category::~Category()
{
delete m_pCategory;
m_pCategory = NULL;
}

/// <summary>Finalize.</summary>
Category::!Category()
{
delete m_pCategory;
m_pCategory = NULL;
}

.



Relevant Pages

  • Re: calling cpp file from c#
    ... I defined two wrapper classes and I want to use ... one of these class to construct an instance the other wrapper class. ... error: NewNamespace::Class1 cannot be converted to Class1 ... Is there anybody whoe know why it not works? ...
    (microsoft.public.dotnet.languages.csharp)
  • Image Scanner w/ ScanCAPI
    ... I am writing a wrapper class to capture images with a motorola scanner. ... We currently have wrapper classes for the regular barcode scanning. ... either any insight or example C# code. ...
    (microsoft.public.dotnet.framework.compactframework)