簡體   English   中英

如何在外部dll中引用入口點(C#/ Unity 3D)

[英]how to reference entry point in an external dll (C# / unity 3D)

我正在為需要使用串行端口的應用程序使用Unity 3D,但是在Unity中,缺少事件DataReceived和其他鏈接函數的實現。 因此,我認為解決方案是使自己的DLL可以管理串行端口數據,並作為一個外部DLL統一調用它。

我寫了下面的代碼。 我的類庫項目中的代碼(只是為測試凍結了一個串行端口)

碼:

using System;
using System.IO.Ports;

namespace serialPortManager2
{
    public class laserManager
    {
        private SerialPort laserComPort;

        public bool  open()
        {
            bool laserSerialPortDetected = false;
            // ouverture du port série pour pilotage du laser
            foreach (string portName in SerialPort.GetPortNames())
            {
                if (portName == "COM4") laserSerialPortDetected = true;
            }
            if (laserSerialPortDetected)
            {
                laserComPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
                laserComPort.Open();
                if (laserComPort.IsOpen)
                {
                    // timeout de lecture d'une mesure laser
                    laserComPort.ReadTimeout = 5000;
                    return true;
                }
                else return false;
            }
            else return false;
        }
    }
}

在Unity中引用DLL的代碼:

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public static class SPNativePlugIn {

// The name of the external library containing the native functions
private const string LIBRARY_NAME = "serialPortManager2";

[DllImport(LIBRARY_NAME)] public static extern bool open();

}

我的問題是出現此錯誤: EntryPointNotFoundException: open

我想我必須在某個地方集成laserManager類,但是我不知道語法,我嘗試了很多事情,但找不到。

在“ Assets”文件夾中創建一個名為“ Plugins”的文件夾,然后將您的.dll文件放入“ Plugins”文件夾中,並using dllFileName;以此方式將其導入腳本中using dllFileName;

適用於未包含在統一默認庫中的每個.dll

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM