Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package the project into DLL libraries #40

Open
RenSiyao opened this issue Oct 14, 2020 · 10 comments
Open

Package the project into DLL libraries #40

RenSiyao opened this issue Oct 14, 2020 · 10 comments
Labels
question Further information is requested

Comments

@RenSiyao
Copy link

How to put the project into Unity after packaging the DLL library。
Who can tell me the complete process of packaging a project into a DLL library and how to call this DLL inside Unity?
I used the call method shown in the figure below but got an error in Unity.Who can help me?
image
image

@dakesse
Copy link

dakesse commented Oct 14, 2020

Have you tried using DUMPBIN /exports my.dll to get the correct entry points?
This gives you something like this:

[DllImport("my.dll", EntryPoint = "?InitSensors@DllExports@@SAXXZ")]
public static extern void initSensors();

@dorinung dorinung added the question Further information is requested label Oct 16, 2020
@RenSiyao
Copy link
Author

RenSiyao commented Oct 19, 2020

您是否尝试过使用DUMPBIN /exports my.dll以获取正确的入口点?
这给你这样的东西:

[DllImport("my.dll", EntryPoint = "?InitSensors@DllExports@@SAXXZ")]
public static extern void initSensors();

First of all, thank you for your reply. I still cannot detect the method in DLL library according to the method you provided.Do you also try to use sensor data from Hololens2ForCV in Unity for your own projects?Can you tell me the complete process?From publishing projects to Hololens and how to build DLL library files.

@dakesse
Copy link

dakesse commented Oct 21, 2020

您是否尝试过使用DUMPBIN /exports my.dll以获取正确的入口点?
这给你这样的东西:

[DllImport("my.dll", EntryPoint = "?InitSensors@DllExports@@SAXXZ")]
public static extern void initSensors();

First of all, thank you for your reply. I still cannot detect the method in DLL library according to the method you provided.Do you also try to use sensor data from Hololens2ForCV in Unity for your own projects?Can you tell me the complete process?From publishing projects to Hololens and how to build DLL library files.

Hi @RenSiyao ,
yes I use research mode sensor data in Unity, strictly speaking accelerometer and gyro values.
If you haven't already, take a look into #31.

The complete process would be a bit to much but here are the general steps:

  • For the DLL I used a VS 2019 C++ DLL project in which I added the research mode api header. then I implemented functions to init the sensors and get their data analogue to the SensorVisualization example. These are my functions declared in the DLL's header:
class DllExports {
public:
  DllExport static void InitSensors();
  DllExport static void OpenAccSensorStream();
  DllExport static void OpenGyroSensorStream();
  DllExport static void OpenMagnetSensorStream();

  DllExport static void GetAccDataStamped(float& accX, float& accY, float& accZ, UINT64& timestamp);
  DllExport static void GetGyroDataStamped(float& gyroX, float& gyroY, float& gyroZ, UINT64& timestamp);
  DllExport static void GetMagnetDataStamped(float& magnetX, float& magnetY, float& magnetZ, UINT64& timestamp);
  DllExport static SensorDataStruct* GetAccDataBatched();
  DllExport static SensorDataStruct* GetGyroDataBatched();
  DllExport static SensorDataStruct* GetMagnetDataBatched();

  DllExport static void CloseAccSensorStream();
  DllExport static void CloseGyroSensorStream();
  DllExport static void CloseMagnetSensorStream();
  DllExport static void ReleaseSensors();
};

Target platform has to be ARM64.

  • I tested my DLL with a C++ UWP app before including it to Unity.
  • For Unity I needed the correct entry points of my exported functions. Via the developer command prompt for VS and the command dumpbin /exports my.dll you can get them.
  • Then copy the DLL into your Unity project and import the functions that you want to use in a script:
[DllImport("my.dll", EntryPoint = "?InitSensors@DllExports@@SAXXZ")]
public static extern void initSensors();
...

Here you have to be careful how you pass data from C++ to C#. I solved it with an 'unsafe' block but marshalling can be a way too.

  • After the first build you have to modify the Package.appxmanifest as discribet in the ResearchMode API Doc and add <rescap:Capability Name="perceptionSensorsExperimental" />.
  • Research mode must be activated in the Device Portal as described here.
  • Finally you can deploy to your HoloLens 2.

I hope that helps a little. Otherwise just feel free to ask.

@agroenenberg
Copy link

@RenSiyao I'm trying to get the StartRecording() and StopRecording() functions incorporated as well but can't get the winrt::Windows library in my DLL. How did you manage to do that? Did you use a Windows Runtime Component format? Thanks, it would help me a lot

@RenSiyao
Copy link
Author

@RenSiyao我正在尝试同时合并StartRecording()和StopRecording()函数,但是无法在我的DLL中获得winrt :: Windows库。您是如何做到的?您是否使用Windows运行时组件格式?谢谢,对我有很大帮助
It's a pity that I can't help you, because my project hasn't been built successfully yet.

@agroenenberg
Copy link

Your DLL built succesfully right? Did you look at #31 ? I had the same problem and solved it. Did you put your DLL in your Assets/Plugins folder?

@RenSiyao
Copy link
Author

您的DLL成功建立了,对吗?你看到#31了吗?我有同样的问题并解决了。您是否将DLL放在了Assets / Plugins文件夹中?

The DLL library I successfully built is a case study in the depth camera project, and my DLL library cannot be used on the journey.
I used the DLL library built into this project.Hope I can help you.https://github.com/petergu684/HoloLens2-ResearchMode-Unity

@agroenenberg
Copy link

I'll look into it and let you know if I can get it to work!

@RenSiyao
Copy link
Author

You can only get one depth sensor data for the DLL library I provided to you. I cannot solve your function problem of StartRecording () and StopRecording () for you.

@JiangTao100
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants