Use. NET2.0 write COM components for Visual Basic calls

Source: Internet
Author: User

  1. Defining interfaces

COM is called by an external application by throwing an interface, and each interface, component has a GUID, and developing COM components in. NET is no exception.

[Guid ("0bb13346-7e9d-4aba-9ff2-862e0105489a")]

public interface Imyservice

{

Defines an interface method or attribute, each of which has a DispID property for use by VBScript, etc.

[DispId (1)]

void Method1 (args ...);

}

  2. Derived classes that implement interfaces

GUID property defines the GUID of the component

ProgID defines ProgID for COM components

[Guid (

"ba0a3019-f0d8-4406-8116-f80d5515c686"),

ProgId ("Classnamespace.myservice"),

ClassInterface (

ClassInterfaceType.None)]

public class

Myservice:imyservice

{

...//Implementation Code section

}

  3. Conversion of. NET fittings to public assembly parts

(1) Create strong names

Sn–k mykey.snk

and copy the strong name to the engineering directory.

Modify the corresponding configuration in AssembyInfo.cs

[Assembly:assemblykeyfile (".. /.. /mykey.snk ")]

(2) Export type library

In order to be used in VB, you must export the COM type library using Tlbexp.exe.

TlbExp siscallib.dll/out:siscallib.tlb

(3 Registration Fitting

REGASM MyService.dll

(4) Add accessories to the GAC

Gacutil-i MyService.dll

Note: This step is not required.

(5) Modify COM external visibility configuration in AssembyInfo.cs

Set ComVisible to False so that the type in this assembly

is not visible to COM components. If you need to access the types in this assembly from COM,

The ComVisible property on the type is set to true.

[Assembly:comvisible (True)]

If this project is exposed to COM, the following GUIDs are used for the ID of the type library

[Assembly:guid ("e011ed16-93a3-41aa-8375-399fa259b935")]

After the above work, it will be one. NET fitting into COM components.

  4. Call the generated COM component (DLL) in VB

1) Engineering-> Reference

2) Create an object call

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.