我正在编写一个 .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/