简体   繁体   English

在C#.net中使用COM接口

[英]Using COM Interface in C#.net

Sorry if my question is so primitive. 对不起,如果我的问题是如此原始。 I'm a beginner in C# and I should use a COM Interface (.DLL) and implement it in my code. 我是C#的初学者,我应该使用COM接口(.DLL)并在我的代码中实现它。 It's about a time attendant clock and I need to retrieve data out of its database. 这是一个时间服务器时钟,我需要从其数据库中检索数据。 It uses some classes and my goal is to retrieve "Messages" out of it. 它使用了一些类,我的目标是从中检索“消息”。 The only documentation I have is this: 我唯一的文件是:

The “InsightClass” class contains the following: “InsightClass”类包含以下内容:

Methods 方法

... ...

o GetReviewMessages

o InsightClass

o Login

o Logout

o ReviewMessage

Review Events: 评论活动:

The ReviewMessage event will fire every time a new Review event is received in Insight. 每次在Insight中收到新的Review事件时,都会触发ReviewMessage事件。

Retrieving data: Using the “StartLiveReview” method will begin the receipt of new review messages from the Insight server, conversely, this process is ended with the “EndLiveReview” method. 检索数据:使用“StartLiveReview”方法将开始从Insight服务器接收新的审阅消息,相反,此过程以“EndLiveReview”方法结束。 One can also retrieve a discrete set of Review data by means of the “GetReviewMessages” method. 还可以通过“GetReviewMessages”方法检索一组离散的Review数据。 One specifies the desired date/time boundaries within which data is to be retrieved. 一个指定要在其中检索数据的所需日期/时间边界。 Insight review: 洞察力评论:

The above methods will result in a collection of “InsightReview” objects. 上述方法将生成“InsightReview”对象的集合。 Using the “InsightReviewMessagesClass” class, one can obtain the current count of “InsightReview” objects and access individual “InsightReview” objects by means of the “Item” property. 使用“InsightReviewMessagesClass”类,可以获取“InsightReview”对象的当前计数,并通过“Item”属性访问各个“InsightReview”对象。 An “InsightReview” object is effectively a Review message. “InsightReview”对象实际上是一条Review消息。 It has the following properties: 它具有以下属性:

o ... o ......

o Message o消息

Could you please let me know how can I relate “GetReviewMessages” method to “InsightReview” objects within “InsightReviewMessagesClass” class in my code? 您能告诉我如何将“GetReviewMessages”方法与我的代码中“InsightReviewMessagesClass”类中的“InsightReview”对象相关联?

Thanks a heap in advance... 提前感谢一堆...

Basically you need to add a reference the COM DLL from inside Visual Studio and it will create a new .NET DLL that wraps around the COM DLL and allows you to use the COM DLL from C#. 基本上你需要从Visual Studio内部添加COM DLL的引用,它将创建一个新的.NET DLL,它包装COM DLL,并允许您使用C#中的COM DLL。 In short you do the following steps: 简而言之,您执行以下步骤:

  1. Select Project > Add Reference 选择Project> Add Reference
  2. Select the COM tab in the Add Reference dialog box. 在“添加引用”对话框中选择“COM”选项卡。
  3. Scroll down the list of COM components until you find your COM DLL/library, select it and click OK. 向下滚动COM组件列表,直到找到COM DLL /库,选择它并单击“确定”。

Essentially the above steps get Visual Studio to run Tlbimp for you to generate a .NET DLL that is a wrapper around the COM object. 基本上上面的步骤让Visual Studio运行Tlbimp来生成一个.NET DLL,它是COM对象的包装器。

A good tutorial is here (the first part with all the code is just explanatory to help you understand what is happening, don't be overwhelmed, jump to the Example 1: Using TlbImp section for actual steps you need to follow). 这里有一个很好的教程(第一部分,所有代码只是解释性的,以帮助您了解正在发生的事情,不要被淹没,跳转到示例1:使用TlbImp部分执行您需要遵循的实际步骤)。

If you still have problems give us more information such as what steps you are able to take successfully and maybe a paste of the code from the "Code Definition Window" for the COM Class that you reference which should show the methods you refer to above. 如果您仍有问题,请向我们提供更多信息,例如您可以成功执行哪些步骤,以及可能粘贴您引用的COM类的“代码定义窗口”中的代码,该代码应显示您在上面引用的方法。

There must be one event handler in that which inform you when data InsightReview arrived 必须有一个事件处理程序,它会在数据InsightReview到达时通知您

so subscribe that event from class with appropriate function in your wrapper class. 所以在你的包装类中使用适当的函数从类中订阅该事件。

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

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