I'm trying to include C# dll library to Native C++ console application. I'm using this article: https://support.microsoft.com/en-us/kb/828736#bookmark-7
However the article is written for Visual Studio 2015 and I'm using Visual Studio 2015.
First I have checked a couple of answers here on Stackoverflow, but none of this questions was exactly what I'm looking for.
The question that is closest to my is here: C# library to native C++ application
So, I have create a C# library project, with the following code inside:
namespace Testing_Library
{
// Interface declaration
public interface iCalculator
{
int Add(int number1, int number2);
}
public class ManagedClass:iCalculator
{
public int Add(int number1, int number2)
{
return number1 + number2;
}
}
}
Then I have compiled the project to dll file, and then I have registered the dll file via RegAsm.exe. Now I have two output files:
Testing_Library.dll
and
Testing_Library.tlb
Also I have created Native C++ Windows Console Application Project. Inside this project I have one .cpp file with the following code:
// Import the type library.
#import "..\Testing_Library\bin\Debug\Testing_Library.tlb" raw_interfaces_only
using namespace std;
using namespace Testing_Library;
void main()
{
// Initialize COM.
HRESULT hr = CoInitialize(NULL);
// Create the interface pointer.
iCalculatorPtr pICalc(__uuidof(ManagedClass));
long lResult = 0;
// Call the Add method.
pICalc->Add(5, 10, &lResult);
wprintf(L"The result is %d", lResult);
// Uninitialize COM.
CoUninitialize();
}
And when I try to run the project I receive the following error screen:
Currently I have no idea why am I receiving this error Windows and I can not find information on the internet. Could you please help me? Here you can find the whole Solution with all projects: Onedrive folder
I'm trying to compile and run currently:
Test_me
and
Testing_Library