I am writing an C# program. I call a method on a COM object that returns
Object. I don't know the type of the object (and reflection just says its a
__ComObject), but I know there is supposed to be Controls property. How can
I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just writing
SomeObject.Controls. The VB.NET runtime will handle the late binding which,
in this case, includes calling the COM object's IDispatch interface. I
don't see how to do the same thing in C#. The only "late binding" examples
I can find for C# assume you know the type of the object you are calling. 9 7649
You will need to Invoke the method. Check out Invoke in MSDN.
Thanks,
"Scott English" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its
a __ComObject), but I know there is supposed to be Controls property. How
can I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just writing SomeObject.Controls. The VB.NET runtime will handle the late binding
which, in this case, includes calling the COM object's IDispatch interface. I don't see how to do the same thing in C#. The only "late binding"
examples I can find for C# assume you know the type of the object you are calling.
Are you refering to MethodBase.Invoke? To get a MethodBase object, you must
first know the type of the object the method is on. Am I missing something?
"BuddyHome" <Bu***@onlinehome.com> wrote in message
news:Og*************@TK2MSFTNGP10.phx.gbl... You will need to Invoke the method. Check out Invoke in MSDN.
Thanks,
"Scott English" <no****@nospam.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I am writing an C# program. I call a method on a COM object that
returns Object. I don't know the type of the object (and reflection just says
its a __ComObject), but I know there is supposed to be Controls property. How can I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just
writing SomeObject.Controls. The VB.NET runtime will handle the late binding which, in this case, includes calling the COM object's IDispatch interface. I don't see how to do the same thing in C#. The only "late binding" examples I can find for C# assume you know the type of the object you are
calling.
Sorry Scott,
If are just trying to call a method late bound then see this article. http://groups.google.com/groups?hl=e...%3D10%26sa%3DN
"Scott English" <no****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Are you refering to MethodBase.Invoke? To get a MethodBase object, you
must first know the type of the object the method is on. Am I missing
something? "BuddyHome" <Bu***@onlinehome.com> wrote in message news:Og*************@TK2MSFTNGP10.phx.gbl... You will need to Invoke the method. Check out Invoke in MSDN.
Thanks,
"Scott English" <no****@nospam.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to be Controls property.
How can I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just writing SomeObject.Controls. The VB.NET runtime will handle the late binding
which, in this case, includes calling the COM object's IDispatch interface.
I don't see how to do the same thing in C#. The only "late binding" examples I can find for C# assume you know the type of the object you are calling.
This article is a lot better. http://my.execpc.com/~gopalan/dotnet/reflection.html
"BuddyHome" <Bu***@onlinehome.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl... Sorry Scott,
If are just trying to call a method late bound then see this article.
http://groups.google.com/groups?hl=e...%3D10%26sa%3DN "Scott English" <no****@nospam.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... Are you refering to MethodBase.Invoke? To get a MethodBase object, you must first know the type of the object the method is on. Am I missing something? "BuddyHome" <Bu***@onlinehome.com> wrote in message news:Og*************@TK2MSFTNGP10.phx.gbl... You will need to Invoke the method. Check out Invoke in MSDN.
Thanks,
"Scott English" <no****@nospam.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... > I am writing an C# program. I call a method on a COM object that returns > Object. I don't know the type of the object (and reflection just
says its a > __ComObject), but I know there is supposed to be Controls property. How can > I call the Controls property without knowing the type of the object? > > In VB.NET, you can just do this if Option Explicit is off by just writing > SomeObject.Controls. The VB.NET runtime will handle the late
binding which, > in this case, includes calling the COM object's IDispatch interface.
I > don't see how to do the same thing in C#. The only "late binding" examples > I can find for C# assume you know the type of the object you are calling. > >
Well, in that case, you still need to know the type of the object (the
ProgID). In my case, I don't know the type of object or its ProgID, only
that it is suppose to have a "Controls" attribute.
Again, this is no problem for VB.NET. Is C# really inferior to VB.NET in
this regard? Is there really something that VB.NET can do that C# can't?
"BuddyHome" <Bu***@onlinehome.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl... Sorry Scott,
If are just trying to call a method late bound then see this article.
http://groups.google.com/groups?hl=e...%3D10%26sa%3DN "Scott English" <no****@nospam.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl... Are you refering to MethodBase.Invoke? To get a MethodBase object, you must first know the type of the object the method is on. Am I missing something? "BuddyHome" <Bu***@onlinehome.com> wrote in message news:Og*************@TK2MSFTNGP10.phx.gbl... You will need to Invoke the method. Check out Invoke in MSDN.
Thanks,
"Scott English" <no****@nospam.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... > I am writing an C# program. I call a method on a COM object that returns > Object. I don't know the type of the object (and reflection just
says its a > __ComObject), but I know there is supposed to be Controls property. How can > I call the Controls property without knowing the type of the object? > > In VB.NET, you can just do this if Option Explicit is off by just writing > SomeObject.Controls. The VB.NET runtime will handle the late
binding which, > in this case, includes calling the COM object's IDispatch interface.
I > don't see how to do the same thing in C#. The only "late binding" examples > I can find for C# assume you know the type of the object you are calling. > >
well, did you try to make the late-bound call through type System.__ComObject? according to the documentation, you should still be able to make such a call through this generic type if your object implements the IDispatch interface
----- Scott English wrote: ----
I am writing an C# program. I call a method on a COM object that return
Object. I don't know the type of the object (and reflection just says its
__ComObject), but I know there is supposed to be Controls property. How ca
I call the Controls property without knowing the type of the object
In VB.NET, you can just do this if Option Explicit is off by just writin
SomeObject.Controls. The VB.NET runtime will handle the late binding which
in this case, includes calling the COM object's IDispatch interface.
don't see how to do the same thing in C#. The only "late binding" example
I can find for C# assume you know the type of the object you are calling
Do you mean declaring a variable as System.__ComObject? As in
__ComObject o = (__ComObject)someComObject.SomeMethod();
o.MakeLateBoundCallThroughIDispatch();
This doesn't compile. __ComObject isn't a public type. You can't declare a
variable of as __ComObject.
"Daniel Jin" <an*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com... well, did you try to make the late-bound call through type
System.__ComObject? according to the documentation, you should still be
able to make such a call through this generic type if your object implements
the IDispatch interface. ----- Scott English wrote: -----
I am writing an C# program. I call a method on a COM object that
returns Object. I don't know the type of the object (and reflection just
says its a __ComObject), but I know there is supposed to be Controls property.
How can I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just
writing SomeObject.Controls. The VB.NET runtime will handle the late binding
which, in this case, includes calling the COM object's IDispatch interface.
I don't see how to do the same thing in C#. The only "late binding"
examples I can find for C# assume you know the type of the object you are
calling.
Not sure what property you are expecting to get/set, but basically this is
what you have to do using Reflection (and what VB.NET does under the
covers).
object obj = <someCOMObject> // your __ComObject reference (Idispatch
interface)
// get property
object prop = obj.GetType().InvokeMember("", BindingFlags.GetProperty, null,
obj, null);
// cast obj to corresponding property type, fi. if a BSTR, cast object to a
string
string s = prop as string;
// set property
obj.GetType().InvokeMember("", BindingFlags.SetProperty, null, prop,
...... );
Willy.
"Scott English" <no****@nospam.com> wrote in message
news:OL**************@TK2MSFTNGP10.phx.gbl... Do you mean declaring a variable as System.__ComObject? As in
__ComObject o = (__ComObject)someComObject.SomeMethod(); o.MakeLateBoundCallThroughIDispatch();
This doesn't compile. __ComObject isn't a public type. You can't declare a variable of as __ComObject.
"Daniel Jin" <an*******@discussions.microsoft.com> wrote in message news:85**********************************@microsof t.com... well, did you try to make the late-bound call through type System.__ComObject? according to the documentation, you should still be able to make such a call through this generic type if your object implements the IDispatch interface. ----- Scott English wrote: -----
I am writing an C# program. I call a method on a COM object that
returns Object. I don't know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to be Controls property. How can I call the Controls property without knowing the type of the object?
In VB.NET, you can just do this if Option Explicit is off by just writing SomeObject.Controls. The VB.NET runtime will handle the late binding which, in this case, includes calling the COM object's IDispatch interface. I don't see how to do the same thing in C#. The only "late binding" examples I can find for C# assume you know the type of the object you are calling.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike MacSween |
last post by:
Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
*********************************************************...
|
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right...
|
by: Composer |
last post by:
I've read many postings about the problem of Access.References.IsBroken
and the consensus seems to be that late binding is the cure-all.
I have a very complex Access application that needs...
|
by: Zlatko Matić |
last post by:
I was reading about late binding, but I'm not completely sure what is to be
done in order to adjust code to late binding...
For example, I'm not sure if this is correct:
early binding:
Dim ws...
|
by: eBob.com |
last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been
wanting this capability for a long time. But it seems that I cannot
use it with Option Strict On. In an event handler I have ......
|
by: lgbjr |
last post by:
hi All,
I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:
dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
|
by: Tim Roberts |
last post by:
I've been doing COM a long time, but I've just come across a behavior
with late binding that surprises me. VB and VBS are not my normal
milieux, so I'm hoping someone can point me to a document...
|
by: GS |
last post by:
I have installed the ms PIA for ofc XP, and followed the article
http://support.microsoft.com/kb/247412/
trying to paste into a worksheet
However I got late binding not allowed errors
.......
|
by: ADezii |
last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
|
by: Siv |
last post by:
hi,
I am converting an application that writes to an Excel spreadsheet and the
code trips the "option Strict" that I would like on because the parser says
"option Strict On disallows late...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
| |