473,372 Members | 848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 1505
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Kantowitz | last post by:
I am trying to wrap a native-C++ DLL in managed C++, to use in a .NET project. The native code is compiled into a DLL, and I have created a .def file that exports the mangled names of the...
0
by: Arthur Roodenburg | last post by:
Hello, I have a huge set of unmanaged C++ classes, which I wrapped in managed C++. Everything is in one assembly. Using my wrapper in C# works fine. However, when I would like to use the...
0
by: Vinoth Kumar | last post by:
Hi I have created a unmanaged class in a header file UnManaged.h class UnManaged { UnManaged(){} ~UnManaged(){} void HelloWorld(){} };
2
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
0
by: Ola Sprauten | last post by:
I got a .NET class library project where I have written a managed wrapper for some unmanaged code. The managed wrapper is then used by a c# .net application. The problem I am having is that the...
0
by: Roth | last post by:
I have an unmanaged C++ dll that exports 2 classes and a stl list. I've had no trouble writting wrapper classes around the two exported classes with managed C++, but one class wants a list of...
1
by: roni | last post by:
hi. i have gc class written in manged c++ , some of his data members are __nogc pointers for arrays,structs.. and in that gc class methods i call to the unmaganged dll i wrap . my...
5
by: Lee Crabtree | last post by:
More fun wrapping unmanaged code... I have a class heirarchy that I need to expose to C#, so I need to wrap all the classes. That's not a big deal, except for the base class, which is abstract....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.