Importing c++ dll files in Unity.

Hi,
I have created a dll file using vc++ 2008 , built using /clr and /MD parameters.,
The c++ project have 4 header files and 4 cpp files which are error free.

The dll file was placed in Plugins folder under Standard Asserts ,and I am not be to get reference to the dll in the code. I tried re importing and restarting the project , I am getting
error as

The type or namespace name `SampleDll’ could not be found. Are you missing a using directive or an assembly reference?

Am i missing something? Is there something wrong with the build setting for creating the dll?! Or do i need to include __declspec(dllexport) to the functions of the c++ files.

Do help me in this.

Thanks in advance,
pradeepk

unity i dont think can use c++ it just uses java, boo, and c#

Which means i cant use the c++ dll files in unity?!
Do i have to make a dll using c#?

Unity supports C++ plugins : http://unity3d.com/support/documentation/Manual/Plugins.html

Ok i got the link. That say we can use a dll created with functions.
What if i want to use a dll which has classes?!
Is there a way for that.?!

Check out the MSDN to answer this question.
Technically yes but question is really if you want and need to do it or if you write a real DLL thats targeted at usage in C# and Unity which only exposes datawise whats needed to reduce the amount of garbage and conversion from native to managed and back and all the extra binding code to work and manage the objects

In either case it requires Unity Pro.

I am having a similar problem and the previous post does not resolve my confusion.

If you build a Safe MSIL Assembly in any language, the DLL you get is CIL and does not depend on platform or language – that is the point of it.

We are not trying to import unmanaged code that we wrote in C++, we are trying to import a (supposedly) language-and-platform independent CLR assembly as a DLL. It should be the case that Unity has no idea that we didn’t write the managed assembly in C#, but it won’t use our test DLL.

After a lot of searching, all I can find involves importing unmanaged code. I was very careful to write my technology in managed C++ so it could be used in C# applications. That all works fine in our current XNA-based demo, but it won’t import into Unity. Importing an assembly DLL that was written in C# works, obviously.

If buying Pro means I will solve this problem, I’ll buy Pro. We’d be buying it eventually anyway if we could get past this issue and get something working. But I don’t want to buy Pro just to find out I didn’t need to yet nor that it’s impossible even with Pro and I need to do a complete port to C#.

I appreciate any clarification.

Can I write a C# dll which imported the C++ dll, and use the C# dll in Unity?

Hi @anon_36396939 , @tracy-swift , @kapland and @Rodesqa , indeed it’s possible to make C++ native dll’s and access them from C#, please take a look at this asset:

Make your own native dll

I’m sure it’s just what you need.
All the best!!!

Yes you can. Just make bitness of all equal to Unity’s bitness.