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
↧