Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendMessageCallback function

35 views
Skip to first unread message

Troy McDowell

unread,
Apr 13, 2001, 4:16:04 PM4/13/01
to
Can anyone tell me why certain messages when used with the
SendMessageCallback function return the error of
"The message can be used only with synchronous operations."?

The obvious answer is that it is not allowed. The answer to the question I
am looking for is why they are not allowed.

How would anyone suggest working around this?
I need it to be asynchronous.

Here is a sample bas file showing this error.
It requires a form with a listbox, 2 command buttons and a label.

===================================================


Public Const LB_ADDSTRING = &H180
Public Const LB_INSERTSTRING = &H181
Public Const LB_DELETESTRING = &H182
Public Const LB_FINDSTRING = &H18F
Public Const LB_FINDSTRINGEXACT = &H1A2
Public Const LB_GETTEXT = &H189
Private Const FORMAT_MESSAGE_FROM_SYSTEM = 4096


Public Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Public Declare Function SendMessageCallback Lib "user32" Alias
"SendMessageCallbackA" (ByVal hwnd As Long, ByVal msg As Long, ByVal
wParam As Long, lParam As Any, ByVal lpResultCallBack As Long, ByVal
dwData As Long) As Long
Private Declare Function FormatMessage Lib "kernel32" Alias
"FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal
dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String,
ByVal nSize As Long, Arguments As Long) As Long

Public Sub DeleteString()
Dim lngVariableAddress As Long

lngVariableAddress = StrPtr("string")
' This Call works fine
x = SendMessageCallback(Form1.List1.hwnd, LB_DELETESTRING, 0&, 0&,
AddressOf SendCallback, ByVal lngVariableAddress) 'ByVal CLng(5)
If (x = 0) Then
Form1.label1.Caption "Delete Failed"
End If
End Sub


Public Sub AddString(Astring As String)
Dim lngVariableAddress As Long
Dim xa As Long
Dim lngRet As Long
Dim strAPIError As String
strAPIError = String$(2048, " ")
lngVariableAddress = StrPtr(Astring)
' I need the call or a very similar asynchronous function to Add the
String to a Listbox
x = SendMessageCallback(Form1.List1.hwnd, LB_ADDSTRING, 0&, ByVal
lngVariableAddress, AddressOf SendCallback, ByVal lngVariableAddress)
'ByVal CLng(5)
'x = PostMessage(Form1.List1.hwnd, LB_ADDSTRING, 0&, ByVal Astring)
If (x = 0) Then
xa = Err.LastDllError
lngRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&,
xa, 0, strAPIError, Len(strAPIError), 0)

strAPIError = Left$(strAPIError, lngRet)

Form1.label1.Caption = "Failed: " & strAPIError
End If

End Sub


' Callback for DeleteString and AddString
Public Function SendCallback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
InData As String, ByVal RetData As Long) As Boolean
If (uMsg = LB_DELETESTRING) Then
Debug.Print InData
Form1.label1.Caption = "ListCount = " & RetData
DeleteCallback = True
ElseIf (uMsg = LB_ADDSTRING) Then
Form1.label1.Caption = InData & " Added at " & RetData & "
Position"
End If
End Function

Sent via AllAPI.net
http://www.allapi.net/

0 new messages