Unity access SDK

1. Managed code and unmanaged code

C# is a managed language and C++ is an unmanaged language.

The difference between managed code and unmanaged code
1. Managed code is an intermediate language that runs on the CLR; unmanaged code is compiled into machine code and runs on the machine.

2. Managed code is independent of platform and language, and can better achieve compatibility between different language platforms; unmanaged code depends on platform and language.

3. Managed code can enjoy the services provided by CLR (such as security detection, garbage collection, etc.), and does not need to complete these operations by itself; unmanaged code needs to provide security detection, garbage collection and other operations by itself. 

C# needs to use the feature [DllImport] when calling the C++Dll library

2. DLL file

A DLL file is a dynamic link library, also called an assembly, which is a library containing code and data that can be used by multiple programs at the same time.

An assembly is a logical unit of functionality that runs under the control of the .NET common language runtime (CLR). Assemblies actually exist as .dll files or .exe files.

The DLL files generated by managed code can be directly used in VS by adding references.

The DLL files generated by unmanaged code, such as the DLL generated by compiling code written in C++, cannot be directly referenced in VS, and can be used through the DllImport method.

3. DLLImport use

1. Import the DLL file into the Unity project folder (Plugins)

2. Reference namespace

using System.Runtime.InteropServices;

3. Declare the function

[DllImport(“SDK”, EntryPoint=“Init”, CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Unicode)]

public static extern void Init(string EntName);

Notice:

  1. Characteristic parameters
    1.  DLL library file name
    2.  CallingConvention entry point calling convention
    3.  The charset used by the Charset entry point
    4. EntryPoint entry point name
  2. method
    1. return value
    2. parameter list

Guess you like

Origin blog.csdn.net/weixin_53163894/article/details/131678595