c# - 如何将回调委托(delegate)传递给 .netCF 中的 dll

标签 c#

我正在编写一个 .netCF 应用程序,它连接到不同硬件平台上的条码扫描仪。 I. E. Motorola 或 Intermec 等。我用我自己的 DLL 包装了他们的 DLL 以呈现一个通用接口(interface),我在运行时使用 Reflection LoadFrom() 加载我的 dll,然后获得方法引用。

除了一个异常(exception),我能够将大多数参数传递给我的 dll 中的方法。我需要将回调函数传递给 dll,以便在发生读取时它会回调到主程序中以处理条形码读取。

当我调用该方法时,它抛出一个 ArgumentException。

我的问题是如何将此方法引用传递给我的 dll,或者有更好的方法吗?

    public delegate void ReadNotify(BCReadData readData);

    public void AttachReadNotify(ReadNotify ReadNotifyHandler)
    {
        if (type == ReaderType.UNKNOWN || scanIntf == null)
            return;
        try
        {
           setReadNotify.Invoke(scanIntf,new Object [] {ReadNotifyHandler});
        }
        catch (Exception e)
        {
            throw new Exception("Unable to set notify handler" + e.Message);
        }

    }

最佳答案

如果您的 native 回调使用 __stdcall 调用约定,您可以使用 Marshal.GetFunctionPointerForDelegate 来完成此操作方法。

关于c# - 如何将回调委托(delegate)传递给 .netCF 中的 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8980618/

相关文章:

c# - Windows Phone 7.1 "Send To"功能?

c# - 为什么在添加到集合时不为所有对象调用 Equals()

c# - MySQL try-catch 无法正常工作

c# - 测试远程客户端-服务器应用程序

c# - Ping 到存储过程以了解在 .net 中完成的执行?

c# - $ - 字符串插值实时编译 - 从文件

c# - 如何在 UWP 后台任务中使用 XAML UI 元素?

c# - 最小起订量从带参数的方法返回新对象

c# - 编写 .x 文件

c# - 了解 MonoTouch 绑定(bind)中的 Objective C 委托(delegate)