Any good tutorials on using COM from C#? [closed]

2019-01-21 01:13发布

For one of a side-projects i need to write a C# app that required to use a third-party INPROC COM object. Unfortunately, C# is not my primary programming language, so my knowledge is a bit limited. Is it any good tutorials available on how to access COM object from C#? The usage of this third-party COM object requires me to create implementation of specified COM interface and supply that implementation into COM object in order for it to function.

标签: c# com
4条回答
三岁会撩人
2楼-- · 2019-01-21 01:52

The basics are pretty straightforward, and MSDN has good reference information.

In your C# project, use "Add Reference" to add a reference to the COM component.

If you need to implement a COM interface, create a class that inherits from it:

class MyClass : IMyComInterface
{
   ...
}
查看更多
走好不送
3楼-- · 2019-01-21 02:05

I have quite a large .NET <-> COM bookmark collection that I'm dumping below.

The problem is that no one tutorial/article covers all the basics and gotacha's. So you need to go through a couple of them and mix and match, depending on what you want to do.

Here's the best of what I've found so far...

General .NET COM Articles/Tutorials

MSDN on .NET & COM

ActiveX in .NET

查看更多
太酷不给撩
5楼-- · 2019-01-21 02:13

There is a good book called .NET and COM: The Complete Interoperability Guide that I am about to start reading as I want a better understanding of COM interop. Maybe it would be useful for you too, check it out.

The focus of the book is on COM Interoperability (since it's a much larger subject), and the heart of the discussion is broken down into four parts:

* Using COM Components Within the .NET Framework
* Using .NET Framework Components from COM
* Designing Good .NET Framework Components for COM Clients
* Designing Good COM Components for .NET Framework Clients

The scope of the book is just about everything related to using "unmanaged code" in the .NET Framework. Technologies built on top of COM Interoperability are also covered-Interoperability of Windows Forms Controls and ActiveX controls, Interoperability with COM+, and Interoperability with Distributed COM (DCOM). Although Platform Invocation Services is a separate technology from COM Interoperability, there are many areas of overlap, so including in the book is a natural fit. All of these technologies are a core part of the Common Language Runtime and .NET Framework, and will likely be used not only as the path of migration for existing software projects, but for brand new software development for the next several years

Also have a look at this (legally) free pdf ebook COM and .NET Interoperability which you can download from TheServerSide.com. You have to register before you can download, but you can just bugmenot if you don't feel like it.

查看更多
登录 后发表回答