Com application Summary (3/3) COM component in C #

Source: Internet
Author: User

Due to the wide application of. net, the interoperability problem between C # and COM is often encountered in daily work. To be more complete, This article summarizes the situation of C # Processing com as follows:

In C #, It is very convenient to interoperate with COM, specifically as follows:

No Pia

C #4.0 dynamic features introduced
Guid ID;
Id = new GUID ("D7D0B2E8-1795-4E23-96BF-F07EC28FB44C ");
Dynamic complug = activator. createinstance (type. gettypefromclsid (ID ));
String T = "DLR", R;
Complug. dowork (T, out R );
Console. writeline (R );

Pia

First, add a referncereference group in the IDE to automatically generate a database (you can also manually generate a database using tlbimp.exe)

Compluglib. mykit kit = new compluglib. mykit ();
Kit. dowork (T, out R );
 
You can use
Marshal. *** processes COM objects

The following is a comparison of C # different versions of office operations

Due to the wide application of. net, the interoperability problem between C # and COM is often encountered in daily work. To be more complete, This article summarizes the situation of C # Processing com as follows:

In C #, It is very convenient to interoperate with COM, specifically as follows:

NO Pia

 C #4.0 introduces dynamic features 
 guid ID; 
id = new GUID ("D7D0B2E8-1795-4E23-96BF-F07EC28FB44C");
dynamic complug = activator. createinstance (type. gettypefromclsid (ID);
string T = "DLR", R;
complug. dowork (T, out R);
console. writeline (r);

Pia

First, add a referncereference group in the IDE to automatically generate a database (you can also manually generate a database using tlbimp.exe)

Compluglib. mykit kit = new compluglib. mykit ();
Kit. dowork (T, out R );
 
You can use
Marshal. *** processes COM objects

The following is a comparison of C # different versions of office operations

/// C #4.0

Dynamic word = activator. createinstance (type. gettypefromprogid ("Word. Application"); Word. Visible =True; Var wordapplication =NewMicrosoft. Office. InterOP. Word. Application (); wordapplication. Visible =True;ObjectMissing = system. reflection. Missing. value;ObjectFile = @"C: \ test.txt";ObjectVisible =True;ObjectReadonly =False;
 
 
// You need to introduce Microsoft. Office. InterOP. Word. dll (vs installation)
// C #4.0 named and optional parameters
VaR betterway = wordapplication. Documents. Open (file, readonly: True, visible: True );
Betterway. Activate ();
Betterway. Close ();

// C #1.0 ~ 3.5 (. net3.0 has a simplified operating library office) http://www.microsoft.com/downloads/details.aspx? Familyid = 46b6bf86-e35d-4870-b214-4d7b72b02bf9 & displaylang = EN vsto_ptextlibs.exe
Document adoc = wordapplication. Documents. Open (
Ref file, ref missing, ref readonly, ref missing,
Ref missing, ref missing,
Ref missing, ref visible,
Ref missing, ref missing );
Adoc. Close ();

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.