I'll attempt to be as brief as possible. I have tried many documented solutions with no luck.
I am working with a team of students on a senior project. We have created a discrete event simulation project in C++ using Visual Studio 2019. The project consists of numerous classes and their respective header files. The project is able to be built and run as a console application.
We are using Unity to build a GUI for the project and I am attempting to call certain functions from the C++ project within the Unity project.
My first attempt was to build the C++ project as a DLL. I wrapped a function I wanted from the C++ code in an extern "C" block and added __declspec(dllexport) to the function definition
Example:
extern "C"{
__declspec(dllexport) void InputReader::AddSelectedObject(string name);
}
The dll build was successful and was named "DES.dll". I was able to see the "AddSelectedObject" in the dll file via notepad to verify that the C-style block was preventing the C++ compiler from encoding the function name. I added the dll to our Unity project under Assests/Plugins/. In the C# script that I want to make the C++ function call, I defined the function using:
[DllImport ("DES")]
private static extern void AddSelectedObject(string name);
I ran the Unity project and received an EntryPointNotFound exception when the line above was executed.
This led me on a massive goose chase for a solution via many Unity Answer, Stack Overflow, and other site discussion boards as well as many pages of the Unity API Manual.
I have tried switching the project to the IL2CPP scripting backend and using the .CPP files instead of a dll and attempted to call the function via
[DllImport ("__Internal")]
private static extern void AddSelectedObject(string name);
I attempted to use marshalling for the string variable
private static extern void AddSelectedObject([MarshalAs(UnmanagedType.LPWStr)]string name);
I attempted to switch the build in Unity to Universal Windows Platform
I have attempted to define the entry point via
[DllImport ("DES", EntryPoint = "AddSelectedObject")]
private static extern void AddSelectedObject(string name);
It seems no matter what I try, all proposed solutions lead to the "EntryPointNotFound" Exception.
What am I missing? Do I need to write a header specifically for the DLL? If so, do I call #include for the class headers containing the function definitions I need? Are they still defined by their respective class? It seems every solution I find is curtailed around C++ libraries that contain one class and one header instead of a complex standalone C++ project.
Please help!
↧