ASP.Net compatibility with C++

This blog post explains why is compatible with C++ more than any other option. development company has shared this post for developers who would like to know about compatibility with C++.

C++ is an older language of the C family, whereas the C# followed in is comparatively a new version. But still there is a lot of compatibility and need of time where we have to use the C++ code in ASP.Net.

The C++ code can be migrated to the modern ASP.NET applications by using CLR (Common Language Runtime ) environment. This redesign is called C++/CLI, and is intended to provide a more natural syntax for consuming and authoring CLR types. The traditional C++ language is enabled to write more elegant and efficient code targeting the .NET Framework. The following ways provide an insight to use C++ for ASP.NET.

The existing tools,utilities, and classes written in C++ are still useful in the higher version of languages. In Asp. Net ,there are three main methods to invoke the C++ code to be reused.

1. IJW : This method provides the facility to reuse C++ code in the ASP. Net. A minor change in the code is required . After invoking the code , you have to recompile the code in . Net platform.

#include "stdafx.h" #using <mscorlib.dll> #include <tchar.h> #include <windows.h> using namespace System; using namespace System::Runtime::InteropServices; public __gc class MsgBox { public: MsgBox(String *str) { IntPtr ptrtxt = Marshal::StringToCoTaskMemUni(str); MessageBoxW(0,(LPCWSTR)ptrtxt.ToPointer(), L"IJW is powerful",0); Marshal::FreeCoTaskMem(ptrtxt); } }; int _tmain(void) { String *str; str = "WELCOME"; MsgBox *m_msgbox = new MsgBox(str); return 0;

StringToCoTaskMemUni copies the string to an unmanaged area in the heap and will not get garbage collected. This is the major advantage which can not be implemented using C#

2. COM. The COM model allows you to reuse the classes written in different languages. This particular method can be used with C++ or by any other class written in the object-oriented form.

In C++ , this done by declaring the abstract classes which use pure virtual function.

class Box { public: // pure virtual function virtual double getVolume() = 0; private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box };

3. P/Invoke . This method allows importing a class as functions. You can import class methods as individual functions.

To marshal C++ classes into a C# project ,Microsoft provides marshal C-functions. the P/Invoke method creates a lot of complications and changes are to be made in C# code. hence this option is chosen rarely

//** IJW means "It just works" and P/Invoke means " Platform Invocation Services". The above mentioned three methods are inbuilt in C++. Retrieve Exported Information from the DLL
So whenever we have to import a class from C++ , import the class methods from the DLL. If the source code is not available, the Microsoft dumping tool "dumpbin.exe" to retrieve the name for each function from the DLL is used . Next is to determine functions and accessible methods based on the class definitions in the header. Mapping of the mangled names of the class members can be listed as:

C++ Decorated Name

Class Member



Default constructor

Added by compiler


Vehicle::Vehicle(char *)




Class default structure

Added by compiler


Virtual table (VTB)

Added by compiler






Default constructor

Added by compiler




Class default structure

Added by compiler


Virtual table (VTB)

Added by compiler



The "name mangling" are compiler-dependent, and vary from one version to another. If you add/remove/change class members to the Win32 project, the new DLL will have different "mangled names" for the constructor or other class members having entire information about the class member and its relationship with the rest of the class. In the case of the relationship changes , the mangled name will also be changed in new DLL.

After seeing, the example , we can say that the C++ can access Common Language Runtime (CLR) in Visual C++ 2005. The redesign is named as CLI. The new CLI represents a more natural syntax for authoring and using CLR types.

To sum up the compatibility of the C++ with the ASP.Net , the following table elaborates the convertibility type from C++ to ASP.Net




Allocate reference type

ReferenceType^ h = gcnew ReferenceType;

ReferenceType h = new ReferenceType();

Allocate value type

ValueType v(3, 4);

ValueType v = new ValueType(3, 4);

Reference type, stack semantics

ReferenceType h;


Calling Dispose method

ReferenceType^ h = gcnew ReferenceType;
delete h;

ReferenceType h = new ReferenceType();

Implementing Dispose method

~TypeName() {}

void IDisposable.Dispose() {}

Implementing Finalize method

!TypeName() {}

~TypeName() {}


int^ h = 123;

object h = 123;


int^ hi = 123;
int c = *hi;

object h = 123;
int i = (int) h;

Reference type definition

ref class ReferenceType {};
ref struct ReferenceType {};

class ReferenceType {}

Value type definition

value class ValueType {};
value struct ValueType {};

struct ValueType {}

Using properties

h.Prop = 123;
int v = h.Prop;

h.Prop = 123;
int v = h.Prop;

Property definition

property String^ Name 
    String^ get()
        return m_value;
    void set(String^ value)
        m_value = value;

string Name 
        return m_name;
        m_name = value;

As the many complicated tasks of the C# can be easily written in the C++ classes in simple forms , therefore the above mentioned tools are used to implement mangled classes of C++ in C# thus creating powerful applications in ASP. Net.

The purpose of sharing this post is to know compatibility with C++. ASP.NET Development Company Experts will answer all your queries. Send them directly and wait for their response.

Author Bio:
Akshita is working as content writer in ASP.NET Development company. You can write to her about more of such related topics to avail more info.


Client Testimonials

  • Fabio Durso

    We found a reliable and efficient partner in NexSoftSys, ready to support our strategy of offshore software development. NexSoftSys has particularly impressed by the speed of response to any request for the development of software applications and for their maintenance.

  • Filipe

    We did hire full time Java developers from NexSoftSys, to help us to improve a time to market of a product. The software platform is based on Java & Extjs, and they are delivering the software on time and with success. We strongly recommend NexSoftSys as Reliable Development partner.

  • Steve

    Powerful solutions are given by NexSoftSys dedicated developers for my projects. They suggest solutions as per current market trend. Other than this, the team is always ready for any type of changes or update. That is the main reason that I would like to give my next project to them.

Copyright © 2016 - NexSoftSys All rights reserved