ASP.NET calls COM

zhaozj2021-02-16  66

Write a COM component using ATL COM AppWizard in VC Z. The "TLBIMP.EXE" is used in VS.NET, generates a fitting from the COM component, so that the control code can access the COM component object by accessing this install object.

Use ILDASM.EXE (VS.NET self-contained tool) to view the generated assembly.

Figure

As shown: In the assembly, we mainly pay attention to these interface functions:

System.String getFile ()

Void setCMD (System.Int32 nstepnum)

void setfile (system.string bstrfilein)

New void setlog (system.string bstrfilein)

It is the interface function that we have defined in COM. Then, add a reference to the assembly generated on the ASP.NET to implement the COM components in the C # code of the ASP.NET.

Try

{

Runlib.compileclass mc = new runlib.compileclass ();

Runlib.icompile IMC = (Runlib.icompile) MC;

TextBox1.text = imc.getfile ();

// The following is used for garbage collection

MC = NULL;

IMC = NULL;

Gc.collect ();

Gc.waitforpendingfinalizers ();

Gc.collect ();

}

Catch (Exception EX)

{

Label5.text = "Exception:" ex.Message;

}

COM components registration and configuration. (Take Widows 2000 as an example, Windows Server 2003 and Windows XP is similar)

Click Start, "Run", fill in cmd.exe, and then determine. In the command line window, enter the CD switch path to the directory where the component is the EXE file: Enter the component name .exe / regserver, Enter; if the component is a DLL file, enter the regsvr32 component name .dll, Enter; Close command Row window. Click Start, "Run", fill in DCMCNFG.EXE, press Enter.

Check the Server, click Properties Click Security, select "Use Custom Start Permissions", click Edit, Add User ASPNET, Access Type: Allow call. Once all the way, exit the "Distributed COM Configuration" program.

转载请注明原文地址:https://www.9cbs.com/read-20007.html

New Post(0)