Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 27th, 2006, 09:17 PM
Registered User
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Making COM Object For ASP.NET Use

Not sure if this is the right board, but here it goes.

I'm trying to learn how to create a COM object in a C++ DLL, register it properly, and then use it in a .aspx page.

My [desired] usage is this: (custom math class and add function used for simplicity to learn):
<%@ Page Language="VB" Debug="true" aspcompat="true" %>
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
 Dim oMath=Server.CreateObject("MathX.CCalculator.1")
 Dim c=0
 oMath.Add(1,2,c) 'c should be 1+2=3
End Sub
Then I created and registered the DLL, but when I run the aspx page I get this error:
"System.NullReferenceException: Object reference not set to an instance of an object."
It is referring to the oMath object being null. So, now I'm not sure what I need to add to my DLL to make this work... I have the 4 COM functions created and then exported like such in the DEF file:
    DllCanUnloadNow        PRIVATE
    DllGetClassObject    PRIVATE
    DllRegisterServer    PRIVATE
    DllUnregisterServer    PRIVATE

And I have an ICalculator interface, a CCalculator object class, and a CFCalculator class factory implemented.

Can someone point me in the right direction? Or where to look? I'm not even sure where the problem would be. I can give specific code of the C++ DLL if necessary.

Old September 30th, 2006, 10:06 PM
Registered User
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

I think the problem lies somewhere in the Server.CreateObject() method call. When I looked it up on MSDN, it said that it creates an instance of a registered component (so that IIS can access it?), so I figure my problem is either is related to not creating the object correctly in the DLL, or to not registering the object correctly.

I'm thinking the second is more likely (and I'm hopeful that it is the second one, as it would be easier to figure out how to fix), and so I need to know if I'm registering it right.
So far, all I'm doing to register it is adding the following to the registry:
HKEY_CLASSES_ROOT\CLSID\{...} ("...", replace with UUID) 
  default value: "Simple COM Test Class"
  default value: [filepath]
  ThreadingModel: "Apartment"
  default value: "MathX.CCalculator.1"

  no default value
  default value: {...} (UUID again)

So basically its a bunch of referencing- the prog id gives the UUID which gives the prog id and the filepath of DLL. Do I need anything else?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Placing HTML object in ASP.NET toddw607 ASP.NET 2.0 Basics 3 April 30th, 2008 03:58 PM
remote connection object in asp.net nirmalbarsainyan ASP.NET 2.0 Basics 1 August 9th, 2007 06:27 PM
Making a COM object in VB.NET Cohadar Pro VB.NET 2002/2003 0 March 30th, 2006 06:49 AM
Making a text object writable sureshbabu Crystal Reports 0 December 16th, 2004 01:29 AM
Instanciate .net assembly as com object from ASP Ian Ohlander Classic ASP Components 0 April 15th, 2004 11:54 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.