ASP and VB call the DLL compiled by. Net (Supplement: add the source file)

Source: Internet
Author: User
Tags net command
. Net DLL is not a dynamic link library, but a Type Library. CCW is required to call it as COM. The following is an instance.

First, create the project comlib of A Class Library and write an interface. the object to be called by com implements this interface and a class to implement this interface, if you want to create an object using Createobject in VB or ASP, you need a constructor without parameters. The Code is as follows:
Using system; using system. windows. forms; namespace comlib {// defines the interface. This is very important (the methods in this interface are the same as those in the COM component) public interface iclass1 {void say (string word );} public class class1: iclass1 {public void say (string word) {MessageBox. show (Word );}}}
Run the Visual Studio 2005. Net command prompt and run Sn-K comlib. SNK to generate an SNK signature file comlib. SNK. To make the type visible in COM, you need to set this [Assembly: comvisible (true)] In the assemblyinfo. CS file. Add a [Assembly: assemblykeyfile ("file path \ comlib. SNK ")] In Solution Explorer, select project> right-click and choose Properties> Generate tab> Register com InterOP, in this way, the COM component is automatically registered when the project is created. After the project is generated, you can call COM. Here, we use VB as an example to create an EXE project and add references to comlib. TLB. Some files are in the bin directory. Then use the following code to call
Option explicit private sub form_load () dim IC as iclass1 set Ic = new class1 IC. Say "Hello Jerry! "'Use this method in ASP dim a set a = Createobject (" comlib. class1 ") end sub
A message box appears after the project is run. Indicates that the call is successful. The above com registration is automatic registration, but sometimes manual registration is required. For example, if you want to use the Type Library on another computer, there is no Visual Studio 2005 on that computer. To manually register an assembly, follow these steps: (1) Use the regasm tool to register the Assembly, run the Visual Studio 2003. Net command prompt, and run regasm comlib. dll/TLB: comlib. TLB.
(2) Use the gacutil tool to install the DLL assembly to the Global Assembly Cache. Run the Visual Studio 2003. Net command prompt and then run gacutil/I comlib. dll.

Attached source file download: clsin.rar

 

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.