COM createobject query

  • Thread starter Thread starter Jethro
  • Start date Start date
J

Jethro

Hi all

upgrade a VB6 Project, and am now stumped.

The project contained 4 class modules. These were upgraded from :

Public Class HTMLMail

to :

<System.Runtime.InteropServices.ProgId("HTMLMail_NET.HTMLMail")> Public
Class HTMLMail

My code gets a string from the registry (I had to rewrite my registry
handlers to dump the API), and attempts this :

sClass = GetString()
objClass=CreateObject(sClass)
objClass.MyMethod() <--------------------

This line fails with a System.IO.Runtime.Exception "Path not found".

If I replace the CreateObject with Dim objClass as new HTMLMail then all is
well.

Obviously I have missed a subtlety here of the upgrade ...

I want to keep this way of working, as it allows me to introduce new
features (i.e. paid for) by simply putting additional DLLs on the client
machine - No DLL, no feature ! Additionally I can maintain features
independently ...

Thanks in advance

Jethro
 
I want to keep this way of working, as it allows me to introduce new
features (i.e. paid for) by simply putting additional DLLs on the client
machine - No DLL, no feature ! Additionally I can maintain features
independently ...

AFAIR, Late binding is not supported in VB.Net. The best way to handle
your situation is to have each .dll implement an interface (for example
IFeature).

Then, when your main program loads, it can scan the 'feature folder" for
the .dll's that implement the interface.

It works well and you get the benefit of compile time checking of the code.

HTH
 
Hi all
upgrade a VB6 Project, and am now stumped.

The project contained 4 class modules. These were upgraded from :

Public Class HTMLMail

to :

<System.Runtime.InteropServices.ProgId("HTMLMail_NET.HTMLMail")> Public
Class HTMLMail

My code gets a string from the registry (I had to rewrite my registry
handlers to dump the API), and attempts this :

sClass = GetString()
objClass=CreateObject(sClass)
objClass.MyMethod() <--------------------

This line fails with a System.IO.Runtime.Exception "Path not found".

If I replace the CreateObject with Dim objClass as new HTMLMail then all is
well.

Obviously I have missed a subtlety here of the upgrade ...

I want to keep this way of working, as it allows me to introduce new
features (i.e. paid for) by simply putting additional DLLs on the client
machine - No DLL, no feature ! Additionally I can maintain features
independently ...

In answer to the previous answer ...

ADODB recordsets are being created OK using "CreateObject" ....
 
I think CreateObject is only to be used with objects that are com objects
(your class is now a .net class) - try this instead:
System.Reflection.Assembly.GetCallingAssembly.CreateInstance(sClass) - note
that sClass will have to have the full path of the class's type - see this
example:
Module Module1

Class c1

End Class

Sub Main()

MsgBox(System.Reflection.Assembly.GetExecutingAssembly.CreateInstance("Conso
leapplication6.module1+c1", True) Is Nothing)
End Sub

End Module

My test app had a root namespace Consoleapplication6, and the class c1 was
nested inside a module - hence namespace.nestingtype+classname
the true argument makes it case insensitive.

Hope that helps,
Alex

--------------------
 
Alexandre Moura said:
I think CreateObject is only to be used with objects that are com objects
(your class is now a .net class) - try this instead:
System.Reflection.Assembly.GetCallingAssembly.CreateInstance(sClass) - note
that sClass will have to have the full path of the class's type - see this
example:
Module Module1

Class c1

End Class

Sub Main()

MsgBox(System.Reflection.Assembly.GetExecutingAssembly.CreateInstance("Conso
leapplication6.module1+c1", True) Is Nothing)
End Sub

End Module

My test app had a root namespace Consoleapplication6, and the class c1 was
nested inside a module - hence namespace.nestingtype+classname
the true argument makes it case insensitive.

Hope that helps,
Alex
This is starting to make sense ... I have tried this, but I suspect I
haven't got the module name correct .... There is no module declaration in
the file, just the :

<System.Runtime.InteropServices.ProgId("HTMLMail_NET.HTMLMail")> Public
Class HTMLMail

declaration ...

This file is part of my main project ("assembly now"), which is called
"Webupload". In VB6, I just instansiated "Webupload.HTMLMail", which was
compiled into my ActiveX exe.

The reason I did this is so that I could release a "core" functionality to
all clients, and those that paid extra could recieve DLLs which would
contain additional classes that enhanced functionality, however the core
module contains code which is identical for
all classes (file handling etc).

If the whole thing had been written in VB.NET I would have created a base
class, and then inherited from it, so that each derived class could use
functions created in the base class ... even better I would have used VC++
.... however I "inherited" the project, and a complete rewrite is not a
priority .....

thanks for the help
 
Back
Top