Common routines in C #

Source: Internet
Author: User
Tags static class
0. Call the COM component from C # (post-connection)
The. NET Framework is a natural development of COM. The two share many core elements, including reuse of components and language.
For backward compatibility, COM Interop can use existing COM components instead of modifying the original components. When
When framework developers want to merge COM code into a management application, they can use the COM Interop function to introduce related CO
Type. After the introduction, this COM type can be used. This is a preliminary connection. But sometimes you need the Chinese-term connection of the object,
This can also be implemented in. NET. Using namespace ing, you can call COM objects through post-connection.
    
This section describes an application routine, which calls Excel and visualizes it by using a later connection.
Later connections will use the Type class of Reflectionb, which has many methods to obtain COM objects,
GetTypeFromProgID ("Application"). This method obtains the com id from the system registry,
Then, use Activator. CreateInstance (), a member of the STATIC class, to create a new example of this COM object.
    
To call methods, functions, and attributes of a COM object, you must use the InvokeMethood () method that contains the correctly set Type object.
This method accepts some parameter variables. The most important one is the ex attribute (get or set) of the method type ). In the example, we?
Excel. Visible uses the set attribute to make the Excel application Visible.
We will try to call the Excel application in the. NET environment. This is a later connection application, because if the connection is broken
You need to use the RCW (RunTime Callable Wraper) of the COM object to complete the tasks assigned by the following command line program tblimp:
Ex. c:> tblimp/out:
    
// Variable
Type excel;
Object [] parameter = new object [1];
Object excelObject;
Try
{
Excel = Type. GetTypeFromProgID ("Excel. Application ");
ExcelObject = Activator. CreateInstance (excel );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.