简体   繁体   English

vb.net参考程序集WithEvents无法正常工作

[英]vb.net Reference Assembly WithEvents not working

I have been searching this for forever and have not been able to find an answer so any help would be greatly appreciated! 我一直在搜寻此书,却一直找不到答案,因此不胜感激!

I am originally using this dll as an activeX control through .asp pages and it works perfectly. 我最初是通过.asp页将此dll作为ActiveX控件使用的,它工作得很好。 I am now having to rewrite it as a class because my boss asked me too. 我现在必须将其重写为一堂课,因为老板也问我。 So in my project I have right clicked and added reference name.dll. 因此,在我的项目中,我右键单击并添加了参考name.dll。 The FileType of this is Assembly. 该文件的FileType是Assembly。

so i created a variable 所以我创建了一个变量

Friend WithEvents scan As name.Integration.ActiveX.ActiveXObject

With this I am able to call its methods and it works perfectly at this point. 有了这个,我可以调用它的方法,并且在这一点上它可以完美地工作。 However, after I call a method it runs a process and starts waiting for a card to be inserted into the scanner. 但是,在我调用一个方法后,它会运行一个过程并开始等待将卡插入扫描仪中。 When a card is inserted into the scanner it is suppose to throw an event and then start scanning. 当将卡插入扫描仪时,应该引发一个事件然后开始扫描。

Once I insert a card it scans but the issue I'm having is my program is not catching any of the 50 events it is throwing. 一旦插入卡,它就会扫描,但是我遇到的问题是我的程序无法捕获所引发的50个事件中的任何一个。 Does anyone know how or why? 有谁知道如何或为什么? I'm desperately needing to fix this. 我非常需要解决此问题。

If I understand you correctly (and I'm reading between the lines here) you have an ActiveX control from a third party. 如果我正确理解您的意思(并且正在此处阅读),那么您有来自第三方的ActiveX控件。 Your previous web page used this control. 您先前的网页使用了此控件。 You now instead reference the dll that contains the ActiveX control, so VS automatically creates a .net wrapper around the ActiveX component. 现在,您改为引用包含ActiveX控件的dll,因此VS会自动在ActiveX组件周围创建一个.net包装器。 Is that correct? 那是对的吗?

If yes, confirm you are referencing the correct type from the correct libary. 如果是,请确认您从正确的库引用了正确的类型。

  1. Use the Object Browser to view the dll's types. 使用对象浏览器查看dll的类型。 I think you'll find you have two libraries associated with the dll. 我想您会发现您有两个与dll相关联的库。 For example, assume your library is named "ThirdParty". 例如,假设您的库名为“ ThirdParty”。 You may see "AxThirdParty" as well as "Interop.ThirdParty". 您可能会看到“ AxThirdParty”以及“ Interop.ThirdParty”。 The "interop" library contains most classes. “互操作”库包含大多数类。 However, the "Ax..." library is key to handling events. 但是,“ Ax ...”库是处理事件的关键。 Your object that declares events from be from this library. 声明事件的对象来自此库。 If you don't see this libary, you may need to add the control to a Windows .net form to get VS to create it for you. 如果您没有看到此库,则可能需要将控件添加到Windows .net表单中,以使VS为您创建它。

  2. Don't try to handle events in the "Ax..." library that are hidden. 不要尝试处理“ Ax ...”库中隐藏的事件。 Note that handling hidden events does not cause compile errors, but nor do they ever get raised. 请注意,处理隐藏事件不会导致编译错误,但是也不会引发错误。 Do you see the event your trying to handle in the "Ax..." library? 您是否在“ Ax ...”库中看到要处理的事件? If so, is it shown in light gray? 如果是这样,是否以浅灰色显示? Note that VS will rename any interop event that conflicts with standard control events. 请注意,VS将重命名与标准控制事件冲突的任何互操作事件。 For example, the ActiveX control's click event gets named "ClickEvent" and it is the ClickEvent event you want to handle, not the Click event. 例如,ActiveX控件的click事件被命名为“ ClickEvent”,它是您要处理的ClickEvent事件,而不是Click事件。

Note that above applies to Windows forms. 请注意,以上内容适用于Windows窗体。 I think Hans is right about the message loop. 我认为Hans对消息循环是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM