473,837 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem calling unmanaged C++ Library from C# through managed wrapper

I have an unmanaged C++ library that I need to use through C#. I created a
Managed C++ class library and through it wrote a wrapper class to call what
I need.
However, one of the methods (an Initialize function in the unmanaged
library) crashes everytime I call it. Initialize calls another function
'GetInstance' (a static member function of a class) which looks something
like:
CLibConfig& CLibConfig::Get Instance()
{
//Our instance (to avoid singleton problems!)
static CLibConfig sInstance; <--------

//Return it
return sInstance;
}

It is on the static sInstance line that I get a debug assertion.
in dbheap.c, Line1291.
_CrtIsValidHeap Pointer(pUserDa ta).

The static line is the last line from the call stack within the C++ library,
from there it goes into the C runtime. Any suggestions?
--
Adam Clauss
ca*****@tamu.ed u
Nov 17 '05 #1
1 7166
After doing something similar to use th Windows Media Format SDK in managed
code I learn that the best one can do is let the unmanaged code in unmanaged
world :-) The problem of initialization of unmanaged static variables can
arise frequently as manged functions that need CRT initialization because
the initialization code don't run when compiled to produce managed code.
What I advise is wripper your wrapper as COM object(s) or make all include
all your unmanaged library in an unmanaged DLL that you can use by your
managed wrapper.

Hope this can helps, if you are interesting in what I did you can look it
at: http://www.thecodeproject.com/userit...Compressor.asp (the url can
change in the future)

Best regards,
Idael.

"Adam Clauss" <ca*****@tamu.e du> wrote in message
news:O7******** ******@tk2msftn gp13.phx.gbl...
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need.
However, one of the methods (an Initialize function in the unmanaged
library) crashes everytime I call it. Initialize calls another function
'GetInstance' (a static member function of a class) which looks something
like:
CLibConfig& CLibConfig::Get Instance()
{
//Our instance (to avoid singleton problems!)
static CLibConfig sInstance; <--------

//Return it
return sInstance;
}

It is on the static sInstance line that I get a debug assertion.
in dbheap.c, Line1291.
_CrtIsValidHeap Pointer(pUserDa ta).

The static line is the last line from the call stack within the C++ library, from there it goes into the C runtime. Any suggestions?
--
Adam Clauss
ca*****@tamu.ed u

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1422
by: Brett | last post by:
We have an application completely written in C++ under visual studio v6. One of our customers wants to use some of our existing components in his project but doesn't know C++ and isn't interested in learning it. He does know C# and VB though. Whats the best option for us (ie. minimum work) to provide him with an API that he can use in his own applications? I was originally considering a COM interface, but looking into .NET, I'm wondering...
9
18048
by: Andrew Cumming | last post by:
I am having trouble using Platform Invoke to call C++ DLLs from C# windows applications. The DLLs seem to load, but I get run-time errors to the effect that the named entry points cannot be found. The DLLs are compiled in MS Visual C++ Version 6 and the C# applications are written in MS VS C#.NET 2003. I am using the specifier _declspec(dllexport) for a class in the DLL and I am using DllImport(...) for each method imported into the C#...
0
2109
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 unmanaged code relies heavily on LoadString to load strings from a resource string table. I added a string table to the .NET class library project, and added all the necessary entries, but it all fails when it when it calls AfxGetResourceHandle()....
4
9883
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code can use the same business logic as our C++ client. Here are some questions: 1) Is there a way to call into native C++ classes directly? Meaning we do not have C API. I believe we could use a C API using the in C#. 2) If can't do #1, do we need...
0
3947
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
4
2251
by: SteveK | last post by:
**Newbie with managed C++** I'm trying to wrap an unmanaged C++ class in a managed C++ class library. When I instantiate the wrapper class it's ctor calls the ctor on the unmanaged class and at that point I get the exception: "An unhandled exception of type 'System.StackOverflowException' occurred in suabwrapper.dll" I have been able to reproduce this with an unmanaged class that is VERY simple:
9
3126
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
9
3569
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The 3rd party unmanaged DLL will pass this reference into standard Win32 unmanaged static callback function in my code. Inside this unmanaged callback function I need to cast this unmnaged pointer that I have received from 3rd party back into the...
1
4544
by: Kenneth Porter | last post by:
I have an unmanaged library that can accept an instance of an abstract class and call back into it. I'm writing a wrapper for this library. How do I wrap a managed callback in a class derived from the unmanaged class to pass to the library? I tried creating a managed class that carries an unmanaged callback class which calls back into the managed class, but I can't put a handle to the unmanaged class in the unmanaged class. (I get...
0
9695
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10902
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.