|
|
 |
RE: FN-FORUM: Create an instance of a .NET component
date posted 9th January 2006 09:13
Hi,
Create and instance of a .NET assembly at runtime. Got it sorted now -
for anybody that's interested;
Public Function LoadClassByName(ByVal lstrAssemblyName As String,
ByVal lstrClassName As String, ByVal lobjArguments() As Object, ByRef
lstrMsg As String, ByRef lobjTemp As Object) As Boolean
Dim lobjAssembly As Reflection.Assembly
Dim lobjParams() As Object
If Dir(lstrAssemblyName).Equals("") Then
lstrMsg =3D "Assembly could not be found [" & =
lstrAssemblyName
& "]"
lobjTemp =3D Nothing
Return False
End If
'Load assembly
Try
lobjAssembly =3D lobjAssembly.LoadFrom(lstrAssemblyName)
Catch When Err.Number 0
lstrMsg =3D Err.Description
Return False
End Try
'Create instance of object
Try
lobjTemp =3D lobjAssembly.CreateInstance(lstrClassName, =
False,
Reflection.BindingFlags.CreateInstance, Nothing, lobjArguments, Nothing,
Nothing)
Catch When Err.Number 0
lstrMsg =3D Err.Description
Return False
End Try
If lobjTemp Is Nothing Then
lstrMsg =3D "Instance of [" & lstrClassName & "] could not =
be
created"
lobjTemp =3D Nothing
Return False
End If
Return True
End Function
Cheers
Andy
=20
-----Original Message-----
From: [EMAIL REMOVED] [EMAIL REMOVED] On Behalf Of Ben
Moxon
Sent: Monday, January 09, 2006 9:36 AM
To: Andy Macnaughton-Jones
Subject: Re: FN-FORUM: Create an instance of a .NET component
Andy Macnaughton-Jones wrote:
>In VB.NET, it seems to be a bit long winded and I don't seem able to=20
>create a project that lets me create a COM dll - I need to be able to=20
>late bind to an object to reference it at run time rather than design=20
>time.
>
hen you say "create a com dll" do you mean that you want to build a COM
dll in VB.Net or you want to instanciate one from VB.Net?
-ben
--
Freelancers, contractors earn more with Prosperity4 Call 0870 870 4414
or visit www.prosperity4.com and benefit from Inland Revenue approved
expenses today.
To advertise here: http://www.freelancers.net/advertising.html
|
 |
|