Unity UWP DLL Import

  c++, dll, unity3d, uwp

1-> Project Type DLL(UniversalWindows)

2-> Dll1.h code

#pragma once

#ifdef Dll1
#define Dll1 __declspec(dllexport)
#else
#define Dll1 __declspec(dllimport)
#endif

extern "C" Dll1 bool test();

Dll1.cpp code

#include "Dll1.h"


bool test() {
  return true;
}

3-> build Config-> Debug : Platform-> ARM

4-> Dll1.dll copy to assets/Plugins/WSA/ARM
Dll1 asset settings in unity

5-> if I use this code

[DllImport("Dll1")]
public static extern bool test();

I get this error in Hololens2 device
Unable to load DLL 'Dll1'

Unity Doc :Universal Windows Platform: Plugins on IL2CPP Scripting Backend

else if i use this code

[DllImport("__Internal")]
public static extern bool test();

I get this error on VS build to device

ERROR screenshot

Severity Code Description Project File Line Suppression State

Error LNK1120 1 unresolved externals Il2CppOutputProject GameAssembly.dll 1

Error LNK2019 unresolved external symbol test referenced in function RabbitNativeMethods_test_mB4443389B66566A0E9E043101C464B82C2B09074 Il2CppOutputProject E01DB848396BE771DA150FCD3EBDE0E9.obj 1

Unity Build Settings

Scripting Backend > IL2CPP

Api Level > .NET 4.X

Architecture > ARM

Target and Min SDK > 10.0.19041.0

VS Build Settings

Relase / ARM

Unity version 2020.3.12f1
VS2019 16.10.3

Source: Windows Questions C++

LEAVE A COMMENT