System.NullReferenceException with unmanaged code wrapper

B

Bruce

I am using VC .NET 2003.

I created a simple unmanaged class in C++. The class is contained in a
library.

I then created a simple managed class wrapper that calls a function in
the unmanaged class. I am getting a System.NullReferenceException when
instantiating the unmanaged class. What is causing this error?

Unmanaged code:

class TestClass
{
public:
TestClass(void);
~TestClass(void);
int RetunTest(void);
};


TestClass::TestClass(void)
{
}

TestClass::~TestClass(void)
{
}

int TestClass::RetunTest(void)
{
return 10;
}


Managed Code:


#include "D:\Data\My Projects\VC\test\TestClass.h"

using namespace System;

namespace ManagedTest
{
public __gc class Class1
{
// TODO: Add your methods for this class here.
public:

Class1()
{
c = new TestClass(); //Error is occurring on this line
}
int CallUnmanged(void)
{
int x = c->RetunTest();
return x;
}

private:

TestClass *c;

};
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top