AddressOf Problem with vb6 to .NET 2005 Conversion

J

JOHNDOE

All right, I've been trying to wrap my head around this by reviewing
what is out on the web but still seem to be struggling with this....
Here is the calling code with the AddressOf Error:

Private Sub cmdInitialize_Click(ByVal eventSender As System.Object,
ByVal eventArgs As System.EventArgs) Handles cmdInitialize.Click

Dim oCtl As System.Windows.Forms.Control

Debug.Print("------------------- Begin DDE Test
-----------------------")

g_lInstID = 0

' Initialize the DDE subsystem. This only needs to be done once.
'UPGRADE_WARNING: Add a delegate for AddressOf DDECallback Click for
more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?
keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
'If DdeInitialize(g_lInstID, AddressOf DDECallback,
APPCMD_CLIENTONLY Or MF_SENDMSGS Or MF_POSTMSGS, 0) Then
If DdeInitialize(g_lInstID, AddressOf DDECallback,
APPCMD_CLIENTONLY Or MF_SENDMSGS Or MF_POSTMSGS, 0) Then

Debug.Print("DDE Initialize Failure.")
TranslateError()

Else

Debug.Print("DDE Initialize Success.")

End If

'Enable the command buttons.
For Each oCtl In Controls

'UPGRADE_WARNING: TypeOf has a new behavior. Click for
more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?
keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
If ((TypeOf oCtl Is System.Windows.Forms.TextBox) Or
(TypeOf oCtl Is System.Windows.Forms.ComboBox)) And (oCtl.Enabled =
False) Then
oCtl.Enabled = True
End If

Next oCtl

cmdInitialize.Enabled = False
cmdUninitialize.Enabled = True
cmdClear.Enabled = True
cboItem.SelectedIndex = 0

Here is the function that I am calling:
Public Function DDECallback(ByVal uType As Integer, ByVal uFmt As
Integer, ByVal hConv As Integer, ByVal hszString1 As Integer, ByVal
hszString2 As Integer, ByVal hData As Integer, ByVal dwData1 As
Integer, ByVal dwData2 As Integer) As Integer

Dim lSize As Integer
Dim sBuffer As String
Dim Ret As Integer

Debug.Print("In client callback. uType: " & uType)

Select Case uType

' This is th eevent you'll receive when a server sends you
a advisment.
Case XTYP_ADVDATA
Debug.Print("XTYP_ADVDATA")

lSize = DdeGetData(hData, vbNullString, 0, 0)

' If size is 0 then there's no data to grab.
If (lSize > 0) Then

' Allocate a buffer for the return data.
sBuffer = New String(Chr(0), lSize - MAGIC_NUMBER)

' Grab the data.
lSize = DdeGetData(hData, sBuffer, Len(sBuffer),
0)

' Print the contents of the buffer.
frmDDEApp.txtValue.Text = sBuffer
End If

Case XTYP_ADVSTART
Debug.Print("XTYP_ADVSTART")

Case XTYP_ADVSTOP
Debug.Print("XTYP_ADVSTOP")

Case XTYP_CONNECT
Debug.Print("XTYP_CONNECT")

Case XTYP_CONNECT_CONFIRM
Debug.Print("XTYP_CONNECT_CONFIRM")

Case XTYP_DISCONNECT
Debug.Print("XTYP_DISCONNECT")

Case XTYP_ERROR
Debug.Print("XTYP_ERROR")

Case XTYP_EXECUTE
Debug.Print("XTYP_EXECUTE")

Case XTYP_MASK
Debug.Print("XTYP_MASK")

Case XTYP_MONITOR
Debug.Print("XTYP_MONITOR")

Case XTYP_POKE
Debug.Print("XTYP_POKE")

Case XTYP_REGISTER
Debug.Print("XTYP_REGISTER")
g_hService2 = hszString2

lSize = DdeQueryString(g_lInstID, hszString2,
vbNullString, 0, CP_WINANSI)
sBuffer = Space(lSize)
DdeQueryString(g_lInstID, hszString2, sBuffer, lSize +
1, CP_WINANSI)

sBuffer = UCase(sBuffer)

Case XTYP_REQUEST
Debug.Print("XTYP_REQUEST")

Case XTYP_SHIFT
Debug.Print("XTYP_SHIFT")

Case XTYP_UNREGISTER
Debug.Print("XTYP_UNREGISTER")

Case XTYP_WILDCONNECT
Debug.Print("XTYP_WILDCONNECT")

Case XTYP_XACT_COMPLETE
Debug.Print("XTYP_XACT_COMPLETE")

End Select

DDECallback = 0

End Function

Thanks to everyone for their help!

-Kurt
 
T

Tom Shelton

All right, I've been trying to wrap my head around this by reviewing
what is out on the web but still seem to be struggling with this....
Here is the calling code with the AddressOf Error:

Private Sub cmdInitialize_Click(ByVal eventSender As System.Object,
ByVal eventArgs As System.EventArgs) Handles cmdInitialize.Click

Dim oCtl As System.Windows.Forms.Control

Debug.Print("------------------- Begin DDE Test
-----------------------")

g_lInstID = 0

' Initialize the DDE subsystem. This only needs to be done once.
'UPGRADE_WARNING: Add a delegate for AddressOf DDECallback Click for
more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?
keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
'If DdeInitialize(g_lInstID, AddressOf DDECallback,
APPCMD_CLIENTONLY Or MF_SENDMSGS Or MF_POSTMSGS, 0) Then
If DdeInitialize(g_lInstID, AddressOf DDECallback,
APPCMD_CLIENTONLY Or MF_SENDMSGS Or MF_POSTMSGS, 0) Then

Debug.Print("DDE Initialize Failure.")
TranslateError()

Else

Debug.Print("DDE Initialize Success.")

End If

'Enable the command buttons.
For Each oCtl In Controls

'UPGRADE_WARNING: TypeOf has a new behavior. Click for
more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?
keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
If ((TypeOf oCtl Is System.Windows.Forms.TextBox) Or
(TypeOf oCtl Is System.Windows.Forms.ComboBox)) And (oCtl.Enabled =
False) Then
oCtl.Enabled = True
End If

Next oCtl

cmdInitialize.Enabled = False
cmdUninitialize.Enabled = True
cmdClear.Enabled = True
cboItem.SelectedIndex = 0

Here is the function that I am calling:
Public Function DDECallback(ByVal uType As Integer, ByVal uFmt As
Integer, ByVal hConv As Integer, ByVal hszString1 As Integer, ByVal
hszString2 As Integer, ByVal hData As Integer, ByVal dwData1 As
Integer, ByVal dwData2 As Integer) As Integer

Dim lSize As Integer
Dim sBuffer As String
Dim Ret As Integer

Debug.Print("In client callback. uType: " & uType)

Select Case uType

' This is th eevent you'll receive when a server sends you
a advisment.
Case XTYP_ADVDATA
Debug.Print("XTYP_ADVDATA")

lSize = DdeGetData(hData, vbNullString, 0, 0)

' If size is 0 then there's no data to grab.
If (lSize > 0) Then

' Allocate a buffer for the return data.
sBuffer = New String(Chr(0), lSize - MAGIC_NUMBER)

' Grab the data.
lSize = DdeGetData(hData, sBuffer, Len(sBuffer),
0)

' Print the contents of the buffer.
frmDDEApp.txtValue.Text = sBuffer
End If

Case XTYP_ADVSTART
Debug.Print("XTYP_ADVSTART")

Case XTYP_ADVSTOP
Debug.Print("XTYP_ADVSTOP")

Case XTYP_CONNECT
Debug.Print("XTYP_CONNECT")

Case XTYP_CONNECT_CONFIRM
Debug.Print("XTYP_CONNECT_CONFIRM")

Case XTYP_DISCONNECT
Debug.Print("XTYP_DISCONNECT")

Case XTYP_ERROR
Debug.Print("XTYP_ERROR")

Case XTYP_EXECUTE
Debug.Print("XTYP_EXECUTE")

Case XTYP_MASK
Debug.Print("XTYP_MASK")

Case XTYP_MONITOR
Debug.Print("XTYP_MONITOR")

Case XTYP_POKE
Debug.Print("XTYP_POKE")

Case XTYP_REGISTER
Debug.Print("XTYP_REGISTER")
g_hService2 = hszString2

lSize = DdeQueryString(g_lInstID, hszString2,
vbNullString, 0, CP_WINANSI)
sBuffer = Space(lSize)
DdeQueryString(g_lInstID, hszString2, sBuffer, lSize +
1, CP_WINANSI)

sBuffer = UCase(sBuffer)

Case XTYP_REQUEST
Debug.Print("XTYP_REQUEST")

Case XTYP_SHIFT
Debug.Print("XTYP_SHIFT")

Case XTYP_UNREGISTER
Debug.Print("XTYP_UNREGISTER")

Case XTYP_WILDCONNECT
Debug.Print("XTYP_WILDCONNECT")

Case XTYP_XACT_COMPLETE
Debug.Print("XTYP_XACT_COMPLETE")

End Select

DDECallback = 0

End Function

Thanks to everyone for their help!

-Kurt


Kurt,

The compiler is wanting you to declare a delegate for the ddecallback
function. It would look something like (assuming your function
signiture is correct):

Public Delegate Function DDECallbackDelegate _
(ByVal uType As Integer, _
ByVal uFmt As Integer, _
ByVal hConv As Integer, _
ByVal hszString1 As Integer, _
ByVal hszString2 As Integer, _
ByVal hData As Integer, _
ByVal dwData1 As Integer, _
ByVal dwData2 As Integer) As Integer

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top