Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert the COM interface of C #

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to convert the COM interface of C#". In the daily operation, I believe many people have doubts about how to convert the COM interface of C#. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to convert the COM interface of C#". Next, please follow the editor to study!

C # supports not only the .net platform, but also the COM platform. To support COM and .net, C # contains a unique language feature called attributes. An attribute is actually a C # class that provides meta-information by decorating the source code. Properties enable C # to support specific technologies, such as COM and .net, without interfering with the language specification itself. C # provides property classes that convert COM interfaces to C # interfaces. Other property classes convert the C # COM interface to a C # class. No IDL or class factory is required to perform these transformations.

Any COM component that is now deployed can be used in interface transformation. Typically, the required adjustments are completely automatic.

In particular, COM components can be accessed from the .NET Framework using runtime callable wrappers (RCW). This wrapper converts the C # COM interface provided by the COM component into an interface compatible with the .NET Framework. For OLE automation interfaces, RCW can be automatically generated from the type library; for non-OLE automation interfaces, developers can write custom RCW to manually map the types provided by the COM interface to types compatible with the .NET Framework.

The following is the C# program for interface conversion:

Using System.Runtime.InteropServices; / / declare a COM interface IMediaControl [Guid ("56A868B1-0AD4-11CE-B03A-0020AF0BA770"), InterfaceType (ComInterfaceType.InterfaceIsDual)] interface IMediaControl / / No base interface {void Run (); void Pause (); void Stop (); void GetState ([In] int msTimeout, [Out] out int pfs); void RenderFile ([In, MarshalAs (UnmanagedType.BStr)] string strFilename) Void AddSourceFilter ([In, MarshalAs (UnmanagedType.BStr)] string strFilename, [Out, MarshalAs (UnmanagedType.Interface)] out object ppUnk); [return: MarshalAs (UnmanagedType.Interface)] object FilterCollection (); [return: MarshalAs (UnmanagedType.Interface)] object RegFilterCollection (); void StopWhenReady ();} at this point, the study on "how to convert the COM interface of C#" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 264

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report