I have created a DLL file in C++. I want to import it in my Windows Phone project. I have followed a number of instructions from different sources, even when I run my code I
To import make use of a C++ into your C# project you have to make it visible from managed code. To do so, you should create a new 'Windows Phone Runetime' component, under the Visual C++ section in the New Project menu. You can name your project "Dll" for example.
Once your project is created you can modify the source to have something that looks like this.
Dll.cpp :
#include "Dll.h"
namespace ns {
double Cpp_class::cppAdd(double a, double b)
{
return a + b;
}
}
Dll.h :
#pragma once
namespace ns {
public ref class Cpp_class sealed /* this is what makes your class visible to managed code */
{
public:
static double cppAdd(double a, double b);
};
}
Compile it to verify you didn't do anything wrong. Once this is done, create a new Windows Phone app project (under the Visual C# in the New Project menu. Right click the solution name and select 'Add' > 'Add Existing Project', select your Dll project. Once you did this, right click the Windows Phone app project, select 'Add Reference', under the 'Solution' tab, you'll see you Dll project.
If you did all this correctly, you can now use your native code inside the C# portion of the Windows Phone App by "using" it :
using Dll;
[...]
ns.Cpp_class.Add(1,3);
Remember that you won't be able to use the component if you didn't add the reference.
I really hope that helps !