Quantcast
Channel: Questions in topic: "dllimport"
Viewing all articles
Browse latest Browse all 160

Converting from c# string to c++ string

$
0
0
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 (just functions with int or double variables) and it worked fine, so I don't know what I'm missing with this one, probably UNICODE In the Unity script I wrote [DllImport("QuartaLibreria.dll", CharSet = CharSet.Unicode)] static extern string LeggiFile(string nomeFile); Text testo; unsafe void Start() { testo = GetComponent(); temp = LeggiFile("Assets/alzBraccioCorretto.json"); testo.text = temp; } In the header of the library I have #define QUARTALIBRERIA_API __declspec(dllexport) //all the other headers and #include string leggiFile(char* nomeFile); extern "C" { QUARTALIBRERIA_API wstring LeggiFile(wstring nomeFile);} In the cpp of the library I have string leggiFile(string nomeFile) { ifstream _stream(nomeFile.c_str()); string temp; _stream >> temp >> temp; _stream.close(); return temp; } QUARTALIBRERIA_API wstring LeggiFile(wstring nomeFile){ std::string str(nomeFile.begin(), nomeFile.end()); string daRit = leggiFile(str); std::wstring WdaRit(daRit.length(), L' '); // Make room for characters std::copy(daRit.begin(), daRit.end(), WdaRit.begin()); return WdaRit; }

Viewing all articles
Browse latest Browse all 160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>