1. Create a class library mytestdll.
2. Right-click the project "mytestdll"-"properties-" generate-"and select" register for com"
3 open the assemblyinfo. CS file and modify [Assembly: comvisible (true)]
4. Open the command line prompt of visual sudio 2008, input guidgen.exe, select define_guid, and click "New guid"
5 code
1. Each class name corresponds to an interface name. The interface name is preceded by a capitalized I
2. Attribute [dispid (n)] should be used for the method declared in the interface
3. The class must have a non-argument constructor.
Code
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. runtime. interopservices;
Namespace mytestdll
{
// Here, The GUID is generated in step 1.
[GUID ("FFA4B191-FB5B-4dd5-B7B1-B2F32BF6F1FF")]
Public interface imytestdll
{
[Dispid (0)]
String getabout ();
}
Public class test1: imytestdll
{
Private string summary;
Public test1 ()
{
Summary = "this is my first test ";
}
Public String getabout ()
{
Return summary;
}
}
}
6. Generate a project
ASP test code
<%
Dim o
Set o = server. Createobject ("mytestdll. test1 ")
Response. Write O. getabout ()
Set o = nothing
%>
Tip: If you want to use this COM component developed by C # on another computer, you still need to use regasm to register it.
Method:
First, copy the files in the bin \ DEBUG directory to the target computer, and then open the command prompt line tool and enter:
Regasm the directory/file name you copied to. dll/tlb f:/dll/file name. TLB/codebase
Running can be used on this computer.
References:
Http://topic.csdn.net/u/20080625/13/0294fe91-200c-4939-b36b-c9a2c6781354.html
Http://topic.csdn.net/t/20060314/15/4613620.html
Http://cplus.e800.com.cn/articles/2009/211/1234338268521_3.html
Http://topic.csdn.net/t/20020712/10/868557.html
Http://www.itzhe.cn/news/20071123/21768.html
Http://www.cnblogs.com/illele/archive/2007/10/25/937050.html