Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Building the object is very easy - registering it and managing the COM dependency can be quite tricky.</p> <p>Your .NET project should be a class library, and your class can be a straightfoward C# / .NET CLR object:</p> <pre><code>namespace MyCompany.MyProject.Com { public class MyObject { public int Width { get; set; } public int Height { get; set; } public void Load(string location) { /* implementation here */ } public void Resize(int width, int height) { /* implementation here */ } } } </code></pre> <p>Right-click your project, select Properties, Application, click Assembly Information... and ensure that "Make assembly COM-Visible" is selected at the bottom of the Assembly Information dialog.</p> <p>Build your project - you should end up with MyCompany.MyProject.Com.dll in your \bin\debug\ folder.</p> <p>Build a simple ASP webpage that looks like this:</p> <pre><code>&lt;% option explicit %&gt; &lt;% dim myObject set myObject = Server.CreateObject("MyCompany.MyProject.Com.MyObject") myObject.Width = 20 myObject.Height = 40 %&gt; &lt;html&gt; &lt;head&gt;COM Interop Demo&lt;/head&gt; &lt;body&gt; &lt;p&gt;Width + Height = &lt;%= myObject.Width + myObject.Height %&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Bring up that page on <a href="http://localhost/" rel="nofollow noreferrer">http://localhost/</a> and verify that you get "Server.CreateObject failed" the first time you try and run it.</p> <p>Now register your DLL as a COM object using regasm.exe, installed with the .NET framework:</p> <pre><code>C:\&gt;C:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe /tlb MyCompany.MyProject.Com.dll /codebase Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.4927 Copyright (C) Microsoft Corporation 1998-2004. All rights reserved. Types registered successfully Assembly exported to 'D:\WebDlls\MyCompany.MyProject.Com.tlb', and the type library w as registered successfully </code></pre> <p>Now refresh your web page, and you should see <strong>Width + Height = 60</strong> in your output.</p> <p>These instructions assume you're not running anything in 64-bit; if you are, it gets more complex. (You either need to run <em>everything</em> as 64-bit - compile a 64-bit project and use the 64-bit version of regasm.exe to register it for 64-bit COM, accessed by IIS running a 64-bit scripting host) - or manually force everything to 32-bit.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload