A
andrew.bell.ia
Hi,
I'm trying to put together some managed and unmanaged code. Everything
works fine until the program exits, and I suppose the garbage collector
runs to finalize things. Then I get:
Unhandled Exception: System.NullReferenceException: Object reference
not set to
an instance of an object.
at Tab.MCell.Finalize()
I can't think why I would get a NullReferenceException in managed code.
Any ideas greatly appreciated.
The std::list is in unmanaged code:
#include <list>
#include <math.h>
using namespace std;
namespace Tab {
class __declspec(dllexport) Cell
{
private:
int _row;
int _col;
list<int> _vals;
...
};
}
The managed code looks like:
#using <mscorlib.dll>
#include "Cell.h"
using namespace std;
using namespace System::Collections;
namespace Tab {
public __gc class MCell
{
//
// DATA
//
private:
Cell __nogc *_cell;
//
// FUNCTIONS
//
public:
MCell(Cell *c)
{ _cell = c; }
MCell(int row, int col)
{ _cell = new Cell(row, col); }
~MCell()
{ _cell->~Cell(); }
....
};
}
The unmanaged code is built with the following which makes a DLL (the
8.3 directories are just where the stl stuff is on my machine):
cl -GX -I"C:\PROGRA~1\MIA4C6~1\include" Cell.cc /LD /link
/libpath:"C:\PROGRA~1\MIA4C6~1\lib"
The executable gets built with:
cl -GX -I"C:\PROGRA~1\MIA4C6~1\include" /clr CTest.cc /link
/libpath:"C:\PROGRA~1\MIA4C6~1\lib" Cell.lib
Thanks in advance!
-- Andrew Bell
(e-mail address removed)
I'm trying to put together some managed and unmanaged code. Everything
works fine until the program exits, and I suppose the garbage collector
runs to finalize things. Then I get:
Unhandled Exception: System.NullReferenceException: Object reference
not set to
an instance of an object.
at std.list said:.clear(list<int,std::allocator<int> >* )
at std.list said:._Tidy(list<int,std::allocator<int> >* )
at Tab.MCell.Finalize()
I can't think why I would get a NullReferenceException in managed code.
Any ideas greatly appreciated.
The std::list is in unmanaged code:
#include <list>
#include <math.h>
using namespace std;
namespace Tab {
class __declspec(dllexport) Cell
{
private:
int _row;
int _col;
list<int> _vals;
...
};
}
The managed code looks like:
#using <mscorlib.dll>
#include "Cell.h"
using namespace std;
using namespace System::Collections;
namespace Tab {
public __gc class MCell
{
//
// DATA
//
private:
Cell __nogc *_cell;
//
// FUNCTIONS
//
public:
MCell(Cell *c)
{ _cell = c; }
MCell(int row, int col)
{ _cell = new Cell(row, col); }
~MCell()
{ _cell->~Cell(); }
....
};
}
The unmanaged code is built with the following which makes a DLL (the
8.3 directories are just where the stl stuff is on my machine):
cl -GX -I"C:\PROGRA~1\MIA4C6~1\include" Cell.cc /LD /link
/libpath:"C:\PROGRA~1\MIA4C6~1\lib"
The executable gets built with:
cl -GX -I"C:\PROGRA~1\MIA4C6~1\include" /clr CTest.cc /link
/libpath:"C:\PROGRA~1\MIA4C6~1\lib" Cell.lib
Thanks in advance!
-- Andrew Bell
(e-mail address removed)