Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Importing c++ dll files in Unity.

Discussion in 'Scripting' started by pradeepk, Jan 4, 2012.

  1. pradeepk

    pradeepk

    Joined:
    Nov 2, 2011
    Posts:
    5
    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
     
  2. Rodesqa

    Rodesqa

    Joined:
    May 16, 2011
    Posts:
    181
    unity i dont think can use c++ it just uses java, boo, and c#
     
  3. pradeepk

    pradeepk

    Joined:
    Nov 2, 2011
    Posts:
    5
    Which means i cant use the c++ dll files in unity?!
    Do i have to make a dll using c#?
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
  5. pradeepk

    pradeepk

    Joined:
    Nov 2, 2011
    Posts:
    5
    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.?!
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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.
     
  7. kapland

    kapland

    Joined:
    Feb 22, 2015
    Posts:
    1
    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.
     
  8. tracy-swift

    tracy-swift

    Joined:
    May 29, 2015
    Posts:
    1
    Can I write a C# dll which imported the C++ dll, and use the C# dll in Unity?
     
  9. jemonsuarez

    jemonsuarez

    Joined:
    Sep 24, 2012
    Posts:
    151
  10. Tugrul_512bit

    Tugrul_512bit

    Joined:
    Apr 9, 2016
    Posts:
    46
    Yes you can. Just make bitness of all equal to Unity's bitness.