- Home /
Problem is not reproducible or outdated
RunTime Error in Unity when I'm using a function from a C++ Dll
I'm using a Dll created from a C++ file. When I either put the .dll and .lib files in my Unity-project folder or when I use the function that I need, Unity crashes and I can't open the project untile I remove the .dll or delete the function from the c# script.
This function works well on C++, both in Visual Studio and in Dev-C++ .
PS: Assets/alzBraccioCorretto.json is the file that I need to read
I've tried the same procedure for more simple dlls and it worked fine, so I don't know what I'm missing with this one.
In the Unity script I wrote
[DllImport("QuintaLibreria.dll", CharSet = CharSet.Unicode)]
static extern int LockOn(string filename, double lsxx, double lsxy, double udxx, double udxy, double
timer);
int temp = LockOn("Assets/alzBraccioCorretto.json", -1, -1, 1, 1, 6);
In the header of the library I have
#define MATCHINGLIBRARY_API __declspec(dllexport)
//all the other headers and #include
extern "C" {
MATCHINGLIBRARY_API int LockOn(string filename, double lsxx, double lsxy, double udxx, double
udxy, double timer);}
In the cpp of the library I have
MATCHINGLIBRARY_API int LockOn(string filename, double lsxx, double lsxy,
double udxx, double udxy, double timer) {
char * FileName = new char[filename.size() + 1];
std::copy(filename.begin(), filename.end(), FileName);
FileName[filename.size()] = '\0';
return lockPerson(FileName, lsxx, lsxy, udxx, udxy, timer);
}
Follow this Question
Related Questions
The type or namespace name... again 0 Answers
Failed to load DLL with error "The specified module cannot be found." 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
return char** from C++ DLL 0 Answers
How to assign a function to UnityEvent without the use of lambdas? 1 Answer