PC Review


Reply
Thread Tools Rate Thread

write delegate & callback in dll

 
 
James Wong
Guest
Posts: n/a
 
      24th Jul 2006
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


 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      24th Jul 2006
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.)

 
Reply With Quote
 
James Wong
Guest
Posts: n/a
 
      24th Jul 2006
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" <(E-Mail Removed)> 撰寫於郵件新聞:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
guy
Guest
Posts: n/a
 
      24th Jul 2006

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.

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      25th Jul 2006
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.)

 
Reply With Quote
 
James Wong
Guest
Posts: n/a
 
      28th Jul 2006
thanks~


"Kevin Yu [MSFT]" <v-(E-Mail Removed)> 撰寫於郵件新聞:(E-Mail Removed)...
> 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.)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with delegate callback error Flomo Togba Kwele Microsoft VB .NET 9 7th May 2007 05:37 AM
delegate for unmanaged callback =?Utf-8?B?dGIyMDAw?= Microsoft Dot NET Compact Framework 5 10th Feb 2006 07:10 AM
Delegate Callback with parameter Budi Microsoft C# .NET 0 13th Jul 2004 12:25 AM
callback Proc: need delegate obj. Pls help suria` Microsoft VB .NET 2 24th Nov 2003 10:02 AM
Delegate and callback problem Coder Microsoft Dot NET Framework 5 9th Sep 2003 08:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.