PC Review


Reply
Thread Tools Rate Thread

Delegate constructor compiles in VB.NET, but not in Excel VBA

 
 
microsoftCraze
Guest
Posts: n/a
 
      4th Jun 2010


I have created a DLL callback through a delegate function.
It works fine when the client is C#, or VB.NET.
I can't get it to compile in Excel VBA. I have this problem both in Excel
2003 and Excel 2007.
The DLL references setting is ok, because when I take the reference out the
compiler errors out on RemoteProcess.
What am I missing?

The snippets below are the dll code, the working vb.net client code, and the
failing vba code.

===========================================
The remoteprocess class is compiled as dll:
===========================================
Public Class RemoteProcess
Public Delegate Sub RemoteProcessResultMessage(ByVal sMsg As String)
Public Sub runIt(ByVal callback As RemoteProcessResultMessage)
callback("Hello World!")
End Sub
End Class


===========================================
The VB Client code, which works well:
===========================================
Imports RemoteProcess
Imports System.Runtime.InteropServices

Public Class Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
Dim rpResponse As
RemoteProcess.RemoteProcess.RemoteProcessResultMessage
rpResponse = New
RemoteProcess.RemoteProcess.RemoteProcessResultMessage(AddressOf
ServerResponse)
Dim rp As RemoteProcess.RemoteProcess
rp = New RemoteProcess.RemoteProcess
rp.runIt(rpResponse)
End Sub
Private Sub ServerResponse(ByVal sMessage As String)
MsgBox("Received response: " & sMessage)
End Sub
End Class



======================================================================================
The Excel VBA Client code, which does not compile.
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Expected: end of statement
---------------------------
OK Help
---------------------------
The highlight is on the open parenthesis in the constructor.
It looks like the AddressOf parameter is not expected, but we know it's needed
======================================================================================
Public Sub RunRemote()
Dim rpResponse As RemoteProcess.RemoteProcess.RemoteProcessResultMessage
set rpResponse = New
RemoteProcess.RemoteProcess.RemoteProcessResultMessage(AddressOf
ServerResponse)

Dim rp As RemoteProcess
rp = New RemoteProcess.RemoteProcess
rp.RunIt (rpResponse)
End Sub

Private Sub ServerResponse(ByVal sMessage As String)
MsgBox ("Received response: " & sMessage)
End Sub




 
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
Referencing Class Constructor with Delegate Jessie Microsoft C# .NET 10 30th Jan 2008 02:16 AM
need help convert c# to VB (passing delegate into Thread constructor) Sergey Poberezovskiy Microsoft VB .NET 6 27th Aug 2007 08:51 PM
Could a delegate point to a constructor? =?Utf-8?B?VGhlUGlua1BhbnRoZXI=?= Microsoft Dot NET 2 9th Feb 2006 05:03 PM
Delegate constructor types Edward Diener Microsoft VC .NET 5 4th Jan 2004 02:49 PM
Delegate constructor types Edward Diener Microsoft Dot NET 2 3rd Jan 2004 12:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:05 AM.