473,604 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unmanaged C++ DLL with STL causes crash

We are in the process of creating a managed C++ library to wrap some
existing unmanaged code. The unmanaged code makes use of the STL. We
are seeing NULL pointer exceptions whenever we construct our unmanaged
object. If we remove the dependency on STL in the unmanaged code the
crash goes away. Also, we can always instantiate the unmanged object
the first time but it fails on subsequent attempts. The managed code
is pretty simple. has anyone else seen this behavior?
// SimpleManaged.h

#pragma once

#include "./import/simpleunmanaged .h"
#pragma comment(lib, "./import/simpleunmanaged .lib")
public __gc class CSimpleManaged
{
private:
CSimpleUnmanage d __nogc* m_pSimpleUnmana ged;

public:
CSimpleManaged( void)
: m_pSimpleUnmana ged(new CSimpleUnmanage d())
{
}

~CSimpleManaged (void)
{
//System::Console ::WriteLine(S"~ CSimpleManaged" );
if(NULL != m_pSimpleUnmana ged)
{
delete m_pSimpleUnmana ged;
m_pSimpleUnmana ged = NULL;
}
}

int Sum(int p_iData)
{
int rc = m_pSimpleUnmana ged->Sum(p_iData) ;
return(rc);
}

System::String* Concat(System:: String* p_strData)
{
System::IntPtr ipStrData =
System::Runtime ::InteropServic es::Marshal::St ringToHGlobalUn i(p_strData);
wchar_t* pszData = static_cast<wch ar_t*>(ipStrDat a.ToPointer());

wchar_t* pszResult = m_pSimpleUnmana ged->Concat(pszData );
System::String* strResult = new System::String( pszResult);

System::Runtime ::InteropServic es::Marshal::Fr eeHGlobal(ipStr Data);

return(strResul t);
}
};
Nov 17 '05 #1
1 3298
Well, mixed mode DLLs are linked without an entry point so _DLLmainCRTStar tup is not being called and CRT is not being initialized so static variables are not set, it is possible that the STL classes used by you use some static variables, if those variables are not initialized you would probably get errors during runtime, a detailed explanation of how to resolve this problem could be fond at the following URL: http://msdn.microsoft.com/library/de...omixedmode.asp

--
Nadav
Sofin l.t.d.

"Kurt Smith" wrote:
We are in the process of creating a managed C++ library to wrap some
existing unmanaged code. The unmanaged code makes use of the STL. We
are seeing NULL pointer exceptions whenever we construct our unmanaged
object. If we remove the dependency on STL in the unmanaged code the
crash goes away. Also, we can always instantiate the unmanged object
the first time but it fails on subsequent attempts. The managed code
is pretty simple. has anyone else seen this behavior?
// SimpleManaged.h

#pragma once

#include "./import/simpleunmanaged .h"
#pragma comment(lib, "./import/simpleunmanaged .lib")
public __gc class CSimpleManaged
{
private:
CSimpleUnmanage d __nogc* m_pSimpleUnmana ged;

public:
CSimpleManaged( void)
: m_pSimpleUnmana ged(new CSimpleUnmanage d())
{
}

~CSimpleManaged (void)
{
//System::Console ::WriteLine(S"~ CSimpleManaged" );
if(NULL != m_pSimpleUnmana ged)
{
delete m_pSimpleUnmana ged;
m_pSimpleUnmana ged = NULL;
}
}

int Sum(int p_iData)
{
int rc = m_pSimpleUnmana ged->Sum(p_iData) ;
return(rc);
}

System::String* Concat(System:: String* p_strData)
{
System::IntPtr ipStrData =
System::Runtime ::InteropServic es::Marshal::St ringToHGlobalUn i(p_strData);
wchar_t* pszData = static_cast<wch ar_t*>(ipStrDat a.ToPointer());

wchar_t* pszResult = m_pSimpleUnmana ged->Concat(pszData );
System::String* strResult = new System::String( pszResult);

System::Runtime ::InteropServic es::Marshal::Fr eeHGlobal(ipStr Data);

return(strResul t);
}
};

Nov 17 '05 #2

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

Similar topics

2
489
by: Neil | last post by:
I am developing a demo in C# using Managed DirectX. I wanted to use a C++ static library in the demo (its a class for handling physics), so I decided to create my Graphics classes in C#, inherit from them in MC++. So far so good...... I modified my MC++ project to run as mixed mode (removed nochkclr.obj, added msvcrt.lib, etc etc), and created 2 unmanaged classes which handled the calls to the static lib (btw all the code works fine in...
8
6451
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable .mdb. The query below query runs correctly and without error, but any attempt to save it causes Access to crash without a message, leaving the .ldb file. Opening the DB reveals it saved a blank "query1". I've upgraded to Jet SP 8, and I'm running...
11
2328
by: Yoni Rabinovitch | last post by:
Is it possible to invoke a C# delegate/event handler asynchronously, from unmanaged C++ ? I assume this requires a Managed C++ wrapper, which would call BeginInvoke on the delegate ? Is this correct, and if so, does anyone have an example ? Thanks !!
1
1877
by: knormand | last post by:
I have an older MFC C++ app with some new Managed C++ being thrown in. Recently I turned on the /clr flag for one of my old .cpp files. I then placed '#pragma unmanaged' just below my #include statements near the top of the file. These headers contain older unmanaged class declarations. When running I discovered a new bug, a crash, at a point in execution that was nowhere near any code that's been touched in quite a while. After hunting down...
1
1638
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the code which works well. I understand the basic concept: our code is unmanaged, Windows Forms is Managed and Unmanaged may not call Managed code. I read about Wrappers, PInvoke, Runtime Callable Wrappers for COM and about It just
2
1292
by: J | last post by:
Compiling a straight C++ module under VC++ 7 would seem to autogen an 'IJW' type .NET module, even if the module has standard VC++ syntax. I'm assuming that the 'unmanaged' flag would have no further affect on this code. Nor would __nogc. Correct? Or are there subtle further differences? Are there recommended references that sort this type of thing out in precise detail?
2
2008
by: Harry Simpson | last post by:
I've got a call within my .NET code to a function which uses an API call to get printer settings. When there's an error in the API call code, it crashes the .NET app. Try Catch doesn't prevent the crash - it's like it crashes before the catch catches..... Any ideas how to error handle this type of function so it doesn't crash the application?? TIA
3
1539
by: ropo | last post by:
I have a managed wrapper class that has a delegate to be called from unmanaged code: public ref class CmmMessageCallbackWrapper { private: delegate void InternalMessageDelegate( void*, CmmService::Message::CMessage* ); public: CmmMessageCallbackWrapper()
1
5081
by: wojski696969 | last post by:
Hi.. i've got the serious problem.. In my ASP.NET 2.0 application I'm using COM dll file referenced by interop dll. I'm using few properties from in one of the objects made from this library class. Problem is that i get "IIS Worker Process stopped working and was closed" error on my server. The script is working too long and then the process is stoped. I located wchich line of code causes the crash. It's invocation of one of the...
0
7997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8419
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
8409
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...
1
8065
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2434
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
0
1266
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.