From: microsoftCraze on


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




 | 
Pages: 1
Prev: User form Default value in text box
Next: SelfCert