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