473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieving a handle to a private delegate

Hi!

I have some problems when testing a system.

In class A i have:

Public Event CommEvent As CommEventHandler
Public Delegate Sub CommEventHandler()

and a method:

EnableEvents(ByVal Callback As CommEventHandler)

Then in class B i have

Private Sub OnCommEventReceived() Handles A.CommEvent
From my test class (class C) I need to call EnableEvents with

OnCommEventReceived as an argument. The problem is I do not know how to
provide a handle to OnCommEventReceived. Since OnCommEventReceived is
private I guess I need to use reflection, but I cannot make it work.

I have used for instance MethodInfo to invoke private methods before,
but now I just need some kind of handle to the OnCommEventReceived
method in class B to provide to the EnableEvents method in class A.

Thank you!

/Fredrik Strandberg

Feb 27 '06 #1
3 1647
The "addressof" operator must be used somehow or am I on the wrong
track?

Feb 27 '06 #2

Fredrik Strandberg wrote:
Hi!

I have some problems when testing a system.

In class A i have:

Public Event CommEvent As CommEventHandler
Public Delegate Sub CommEventHandler()

and a method:

EnableEvents(ByVal Callback As CommEventHandler)

Then in class B i have

Private Sub OnCommEventReceived() Handles A.CommEvent
From my test class (class C) I need to call EnableEvents with

OnCommEventReceived as an argument. The problem is I do not know how to
provide a handle to OnCommEventReceived. Since OnCommEventReceived is
private I guess I need to use reflection, but I cannot make it work.

I have used for instance MethodInfo to invoke private methods before,
but now I just need some kind of handle to the OnCommEventReceived
method in class B to provide to the EnableEvents method in class A.


Since you know how to call B.OnCommEventReceived, how about providing
*in class C* a proxy method that has the same signature, and just calls
B.OnCommEventReceived (via reflection). Then just give C.Proxy to
A.EnableEvents.

--
Larry Lard
Replies to group please

Feb 28 '06 #3
Brilliant!

Thank you very much for valuable help!

/Fredrik

Feb 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rajiv Das | last post by:
Environment: Visual Studio 2005, Beta 2 ..Net 2.0 Windows XP, SP2 C# Generics ------------------------------- Hi, I have a Windows Form whose contents I would like to dynamically change. I
1
by: Jeffrey B. Holtz | last post by:
I'm trying to get the Name of the USB device pluged in from the RegisterDeviceNotification that I've used P/Invoke to marshal. I have seen a similar posting on the VisualBasic newgroups but I do...
2
by: Tom | last post by:
Hi newsgroup, I have read a lot af articles about marshalling in C#, but none of them could help me to solve the following problem: There is a C-DLL with the following header-file: ++++++++...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
3
by: Justin | last post by:
I have created a dataset with two tables and an insert command, I need to be able to retreive the Key Identity after inserting into table "A" for use in table "B". Should I use ExecuteScalar()...
2
by: Samuel R. Neff | last post by:
I'm trying to find a good way to handle Control.InvokeRequired without duplicating four lines of code in every function/event. Typically what I've seen in books is this: If InvokeRequired Then...
8
by: Chad | last post by:
To anyone who is smarter than I am when it comes to WMI: Here is what I am trying to do: 1) Detect a USB pen drive when it is inserted 2) Retrieve the drive letter of the pen drive 3) Check...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
10
by: menashay | last post by:
Hello, I am absolute beginner in C# so pardon me if the following question is too easy. I have a form with a one button. When I click the button I want to display a message that reads...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.