有人可以帮我处理来自C

有人可以帮我处理来自C

本文介绍了有人可以帮我处理来自C#DLL的vb6中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现NFC卡读取很好的应用程序,在winforms中可以很好地工作.

I have found nice application for NFC card reading which in winforms works very nice.

在这里找到代码

NfcReader:一个非常简单的C#NFC库,支持插入和丢弃事件

Git: https://github.com/h4kbas/NfcReader

但是我有一个问题.我现在需要在com中为vb6进行这项工作.

But i have a problem. I need now to make this work in com for vb6.

我必须复制"事件挂钩,如下面的代码所示.

I must "replicate" event hooking, like in the following code.

我成功地向vb6公开了方法和事件.

I exposed methods and events to vb6 successfully.

NFC = new NFCReader();

NFC.CardInserted += new NFCReader.CardEventHandlerDelgate(Card_Inserted);
NFC.CardEjected += new NFCReader.CardEventHandlerDelgate(Card_Ejected);
NFC.DeviceDisconnected += new NFCReader.CardEventHandlerDelgate(Device_disconected);
NFC.StartCardMonitoring();

推荐答案

使用提供的@kunif信息,首先必须使.NET库COM可见,才能在VB6中使用NFC阅读器.如果您有源代码,则可以很容易地做到这一点.否则,如果您只有DLL,则可以编写包装DLL并使该COM可见.听起来当您说我已成功将事件和方法公开给vb6"时,您可能已经完成了此操作.

With the information @kunif provided, you first have to make the .NET library COM Visible in order to use the NFC Reader in VB6. If you have the source code, you can do this fairly easily. Otherwise, if you just have a DLL, you can write a wrapper DLL and make that COM Visible. Sounds like you might've done this already when you say "i exposed events and methods to vb6 successfully".

下一步是在VB6中添加对该库的引用:项目">引用...".

The next step is to add a reference to the library in VB6: Project > References...

然后,您可以创建NFCReader的实例:

Then, you can create an instance of the NFCReader:

Public WithEvents objNFC As NFCReader

Private Sub Form_Load()

    ' Create NFCReader object
    Set objNFC = New NFCReader

    objNFC.StartCardMonitoring

End Sub

' Card Inserted event handler
Private Sub objNFC_CardInserted()
    ' Handle Card Inserted event
End Sub

' Card Ejected event handler
Private Sub objNFC_CardEjected()
    ' Handle Card Ejected event
End Sub

' Device Disconnected event handler
Private Sub objNFC_DeviceDisconnected()
    ' Handle Device Disconnected event
End Sub

一旦添加了对DLL的引用,您应该会看到事件及其参数显示在VB6中.确保将对象声明为WithEvents,并且该对象将出现在Visual Studio的代码窗口的左侧下拉列表中.右侧的下拉列表将显示可用事件.

Once you've added a reference to the DLL, you should see the events and their parameters show up in VB6. Make sure you declare the object as WithEvents and the object will appear in the left dropdown in the code window in Visual Studio. The right dropdown will display the available events.

这篇关于有人可以帮我处理来自C#DLL的vb6中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:45