468,511 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,511 developers. It's quick & easy.

Problem wrapping unmanaged dll

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

Nov 17 '05 #1
1 1276
js*******@highstream.net wrote:
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 [ . . . ]


Hi Steve. I haven't looked closely at your code, but whenever using
mixed-mode C++ you should be aware of the issues described in this article:

Mixed DLL Loading Problem
http://msdn.microsoft.com/library/de...ingProblem.asp

This issue can manifest in almost any way, so it may be responsible for your
issue. I hope this helps.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by David Kantowitz | last post: by
reply views Thread by Arthur Roodenburg | last post: by
reply views Thread by Roth | last post: by
1 post views Thread by roni | last post: by
5 posts views Thread by Lee Crabtree | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.