By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,350 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,350 IT Pros & Developers. It's quick & easy.

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

P: n/a
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::GetInstance()
{
//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.
_CrtIsValidHeapPointer(pUserData).

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.edu
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.edu> wrote in message
news:O7**************@tk2msftngp13.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::GetInstance()
{
//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.
_CrtIsValidHeapPointer(pUserData).

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.edu

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.