Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by Ploomstar · Jun 05, 2017 at 12:11 AM · pluginsdllnotfoundexceptiondllimport

EntryPointNotFoundException - native plugin help

EDIT: SOLUTION IS BELOW! - look for the header "SOLUTION"

Hello,

So I'm trying to use a C++ native plugin (balls.dll) with a C# script in my project (Unity 5.5.0f3). The dll is inside my assets/plugins folder.

My code (simplified) looks something like this:

 public class Bigballs : Monobehaviour
 {
     [DllImport("balls")]
     public static extern int Init(); //returns 0 if initialized, else returns -1
 
     int x;

     void Start() 
     {
         x = Init();
     }
 }

While in editor, I hit run and Unity responds with "EntryPointNotFoundException: Init" at the line "x=Init()". What can I do to fix this? I have tried searching Unity forums and googled, it seems no one is really having the same issue in regards to native plugins.

If it is worth mentioning, I have worked with native plugins in the past, and initially, I tried [DllImport("balls.dll")], which is how I was able to access my dll methods in an older project. However, this time I got a "DllNotFoundException". After some quick googling, it was suggested that dropping the .dll would get rid of the DllNotFoundException in the DllImport.

I greatly appreciate your help in advance.

SOLUTION

So here is what I did that FINALLY got it to work. I created a constructor to find my plugin, solving the DllNotFoundException. What it does is set the current path to the location of my plugin, which is in Assets/Plugins/x64.

 static Bigballs() //constructor
     {
         String currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
         String dllPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "x64";
         if (currentPath.Contains(dllPath) == false)
         {
             Environment.SetEnvironmentVariable("PATH", currentPath + Path.PathSeparator + dllPath, EnvironmentVariableTarget.Process);
         }
     }

This resulted in the Dll being found, but still returns EntryPointNotFoundException. So here is the annoying part. You have to crack open the .dll, or if you're lucky and have a .lib, you can use that. What you want to do is find the Entry Point of your function inside the .dll or .lib, I am going to describe how I did it using Visual Studio and a .lib, but this should work for another program that can open .dlls and with a .dll.

So to see the contents of Balls.lib, I dragged it into Visual Studio's solution explorer and then opened it. Inside balls.lib, there is a column of what seems like jibberish, but these are actually entry points. You have to pinpoint the exact function you are trying to import, so for me it is Init(), and inside the .lib, the entry point looked like this:

 ?Init@@YA?AW4variable@@XZ

One thing I noticed, all the functions' entry points seem to be within a pair of periods ('.'), so just copy and paste the entry point, format it to have no spaces, and add it to your DllImport call, like so:

  [DllImport("SimballMedicalHID.dll", EntryPoint = "?Init@@YA?AW4variable@@XZ")]

And that's how I eliminated these two annoying problems. I spent days stuck on my project and I hope that at least some of this is helpful for anyone else experiencing similar issues.

Comment
Add comment · Show 2
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 Kor_Skarn · May 03, 2018 at 08:18 PM 1
Share

The entrypoint name looks like ?Init@@YA?AW4variable@@XZ because this is what is called the "decorated" C++ name. When you compile a C++ exe or dll, each fonction need a globally unique name, therefore a decorated name is generated, which includes the namespace in which the function belongs, as well as hte function parameter signature (because you can have several overloads of the same function with the same name and different parameters).

The correct solution to this problem is to have the functions exported from your dll as C style functions, not C++ functions. This is done by having the function declared in an extern "C" block as such:

extern "C" { __declspec(dllexport) int Init() { return 1; } }

}

avatar image Bunny83 Kor_Skarn · May 03, 2018 at 09:41 PM 0
Share

The name "decoration" / mangling has nothing to do with being globally unique which actually isn't the case. It actually just encodes the return type, calling convention, parameters and parameter types and parent class names into the name itself.


Your solution however is of course correct ^^

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

How to properly use my own DLLs in Unity? 2 Answers

Get Exception DLL Not Found 0 Answers

DLLNotFoundException 0 Answers

Unity XR plugin manager Tries to load oculus dll on windows even if its disabled. 0 Answers

DLL NOT FOUND EXCEPTION even after following procedure 0 Answers


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