• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by mvm95 · Jul 26, 2017 at 04:52 PM · plugindllpluginsnative plugindllimport

How do you use a class from a .dll file?

I'm trying to use a class, "DevIO", from a Microchip library, "MCP2210-M-dotNet2.dll". When I downloaded the library, it had a managed and unmanaged folder, but Unity is reading both of them as native plugins. Supposedly, DllImport is used to access methods from a native plugin, but how do I access a class?

UPDATE: Previously, I did have "MCP2210-M-dotNet2.dll" in a Plugins folder. I added it to the Assets folder as suggested. I then had to manually edit the project references in MonoDevelop and browse to add it as a .Net Assembly. Now "using MCP2210" is recognized, and there are no errors in MonoDevelop, but Unity still has errors.

I read more into how to use the library, and it requires Microsoft Visual C++ 2010 Redistributable Package or the inclusion of "msvcp100.dll" and "msvcr100.dll". However, Unity says they aren't valid .Net Assemblies, so is there a way I can include the Microsoft Visual C++ Redistributable Package in Unity?

Comment
megabrobro

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by ThePunisher · Jul 26, 2017 at 07:01 PM

It looks like dealing with plugins is a Pro-only feature.

Now that I know more about the problem. You should be able to pull in the DLL's from the managed directory under the "MCP2210DLL-M-dotNet2" directory. You will need all of the DLL's under this directory inside your plugins directory.

The "MCP2210DLL-M-dotNet2.dll" and "msvcm90.dll" are both managed dlls written in c#. They will expose all the functionality from the other two dll's (msgvcp90.dll and msvcr90.dll) to you.

There's example documentation within the managed directory. Just open up the "MCP2210DLL-M_CSExampleCode.sln" solution. Within this solution is Program.cs which contains examples on how to use the code. All the code made available to you is under the MCP2210 namespace so your scripts will need the using MCP2210; directive. You won't need to add the DLLs as references to your unity solution since Unity will do this step automatically (assuming you have placed them in your plugins directory).

Edit: Once you've done everything above the following code in a c# script compiled just fine.

 using UnityEngine;
 using System.Collections;
 using MCP2210;
 
 public class MicrochipTest : MonoBehaviour
 {
 
     // Use this for initialization
     void Start ()
     {
         //Variables
         const uint MCP2210_VID = 0x04D8;   // VID for Microchip Technology Inc.
         const uint MCP2210_PID = 0x00DE;   // PID for MCP2210
         bool isConnected = false;           // Connection status variable for MCP2210
 
         MCP2210.DevIO UsbSpi = new DevIO(MCP2210_VID, MCP2210_PID);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

Comment
mvm95

People who like this

1 Show 29 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EnokV · Jul 26, 2017 at 08:10 PM 1
Share

As far as I understand it, he does not want to use a native plugin, but he want to access a .net assembly from Unity. This can be done simply by putting the .DLL in the assets folder of your project. Unity will take care of linking automatically and it should work as long as the DLL is compiled for .NET 3.5 or 4.6(experimental in unity).

avatar image ThePunisher EnokV · Jul 26, 2017 at 08:42 PM 0
Share

Compiling c# code into a DLL and bringing it to Unity assets directory allows you to reference that code (classes, types and all). But it sounds like what he's been given is a native plugin. Something probably written in C, maybe c++.

This is what the Unity manual has to say about that:

"Unity has extensive support for native Plugins, which are libraries of native code written in C, C++, Objective-C, etc. Plugins allow your game code (written in Javascript or C#) to call functions from these libraries. This feature allows Unity to integrate with middleware libraries or existing C/C++ game code.

In order to use a native plugin you firstly need to write functions in a C-based language to access whatever features you need and compile them into a library. In Unity, you will also need to create a C# script which calls functions in the native library.

The native plugin should provide a simple C interface which the C# script then exposes to other user scripts. It is also possible for Unity to call functions exported by the native plugin when certain low-level rendering events happen (for example, when a graphics device is created), see the Native Plugin Interface page for details."

If what he has is a native plugin then he may have to build the Unity script which exploses the functionality built into the plugin.

avatar image EnokV ThePunisher · Jul 27, 2017 at 06:25 AM 0
Share

If you read his post again, you'll see that it is not a native plugin he's talking about.

"MCP2210-M-dotNet2.dll".

Unity probably thinks its a native plugin because he's putting the file in a plugins-folder.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Referencing a DLL in C# 0 Answers

nonstatic extern functions from DLL plugin import 1 Answer

Error loading a 3.0 framework dll (WFC) 1 Answer

Are calls to C++ DLL handled asynchronously? 1 Answer

Do Native Mobile Plugins Require Pro? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges