J
jsroberts
I have been desperately trying to solve a problem where I am wrapping
an unmanaged dll with managed extensions for c++ and then calling the
managed dll functions from C#. However, whenever I call the new
operator to create a new instance of the unmanaged class, I get the
following error:
An unhandled exception of type 'System.NullReferenceException' occurred
in objectblox.epsilon.dll
Additional information: Object reference not set to an instance of an
object.
Below is the code that I have written. Also, please note that this does
work in Debug mode but not in release mode.
//////////////////////////////////////////////////////////////////////////
This is the C# code
//////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using ObjectBlox.Epsilon;
namespace HelloWorldTutorial
{
public class EntryPoint
{
[STAThread]
public static void Main(string[] args)
{
String configFile = "config.xml";
Application app = new Application();
}
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
This is the managed c code
//////////////////////////////////////////////////////////////////////////
----Application.h----:
#pragma once
#pragma unmanaged
#include "dtABC\application.h"
#pragma managed
namespace ObjectBlox
{
namespace Epsilon
{
public __gc class Application
{
private public:
dtABC::Application __nogc *pApp;
public:
Application();
~Application();
};
}
}
----Application.cpp----:
#include "Application.h"
#include <vcclr.h> // for PtrToStringChars
namespace ObjectBlox
{
namespace Epsilon
{
Application::Application()
{
this->pApp = __nogc new dtABC::Application();
}
Application::~Application()
{
}
}
}
Any clue as to what is going on? I have spent too much time trying to
figure this out. Thanks for any light you can shed on this.
Steve Roberts
an unmanaged dll with managed extensions for c++ and then calling the
managed dll functions from C#. However, whenever I call the new
operator to create a new instance of the unmanaged class, I get the
following error:
An unhandled exception of type 'System.NullReferenceException' occurred
in objectblox.epsilon.dll
Additional information: Object reference not set to an instance of an
object.
Below is the code that I have written. Also, please note that this does
work in Debug mode but not in release mode.
//////////////////////////////////////////////////////////////////////////
This is the C# code
//////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using ObjectBlox.Epsilon;
namespace HelloWorldTutorial
{
public class EntryPoint
{
[STAThread]
public static void Main(string[] args)
{
String configFile = "config.xml";
Application app = new Application();
}
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
This is the managed c code
//////////////////////////////////////////////////////////////////////////
----Application.h----:
#pragma once
#pragma unmanaged
#include "dtABC\application.h"
#pragma managed
namespace ObjectBlox
{
namespace Epsilon
{
public __gc class Application
{
private public:
dtABC::Application __nogc *pApp;
public:
Application();
~Application();
};
}
}
----Application.cpp----:
#include "Application.h"
#include <vcclr.h> // for PtrToStringChars
namespace ObjectBlox
{
namespace Epsilon
{
Application::Application()
{
this->pApp = __nogc new dtABC::Application();
}
Application::~Application()
{
}
}
}
Any clue as to what is going on? I have spent too much time trying to
figure this out. Thanks for any light you can shed on this.
Steve Roberts