By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,728 Members | 2,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,728 IT Pros & Developers. It's quick & easy.

ActiveX DLL Late Bind

P: n/a
Greetings,

I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can
you give me an example or URL of this? I've been trying to google it, just
cant find a straight answer. Thanks!


Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Chris,

Have you tried using Activator.CreateInstance()
using the type of the AxImp.exe generated Activex wrapper class ?.

Control ctrl = (Control)Activator.CreateInstance(
Type.GetType("....typeNameOfAxInteropWrapper...")) ;

// Add it to the form's control collection using the Controls property
Controls.Add(ctrl);
ctrl.Show();

Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:3M********************@comcast.com...
Greetings,

I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can
you give me an example or URL of this? I've been trying to google it, just
cant find a straight answer. Thanks!

Nov 15 '05 #2

P: n/a
I have been using:

Type typeofobj = Type.GetTypeFromProgID( "AESRegLib.AESRegistryObject" );

object newobj = Activator.CreateInstance( typeofobj );

MemberInfo[] Mymemberinfoarray = typeofobj.GetMembers();

//Get and display the DeclaringType method.
Console.Write( "\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0) );
Console.Write( "{0}.", typeofobj.FullName );
foreach ( MemberInfo Mymemberinfo in Mymemberinfoarray )
{
Console.Write( "\n" + Mymemberinfo.Name + " declaring type - " +
Mymemberinfo.DeclaringType );
}

But I get this in console:

There are 7 members in System.__ComObject.
CreateObjRef declaring type - System.MarshalByRefObject
InitializeLifetimeService declaring type - System.MarshalByRefObject
GetLifetimeService declaring type - System.MarshalByRefObject
GetHashCode declaring type - System.Object
Equals declaring type - System.Object
ToString declaring type - System.Object\

It doesnt seem to get the right info, not sure what I'm doing wrong.

Any ideas?

Thanks!

"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi Chris,

Have you tried using Activator.CreateInstance()
using the type of the AxImp.exe generated Activex wrapper class ?.

Control ctrl = (Control)Activator.CreateInstance(
Type.GetType("....typeNameOfAxInteropWrapper...")) ;

// Add it to the form's control collection using the Controls property
Controls.Add(ctrl);
ctrl.Show();

Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:3M********************@comcast.com...
Greetings,

I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can you give me an example or URL of this? I've been trying to google it, just cant find a straight answer. Thanks!


Nov 15 '05 #3

P: n/a
HI Chris,

Probably, I misunderstood your original question. I was assuming that
it was an ActiveX control that you were trying to host on a Windows Form.
Typically, the RCW metadata wrapper is exposed as a __ComObject
in managed code when importing a COM object.
Since the COM object is written in VB6, it would be IDispatch based.

Can you try calling one of the methods exposed by the object
using InvokeMember()
In your example, try something like to see if it invokes the methods
correctly:

object[] inputParams= { "My string input param" };

typeofobj.InvokeMember("MyMethodName",
BindingFlags.Default | BindingFlags.InvokeMethod,
null, newobj, inputParams);
Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:Z4********************@comcast.com...
I have been using:

Type typeofobj = Type.GetTypeFromProgID( "AESRegLib.AESRegistryObject" );

object newobj = Activator.CreateInstance( typeofobj );

MemberInfo[] Mymemberinfoarray = typeofobj.GetMembers();

//Get and display the DeclaringType method.
Console.Write( "\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0) );
Console.Write( "{0}.", typeofobj.FullName );
foreach ( MemberInfo Mymemberinfo in Mymemberinfoarray )
{
Console.Write( "\n" + Mymemberinfo.Name + " declaring type - " +
Mymemberinfo.DeclaringType );
}

But I get this in console:

There are 7 members in System.__ComObject.
CreateObjRef declaring type - System.MarshalByRefObject
InitializeLifetimeService declaring type - System.MarshalByRefObject
GetLifetimeService declaring type - System.MarshalByRefObject
GetHashCode declaring type - System.Object
Equals declaring type - System.Object
ToString declaring type - System.Object\

It doesnt seem to get the right info, not sure what I'm doing wrong.

Any ideas?

Thanks!

"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi Chris,

Have you tried using Activator.CreateInstance()
using the type of the AxImp.exe generated Activex wrapper class ?.

Control ctrl = (Control)Activator.CreateInstance(
Type.GetType("....typeNameOfAxInteropWrapper...")) ;

// Add it to the form's control collection using the Controls property
Controls.Add(ctrl);
ctrl.Show();

Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:3M********************@comcast.com...
Greetings,

I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can you give me an example or URL of this? I've been trying to google it, just cant find a straight answer. Thanks!



Nov 15 '05 #4

P: n/a

It gives:

An unhandled exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.

When I add:

string Test = (string)typeofobj.InvokeMember("about",
BindingFlags.Default | BindingFlags.InvokeMethod,
null, newobj, null);
In Delpi to do what I'm wanting in C# is usually something like:

procedure TfrmMain.FormCreate(Sender: TObject);
var
AESreg:Variant; // ActiveX Object
begin

try
AESreg := CreateOleObject('AESRegLib.AESRegistryObject');
except
ShowMessage('Error cannot create object AESRegistryObject ');
Exit;
end;

ShowMessage(AESreg.About);
AESreg := unassigned;
end;
Thank for helping me Aravind, appreciate it a lot.
"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
HI Chris,

Probably, I misunderstood your original question. I was assuming that
it was an ActiveX control that you were trying to host on a Windows Form.
Typically, the RCW metadata wrapper is exposed as a __ComObject
in managed code when importing a COM object.
Since the COM object is written in VB6, it would be IDispatch based.

Can you try calling one of the methods exposed by the object
using InvokeMember()
In your example, try something like to see if it invokes the methods
correctly:

object[] inputParams= { "My string input param" };

typeofobj.InvokeMember("MyMethodName",
BindingFlags.Default | BindingFlags.InvokeMethod,
null, newobj, inputParams);
Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:Z4********************@comcast.com...
I have been using:

Type typeofobj = Type.GetTypeFromProgID( "AESRegLib.AESRegistryObject" );
object newobj = Activator.CreateInstance( typeofobj );

MemberInfo[] Mymemberinfoarray = typeofobj.GetMembers();

//Get and display the DeclaringType method.
Console.Write( "\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0) );
Console.Write( "{0}.", typeofobj.FullName );
foreach ( MemberInfo Mymemberinfo in Mymemberinfoarray )
{
Console.Write( "\n" + Mymemberinfo.Name + " declaring type - " +
Mymemberinfo.DeclaringType );
}

But I get this in console:

There are 7 members in System.__ComObject.
CreateObjRef declaring type - System.MarshalByRefObject
InitializeLifetimeService declaring type - System.MarshalByRefObject
GetLifetimeService declaring type - System.MarshalByRefObject
GetHashCode declaring type - System.Object
Equals declaring type - System.Object
ToString declaring type - System.Object\

It doesnt seem to get the right info, not sure what I'm doing wrong.

Any ideas?

Thanks!

"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi Chris,

Have you tried using Activator.CreateInstance()
using the type of the AxImp.exe generated Activex wrapper class ?.

Control ctrl = (Control)Activator.CreateInstance(
Type.GetType("....typeNameOfAxInteropWrapper...")) ;

// Add it to the form's control collection using the Controls property
Controls.Add(ctrl);
ctrl.Show();

Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:3M********************@comcast.com...
> Greetings,
>
> I'm trying to late bind a ActiveX DLL that was made with VB6 in
C#. Can
> you give me an example or URL of this? I've been trying to google
it, just
> cant find a straight answer. Thanks!
>
>
>
>



Nov 15 '05 #5

P: n/a
Instead of using .InvokeMethod, I did .getmethod, and it worked!

"Chris" <jt******@comcast.net> wrote in message
news:Kd********************@comcast.com...

It gives:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.

When I add:

string Test = (string)typeofobj.InvokeMember("about",
BindingFlags.Default | BindingFlags.InvokeMethod,
null, newobj, null);
In Delpi to do what I'm wanting in C# is usually something like:

procedure TfrmMain.FormCreate(Sender: TObject);
var
AESreg:Variant; // ActiveX Object
begin

try
AESreg := CreateOleObject('AESRegLib.AESRegistryObject');
except
ShowMessage('Error cannot create object AESRegistryObject ');
Exit;
end;

ShowMessage(AESreg.About);
AESreg := unassigned;
end;
Thank for helping me Aravind, appreciate it a lot.
"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
HI Chris,

Probably, I misunderstood your original question. I was assuming that
it was an ActiveX control that you were trying to host on a Windows Form.
Typically, the RCW metadata wrapper is exposed as a __ComObject
in managed code when importing a COM object.
Since the COM object is written in VB6, it would be IDispatch based.

Can you try calling one of the methods exposed by the object
using InvokeMember()
In your example, try something like to see if it invokes the methods
correctly:

object[] inputParams= { "My string input param" };

typeofobj.InvokeMember("MyMethodName",
BindingFlags.Default | BindingFlags.InvokeMethod,
null, newobj, inputParams);
Regards,
Aravind C
"Chris" <jt******@comcast.net> wrote in message
news:Z4********************@comcast.com...
I have been using:

Type typeofobj = Type.GetTypeFromProgID(

"AESRegLib.AESRegistryObject" );
object newobj = Activator.CreateInstance( typeofobj );

MemberInfo[] Mymemberinfoarray = typeofobj.GetMembers();

//Get and display the DeclaringType method.
Console.Write( "\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0) );
Console.Write( "{0}.", typeofobj.FullName );
foreach ( MemberInfo Mymemberinfo in Mymemberinfoarray )
{
Console.Write( "\n" + Mymemberinfo.Name + " declaring type - " +
Mymemberinfo.DeclaringType );
}

But I get this in console:

There are 7 members in System.__ComObject.
CreateObjRef declaring type - System.MarshalByRefObject
InitializeLifetimeService declaring type - System.MarshalByRefObject
GetLifetimeService declaring type - System.MarshalByRefObject
GetHashCode declaring type - System.Object
Equals declaring type - System.Object
ToString declaring type - System.Object\

It doesnt seem to get the right info, not sure what I'm doing wrong.

Any ideas?

Thanks!

"Aravind C" <ar***********@nospam.hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
> Hi Chris,
>
> Have you tried using Activator.CreateInstance()
> using the type of the AxImp.exe generated Activex wrapper class ?.
>
> Control ctrl = (Control)Activator.CreateInstance(
> Type.GetType("....typeNameOfAxInteropWrapper...")) ;
>
> // Add it to the form's control collection using the Controls property > Controls.Add(ctrl);
> ctrl.Show();
>
> Regards,
> Aravind C
>
>
> "Chris" <jt******@comcast.net> wrote in message
> news:3M********************@comcast.com...
> > Greetings,
> >
> > I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can
> > you give me an example or URL of this? I've been trying to google it, just
> > cant find a straight answer. Thanks!
> >
> >
> >
> >
>
>



Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.