• 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 /
  • Help Room /
avatar image
Question by vladeshadow · Nov 04, 2016 at 02:31 PM · dllassemblyc++dllnotfoundexception

DllNotFoundException, C++ dll used with an assembly, not possible?

Hi, I'm kind of new to things like handeling dll in unity and stuff. Here's my problem I need Unity and an over application to communicate with eachother. To do so I have an API made of aC++ dll from that other application, a lib and an header. There called API_C.1.6.dll, API_C.lib and API_DLL_C.h, I also have a second dll called API_NET.dll that is an assembly that does all the DLLIMPORTS for me so that I just have to add a reference to that dll in VS2013 and I can use all the fonction from the first dll.

Here is what the API_DLL_C.h looks like:

 #ifndef __API_CBINDING_h__
 #define __API_CBINDING_h__
 
 //! use this compilation option to create API.dll ///
 #if defined(API_STATIC) || defined(__linux__)
 #define declAPI
 #else
 #ifdef API_EXPORTS
 #define declAPI __declspec(dllexport)
 #else 
 #define declAPI __declspec(dllimport)
 #endif
 #endif
 
 #include API_DLL_Enums.h"
 
 #define MAX_DATA_ID_STRING_SIZE 256
 
 #ifndef API_STATIC
 #ifdef __cplusplus 
 extern "C" {
 # endif
 #endif
 
     declAPI int Process_InitParams(const char* ProcName, const char* ConfigName, float Frequency);
 
 ...(other fonctions)
 }

Here is my cs files that uses the dll:

 using UnityEngine;
 using System;
 using System.IO;
 using API_NET;//from the assembly
 
 
 public class TestComAPIUnity: MonoBehaviour {
 
     // Use this for initialization
     void Start()
     {
         plugin_API.Process_InitParams("TESTUNITY", "DEFAULT", 30f);
         
     }
 
     // Update is called once per frame
     void Update () {
        
     }
 }

This is the simpliest communication between Unity and my other application that can be done with the API.

With this there is no compilation errors but when I try to run in the editor I have this error:

DllNotFoundException: API_C.1.6.dll API_NET.plugin_APIPINVOKE+SWIGExceptionHelper..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper API_NET.plugin_APIPINVOKE..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for API_NET.plugin_APIPINVOKE API_NET.plugin_API..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for API_NET.plugin_API TestComAPIUnity.Start () (at Assets/TestComAPIUnity.cs:12)

What I understand(I think) is that when I call the function, the assembly does it's job and try to find API_C.1.6.dll but can't find it. Just to be sure I build the project the dll is in the project_data\Plugins folder but when I use the exe with my application nothing happens. At some point I did do the DLLIMPORT myself and I had this kind of error:

Failed to load 'Assets/Plugins/x86_64/audiopluginvrunity.dll' with error 'The specified module could not be found. ', TestComAPIUnity.Start () (at Assets/TestComAPIUnity.cs:12) DllNotFoundException: API_C.1.6.dll'

I arrived at the conclusion that doing the DLLIMPORTS myself or not just changed where the error would appear in my script or in the assembly. I also checked if the dlls were 64bits like my OS and my UnityEditor, they are. I placed the API_C.1.6.dll in Assets, in Assets\Plugins, in Assets\Plugins\x86_x64(like the parameter in the plugin inspector), i placed it next to my exe and the assets folder, next to the API_NET.dll(in my application folders). Some people on the internet seemed to had problems because they didn't had Microsoft Visual C++ 2015 Redistributable, I have it and I have a licenced VS2013. I also tried to change my environment variable PATH at runtime with a static constructor but it changed nothing.

I'm starting to run out of ideas, so I ask you guys for help. By the way, judging by the number of post and articles about it, a lot of people seem to have trouble with handeling DLLs in Unity. Thanks

Vincent P.S: because of confidentiality policy I had to change names and stuff so there may be one or to mistakes, sorry and forgive my not that good english

Comment

People who like this

0 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

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

76 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor freezing with multithreaded DLL native plugin in Release but not in Debug 2 Answers

Change from INTEGRATED to DEDICATED video card 0 Answers

System.Threading.Tasks.Extensions.dll is not allowed to be included or could not be found 1 Answer

Namespace Media does not exist 1 Answer

Marshal C# Method with C++ 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