Two main steps involved are
1- Creating a C++ dll
In visual studio
New->Project->Class Library in c++ template. Name of project here is first_dll in
visual studio 2010. Now declare your function as public in first_dll.h file and
write the code in first_dll.cpp file as shown below.
Header File code
// first_dll.h
using namespace System;
namespace first_dll
{
public ref class Class1
{
public:
static double sum(int ,int );
// TODO: Add your methods for this class here.
};
}
Cpp File
//first_dll.cpp
#include "stdafx.h"
#include "first_dll.h"
namespace first_dll
{
double Class1:: sum(int x,int y)
{
return x+y;
}
}
Check This
**Project-> Properties -> Configuration/General -> Configuration Type**
this option should be Dynamic Library(.dll) and build the solution/project now.
first_dll.dll file is created in Debug folder
2- Linking it in C# project
Open C# project
Rightclick on project name in solution explorer -> Add -> References -> Browse to path
where first_dll.dll is created and add the file.
Add this line at top in C# project
Using first_dll;
Now function from dll can be accessed using below statement in some function
double var = Class1.sum(4,5);
I created dll in c++ project in VS2010 and used it in VS2013 C# project.It works well.