Develop COM + components using C #

zhaozj2021-02-17  60

.NET

Technology is the next-generation platform technology that Microsoft vigorously promotes

.NET

Technology Architecture

Beta2

The formal release of the version, this technology has gradually moved to maturity and stability. According to Microsoft's platform system, we don't want to think about it, within the next year or two

.NET

Techniques must have the mainstream technical platform, and a new technical platform is the most important premise of rapid development is: he will not completely abandon the previous technology, this is

.NET

Technical means

COM / COM

Technology.

In general, in the IT technology circle and hardware industry, the upgrade speed of technology is very amazing, and the practice is all new technologies to follow the principle of downward compatibility, but .NET technology not only did this, .NET or even Implementation of each call between each other, this is very difficult to be valuable. That is, not only we can call COM components in the .NET component, but also call the .NET component in the COM component. The benefits of this point are obvious, on the one hand, we can maintain existing technical resources, on the other hand, in the existing resources, can take advantage of the various new technologies brought by .NET. Generate a GUID with the SN command in the E / CLASSLIBRARY1 / directory, as shown below:

Sn -k keyfile.snk

Add the following statement in the project's assemblyinfo.cs file:

[assembly: assemblykeyKeyfile (@ "e: /classlibrary1/keyfile.snk")]]

The role is to make the DLL file created by this project file with GUID (global unique identifier), which is a strong name, which is COM requirements.

The detailed code of the CS is as follows:

Using system;

Using system.Runtime.InteropServices; // To call GUID

Using system.enterpriseservices; // Quote Cam class

Using system.Web.services;

Namespace Classlibrary11

{

// If you do not specify a GUID, you will randomly generate CLSID each time.

[GUID ("539448DE-9F3B-4781-A1F6-F3C852091FC9")]]

Public Interface IsharPObject2

{

String name // Property: Name, Get / Set

{

Get;

SET;

}

Void test ();

}

Public Class Class1: Servicedcomponent, IsharPObject2

{

Public class1 ()

{

//

// Todo: add constructor logic here

//

}

PRIVATE STRING M_STRNAME;

Public String Name // Property: Name, Get / Set

{

Get {return m_strname;}

Set {m_strname = value;

}

Public void test () {}

}

}

After generating a DLL file, there can be three methods, create a COM application in the COM management server, where the method used is to use the command under DOS operation.

Regsvcs / c class1.dll mycom "Mycom is the COM app name to generate"

转载请注明原文地址:https://www.9cbs.com/read-28696.html

New Post(0)