473,394 Members | 1,951 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,394 software developers and data experts.

write delegate & callback in dll

hi,

I want to write some delegate function to the DLL.
How can I output the value to my main program? (Do not output the value to
the UI)
Any good idea for this program?

Thanks~
For example,

Public Class clsCallBackAdd
Delegate Function _AddDelegate(ByVal intInteger As Integer) As Integer

Private Function _Add(ByVal intInteger As Integer) As Integer
intInteger += 1
Return intInteger
End Function

Public Sub gSetDelegate(ByVal intInteger As Integer)
Dim deleg As _AddDelegate
Dim cb As New AsyncCallback(AddressOf gCallBack)

deleg = AddressOf _Add
deleg.BeginInvoke(intInteger, cb, deleg)
End Sub

Public Sub gCallBack(ByVal ar As IAsyncResult)
......
End Sub
End Class
Jul 24 '06 #1
5 1424
Sorry, James. I didn't quite catch your meaning. What do you mean by output
the value to your main program? Do you mean the return value in the _Add
function? Could you explain a little more detail? Thank you!

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 24 '06 #2
I have a windows form (eg. Public Class Form1) will call this DLL,
this form will pass some parameter to the DLL,
When the DLL is processing, my Form1 will do another process.
After the DLL finished the process, how can I get the result value?
"James Wong" <cp*******@nospam.nospam¼¶¼g©ó¶l¥ó·s»D:%2********* *******@TK2MSFTNGP04.phx.gbl...
hi,

I want to write some delegate function to the DLL.
How can I output the value to my main program? (Do not output the value to
the UI)
Any good idea for this program?

Thanks~
For example,

Public Class clsCallBackAdd
Delegate Function _AddDelegate(ByVal intInteger As Integer) As Integer

Private Function _Add(ByVal intInteger As Integer) As Integer
intInteger += 1
Return intInteger
End Function

Public Sub gSetDelegate(ByVal intInteger As Integer)
Dim deleg As _AddDelegate
Dim cb As New AsyncCallback(AddressOf gCallBack)

deleg = AddressOf _Add
deleg.BeginInvoke(intInteger, cb, deleg)
End Sub

Public Sub gCallBack(ByVal ar As IAsyncResult)
......
End Sub
End Class


Jul 24 '06 #3
guy

James Wong wrote:
I have a windows form (eg. Public Class Form1) will call this DLL,
this form will pass some parameter to the DLL,
When the DLL is processing, my Form1 will do another process.
After the DLL finished the process, how can I get the result value?
You rise event in dll and catch it on main form.

Jul 24 '06 #4
Hi James,

So you mean you need to return the value from _Add function that is
calculated on another thread to the main thread. Am I right?

To return the value, the simplest way is to set the value to a certain
variable in the _Add function instead of returning a value. And in the
callback, make the main thread read from that variable. By the way, when
setting the variable value, we have to use SyncLock statement to lock the
object to make sure that no other thread is writing to it simultanously.

For more information about SyncLock, please check the following link:

http://msdn2.microsoft.com/en-us/library/3a86s51t.aspx

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 25 '06 #5
thanks~
"Kevin Yu [MSFT]" <v-****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:ZA******** ******@TK2MSFTNGXA01.phx.gbl...
Hi James,

So you mean you need to return the value from _Add function that is
calculated on another thread to the main thread. Am I right?

To return the value, the simplest way is to set the value to a certain
variable in the _Add function instead of returning a value. And in the
callback, make the main thread read from that variable. By the way, when
setting the variable value, we have to use SyncLock statement to lock the
object to make sure that no other thread is writing to it simultanously.

For more information about SyncLock, please check the following link:

http://msdn2.microsoft.com/en-us/library/3a86s51t.aspx

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 28 '06 #6

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

Similar topics

10
by: John Bowman | last post by:
Hello, I need some help getting a callback delegate passed as an argument to a dynamically linked Dll method so it in turn, can eventually call it. Below is the salient portions of code I'm...
3
by: N8 | last post by:
I am trying to get an exception to occur and consequently found that when adding a target method to a delegates invocation list, a copy of that object is added instead of a reference to the object....
3
by: Wen | last post by:
hello, now, i wanna port a c++ program into C# project. a DLL written by C++ and keep it no change, and UI wirtten by C#. my C++ UI code is as below: // error handlers --global function...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
6
by: Bart Burkhardt | last post by:
Hi, I could use some help in setting a C# callback function that an external unmanaged dll will call on a event. Using a delegate and use the external callback set function doesn't work. The...
3
by: ThinkRS232 | last post by:
I have a PocketPC .Net application (Compact Framework) that calls a Win32 DLL. This DLL in turn has a WINAPI type callback. Following is the actual prototype. Win32 DLL Function Prototype...
13
by: Wilfried Mestdagh | last post by:
Hi, I have an application using a DLL and callbacks. It generate random the error "A callback was made on a garbage collected delegate". I found some articles that the pointer to the delegate...
11
by: ohmmega | last post by:
hello world. i would like to implement a class with a timer, witch informs me every second about it's tick. the code works already, but i would like to change a thing (or more). <code> //at...
0
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...
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
0
BarryA
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...
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
marktang
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,...
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
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.