Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Delegate constructor compiles in VB.NET, but not in Excel VBA
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.RemoteProcessResultMes sage rpResponse = New RemoteProcess.RemoteProcess.RemoteProcessResultMes sage(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.RemoteProcessResultMes sage set rpResponse = New RemoteProcess.RemoteProcess.RemoteProcessResultMes sage(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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Adding Delegate in Outlook | Excel Programming | |||
Is VBA Class have Constructor like java ? | Excel Programming | |||
how do i set up a delegate list in excel | Excel Discussion (Misc queries) | |||
How do I set up an Excel worksheet that compiles data from other . | Excel Worksheet Functions | |||
Code compiles but Excel ERROR | Excel Programming |