繁体   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