ASP invoke COM component Instance compiled by C #

Source: Internet
Author: User

1 new Class library Mytestdll





2 Right-click Project "Mytestdll"-"Properties-" Generate-"Check for COM Interop registration"





3 Open AssemblyInfo.cs file modification [Assembly:comvisible (true)]





4 Open the Visual Sutdio 2008 Command Prompt line tool input Guidgen.exe Select Define_guid Click New GUID





5 Code





1, each class name corresponds to an interface name, the interface name is the class name preceded by an uppercase I





2, the method declared in the interface uses the attribute [DispId (n)]





3, the class must have a parameterless 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 for step 4th.


[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 Build 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 the COM component that we developed with C # on other computers, we still need to register with RegAsm




The
method is:





first copy the files of the Bindebug directory to the target computer, and then open the command prompt line tool input:


regasm you copy to the directory/filename. dll/tlb f:/dll/filename. tlb/codebase





running can be used on this computer.


Related Article

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.