简体   繁体   中英

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. 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:

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.

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. One can also retrieve a discrete set of Review data by means of the “GetReviewMessages” method. 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. Using the “InsightReviewMessagesClass” class, one can obtain the current count of “InsightReview” objects and access individual “InsightReview” objects by means of the “Item” property. An “InsightReview” object is effectively a Review message. It has the following properties:

o ...

o Message

Could you please let me know how can I relate “GetReviewMessages” method to “InsightReview” objects within “InsightReviewMessagesClass” class in my code?

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#. In short you do the following steps:

  1. Select Project > Add Reference
  2. Select the COM tab in the Add Reference dialog box.
  3. Scroll down the list of COM components until you find your COM DLL/library, select it and click OK.

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.

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).

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.

There must be one event handler in that which inform you when data InsightReview arrived

so subscribe that event from class with appropriate function in your wrapper class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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