简体   繁体   中英

How to build a c++ dll imported in unity/c#

I wanna build a c++ dll,but I find there may be something wrong with my dll. I just built a simple function for ARM64 to deploy it into Hololens2. The header.h file:

#include "pch.h"


#ifdef  MYRESEARCHMODE_EXPORTS
#define DllExport __declspec(dllexport) 
#else  
#define  DllExport _declspec(dllimport)
#endif

#ifdef _cplusplus
extern "C"
{
#endif

class  DllExports
  {
  public:
      DllExport   static  int __stdcall DOUT();

  };  

#ifdef _cplusplus   
}
#endif

The .cpp file like this:
#define MYRESEARCHMODE_EXPORTS

#include "pch.h"
#include"myResearchMode.h"

  int __stdcall DllExports::DOUT()
{
  return 123;
}

And I used the Dumpbin to test whether it is built successfully. Then I import it in Unity/Plugin

    [DllImport("myResearchMode.dll", EntryPoint = "?DOUT@DllExports@@SAHXZ  ", CallingConvention = CallingConvention.Cdecl)]
    public static extern int DOUT();

But i find the result failed to show. I guess my dll has something wrong, do I forget to set some settings fot it? Or where the error is?

How did you create the C++ DLL? Which project template are you selected as the scaffolding when getting started to create a C++ DLL in the Visual Studio? If you created your C++ DLL as a Win32 binary, it will throw exceptions when running on the HoloLens2 because Unity will not include standard Win32 binaries when it builds a WSA project. Therefore, Therefore, it's recommended to recreate or port a native win32 DLL to the UWP DLL, see the guidance here: To port a native DLL to the UWP without creating a new project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM