When you add an event handler to some object you need to specify the function to call when the event occurs. Suppose there is a
class TesterClosed() which is called whenever the Tester is closed. Code below:
public void TesterClosed(){ }
Tester m_tester = new Tester();
m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Now suppose I want to do this with late binding where I need to work with objects. The parameter TesterClosed in
Tester.CloseEve ntHandler(....) is of type "void () type". How do I convert this into an object that I can pass to the same function
with late binding? Code below which I'm not sure I'm doing right:
//m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Type objClassType = Type.GetTypeFro mProgID("Tester .CloseEventHand ler");
object [] objParameters_L ate = new object[1];
objParameters_L ate[0] = TesterClosed; /*I get an error here*/
object objTesterEvent_ Late = Activator.Creat eInstance(objCl assType, objParameters_L ate);
objParameters_L ate = new object[1];
objParameters_L ate[0] = objTesterEvent_ Late;
m_tester_Late.G etType().Invoke Member("Close", BindingFlags.In vokeMethod, null, m_tester_Late, objParameters_L ate); 2 3401
> objParameters_L ate[0] = TesterClosed; /*I get an error here*/
ofcourse its the name of the function, you cant assign the name of the
function to an object. try doing
objParameters_L ate[0] = new Tester.CloseEve ntHandler(Teste rClosed);
Ab. http://joehacker.blogspot.com
"Max" <ma******@yahoo .com> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl... When you add an event handler to some object you need to specify the
function to call when the event occurs. Suppose there is a class TesterClosed() which is called whenever the Tester is closed. Code
below: public void TesterClosed(){ }
Tester m_tester = new Tester(); m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Now suppose I want to do this with late binding where I need to work with
objects. The parameter TesterClosed in Tester.CloseEve ntHandler(....) is of type "void () type". How do I convert
this into an object that I can pass to the same function with late binding? Code below which I'm not sure I'm doing right:
//m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Type objClassType = Type.GetTypeFro mProgID("Tester .CloseEventHand ler"); object [] objParameters_L ate = new object[1]; objParameters_L ate[0] = TesterClosed; /*I get an error here*/ object objTesterEvent_ Late = Activator.Creat eInstance(objCl assType,
objParameters_L ate); objParameters_L ate = new object[1]; objParameters_L ate[0] = objTesterEvent_ Late; m_tester_Late.G etType().Invoke Member("Close", BindingFlags.In vokeMethod,
null, m_tester_Late, objParameters_L ate);
Abubakar, I think you miss read my question. You see, I can certainly do that when I know that Tester exists and this will be true
if the library corresponding to Tester is imported. Now suppose there are different versions of the Tester library and you want your
code to work with all of them. A better example is if you can think of Tester as Microsoft Outlook or Microsoft Word which I'm
using, where the Tester library would be Microsoft Outlook 11.0 Object Library or Microsoft Office 11.0 Object Library.
To automate multiple versions of Microsoft Office one cannot just import the latest library, ie Microsoft Office 11.0 Object Library
unless you wanted your code to work with Office 2002/2003. However I would like my code to be compatible with Office 2000 as well
which means I cannot import a particular library but would have to rely on the COM-based in process server from the application at
run time. This means I have to write my code using late binding. Late binding means I need to work with objects where Tester would
not be one of them since I won't be importing any Tester libraries, hence my messy code above.
"Abubakar" <ab*******@gmai l.com> wrote in message news:%2******** **********@TK2M SFTNGP14.phx.gb l... objParameters_L ate[0] = TesterClosed; /*I get an error here*/
ofcourse its the name of the function, you cant assign the name of the function to an object. try doing objParameters_L ate[0] = new Tester.CloseEve ntHandler(Teste rClosed);
Ab. http://joehacker.blogspot.com
"Max" <ma******@yahoo .com> wrote in message news:O3******** ******@TK2MSFTN GP10.phx.gbl... When you add an event handler to some object you need to specify the function to call when the event occurs. Suppose there is a class TesterClosed() which is called whenever the Tester is closed. Code below: public void TesterClosed(){ }
Tester m_tester = new Tester(); m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Now suppose I want to do this with late binding where I need to work with
objects. The parameter TesterClosed in Tester.CloseEve ntHandler(....) is of type "void () type". How do I convert this into an object that I can pass to the same function with late binding? Code below which I'm not sure I'm doing right:
//m_tester.Close += new Tester.CloseEve ntHandler(Teste rClosed);
Type objClassType = Type.GetTypeFro mProgID("Tester .CloseEventHand ler"); object [] objParameters_L ate = new object[1]; objParameters_L ate[0] = TesterClosed; /*I get an error here*/ object objTesterEvent_ Late = Activator.Creat eInstance(objCl assType, objParameters_L ate); objParameters_L ate = new object[1]; objParameters_L ate[0] = objTesterEvent_ Late; m_tester_Late.G etType().Invoke Member("Close", BindingFlags.In vokeMethod,
null, m_tester_Late, objParameters_L ate);
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: verec |
last post by:
I just do not understand this error.
Am I misusing dynamic_cast ?
What I want to do is to have a single template construct
(with no optional argument) so that it works for whatever
T I want to use it with. Now, if that T happens to be some
subclass of a known base class (object, in this case), I
want to perform some extra stuff ...
I've...
|
by: bob_jenkins |
last post by:
{
const void *p;
(void)memset((void *)p, ' ', (size_t)10);
}
Should this call to memset() be legal? Memset is of type
void *memset(void *, unsigned char, size_t)
Also, (void *) is the generic pointer type.
My real question is, is (void *) such a generic pointer type that it
|
by: infobahn |
last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
|
by: kernel.lover |
last post by:
hello,
I want to know if a fuction say malloc is declared as void *malloc()
then whats the significance of void here.
Does void * is used when function has the flexibility to return any
type of value by casting that functions with appropriate data type?
|
by: LordHog |
last post by:
Hello all,
I am having a little problem getting my (void *) assignment to work
correctly. Basically it is some code for a circular queue buffer I am
trying to implement, but getting the deferrencing of the (void *) type
is giving me problems... For brevity sake not all the functions are
defined, but the name gives a clue to what it does...
| |
by: maadhuu |
last post by:
hello, this is a piece of code ,which is giving an error.
#include<stdio.h>
int main()
{
int a =10;
void *p = &a;
printf("%d ", *p ); //error....why should it //be an error ?can't the
compiler make out because //of %d that the pointer is supposed to refer to
an integer ?? or is explicit type casting required ??
|
by: aegis |
last post by:
Given the following:
int a = 10;
int *p;
void *p1;
unsigned char *p2;
p = &a;
|
by: Niu Xiao |
last post by:
I saw a lot of codes like:
void foo(void* arg)
void bar(void** arg)
f((void*)p)
but what does void pointer mean in c? I just know it stands for generic
pointer.
thanks.
|
by: elmar |
last post by:
Hi Clers,
If I look at my ~200000 lines of C code programmed over the past 15
years, there is one annoying thing in this smart language, which
somehow reduces the 'beauty' of the source code ;-):
char *cp;
void *vp;
void **vpp;
|
by: PeterAPIIT |
last post by:
Hello all C++ expert programmer,
i have wrote partial general allocator for my container.
After reading standard C++ library and code guru article, i have
several questions.
1. Why allocator write forward declaration then allocation for void*
rather than directly wrote allocator first ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |