.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Native C++ included in C# - problem with native singleton

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :.NET Framework

Hi all

i am trying to integrate a static native c++ lib into a c# project. I use a c++/cli intermediate layer
which wraps the native classes and exposes them to the managed layer. That has worked fine so
far, i even managed to overcome the problem of using Boost library in the native classes.
I use VS 2005.

I now have a problem when i try to instantiate a singleton within the native code, which is implemented
according to the following principle

public : static Singleton* exemplar();
: Singleton() {}
: static Singleton * instanz;

This singleton class is not wrapped in the c++/cli layer but it is constructed within an exposed native class.

The code compiles and links fine, but when i start the c#-exe i receive the error message:
ModuleLoadException: The C++ module failed to load during native initialization
ie the program doesn't even reach any executable sections.

Is that a known problem?
Can anybody point me towards a solution?



View Complete Post

More Related Resource Links

Problem consuming 32bit WCF service which references a native Dll in a 64 bit OS(Windows Server 2008

I have some 32bit Dlls which i want to use it in 64bit OS as i do not have a source code of this to recompile it for 64 bit OS. I have created a x86(32 Bit) WCF service which calls these Dlls and hosted it as a Windows Service on a x64(64 Bit) machine using Windows Server 2008. I have created one more x64 client which calls a function in the WCF which in turn calls a function from the 32 bit native Dll. Whenever i try calling this WCF from the client I get an error as given below.Can anybody please guide as to where I am going wrong and what is needed to solve this issue. Thanks in advance for any help.******The Error Message********************System.BadImageFormatException: Could not load file or assembly 'TestWCFWrapper, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.File name: 'TestWCFWrapper, Version=, Culture=neutral, PublicKeyToken=null'   at TestWrapperWCFClient.Form2.button1_Click(Object sender, EventArgs e)   at System.Windows.Forms.Control.OnClick(EventArgs e)   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)   at System.Windows.Forms.Control.WndProc(Message& m)   at System.Windows.Forms

sql native client problem for logon CR problem



As i have developed my asp.net application with crystal report using sql server 2005.... on windows xp OS machine x86

My hosting provider is using sql server 2008 on windows server 2008 OS x64...

Please let me know the sql native client version of ms sql server 2005
and sql native client version of ms sql server 2008

will sql native client version of ms sql server 2005 will work on sql native client version of ms sql server 2008..

or we need the same sql native client version of ms sql server 2005 to run my crystal report

Problem for Native App Development for SQL Server 3.5 Compact with VS2005



I want to develop a Native Visual C++ application that monitors several sensors and logs the data captured. I am using a x86 platform with WinCE6.0 R3.

For storing the data I want to use SQL Server Compact 3.5 and wanted to know how to use it from VS2005. I have downloaded and installed the SQL Server Compact 3.5 SP2 for Devices.

How can include the SQL functionality in my current project from VS2005. I am developing a native application.

I found similar queries and answers, but what is explained is relevant for Managed application development.


For Native application development, where can I get the relevant header files for SQL 3.5 CE(sqlce_sync.h, sqlce_err.h, and sqlce_oledb.h), and any libraries(if any required) as indicated in:


I do not get the %ProgramFiles%\Microsoft SQL Server Compact Edition\v3.5\Include on extracting the "SQL Server 3.5 Compact for Devices" on my PC.

With regards


Problem with named pipe server in C# and client in native C++ (ACCESS_DENIED)



I'm trying to use IPC between a server application in C# and client application in native C++.

The IPC is "named pipes".

The OS is Windows 7.

It works just fine with C# server and C# client.

It works fine with native C++ server and native C++ client.

However, the native C++ client refuses to connect to same C# server. The error code is 5 (ERROR_ACCESS_DENIED).

Both security descriptors are NULL.

Does anyone here uses such combination or can shed some light on this issues?




CLR Inside Out: Best Practices For Managed And Native Code Interoperability


There are many factors to consider when building your app with both managed and native code. Find out how to employ interop and how to choose the interop that's right for you.

Jesse Kaplan

MSDN Magazine January 2009

GUI Library: Bring the Simplicity of Windows Forms to Native Apps


In this article, author John Torjo presents a guide to his C++ GUI library called eGUI++ and explains how it makes user interface programming easier.

John Torjo

MSDN Magazine June 2008

WinUnit: Simplified Unit Testing for Native C++ Applications


Maria Blees introduces WinUnit, a handy new unit testing tool for native C++ projects.

Maria Blees

MSDN Magazine February 2008

XmlLite: A Small And Fast XML Parser For Native C++


XmlLite provides a high-performance, low-overhead XML reader and writer geared for applications written in native C++. Learn more here.

Kenny Kerr

MSDN Magazine April 2007

Netting C++: Mapping Native C++ to the Common Type System


This month Stanley Lippman begins translating the Text Query Language Query class hierarchy from C++ to the .NET Common Type System.

Stanley B. Lippman

MSDN Magazine February 2007

Wrappers: Use Our ManWrap Library to Get the Best of .NET in Native C++ Code


By now you're probably used to reaching into the .NET Framework using Managed Extensions with your C++ code. But what do you do if you have legacy apps that use older versions of the compiler, or if you want to avoid some of the CLR requirements? Well, you can wrap Framework classes in a native way so you can use them in any C++/MFC app without /clr. Paul DiLascia shows you how.

Paul DiLascia

MSDN Magazine April 2005

XML in Yukon: New Version Showcases Native XML Type and Advanced Data Handling


The next version of Microsoft SQL Server, code-named "Yukon," represents quite a few steps forward in the evolution of XML integration. Yukon supports native storage of XML data using the XML data type, which makes it possible to run native queries on XML data using the emerging industry standard XQuery language. Data integrity of the XML data type can be enforced through schema validation and XML-based check constraints, and special indexes can be defined that help speed up queries. In addition, Yukon has the built-in ability to expose its data through Web services. This article discusses these and other XML features of Yukon.

Bob Beauchemin

MSDN Magazine February 2004

'mscorlib.dll' targets a different processor/.net calling a native dll

I  have a vb.net that calls a dll in native cpp.  Works fine in 32bit.  Now I want to upgrade to 64 bit.  I've done this before and it worked but now get a runtime error.  Compiles ok but with the error noted in the subject line. Also, when I try to debug, the ide tells me that it can't debug managed and native.  Yes it can, I just forgot how. platform is win7, intel 64 bit.  any suggestion to the forum/whitepaper or ideas are greatly appreciated. Thanks in advance! Robert.

AppDomain.Unload effects Unable to evaluate expression because the code is optimized or a native fra

Hello, I create a custom AppDomain.Create().  I registered the Unhandled Exception Event from my custom AppDomain. In the Unhandled Exception Event i try to Unload my AppDomain with AppDomain.Unload. But this effects a "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." Have anyone a idea what i can do against this behaviour. greetints

Install SQL Server2005 Error:[Native Client]Encryption not supported on the client

Product: Microsoft SQL Server 2005 -- Error 29515. SQL Server Setup could not connect to the database service for server configuration. The error was: [Microsoft][SQL Native Client]Encryption not supported on the client. Refer to server error logs and setup logs for more information. For details on how to view setup logs, see "How to View Setup Log Files" in SQL Server Books Online.

Error: A native exception has occurred in my_file.exe

Hello everyone,   This error is occurring with me when I am working with SSCE in my pocket PC. Can anyone tell me why?   Thanks!

ArgumentOutOfRangeException Crossed native/managed boundary

When run my application i got this error at the starting. ArgumentOutOfRangeException Crossed native/managed boundary Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index How solve this. This Exception coming when i access the following private Collection m_coll; Public Collection coll {   set{m_coll=value;}   get{return m_coll;} } I have initialized the coll in constructor. In 2010 its working fine. Thanks,
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend