Use ASP to call the COM component written in C #

Source: Internet
Author: User

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



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.