Hallo Community,
ich möchte diesen Thread wieder hochholen:
ich hatte jetzt eine Weile meine Interprozess-Kommunikation auf ActiveX umgestellt, aber neben neuen Problemen kam auch hier der ursprüngliche Grund für den Wechsel auch auf: bei CopyStruct hatte ich aufgrund von SendMessage das Problem, dass wenn eines der kommunizierenden Programme sich "aufhängte", auch die anderen Programme anfingen zu "laggen" oder ganz einfroren. VBStein riet mir damals zu PostMessage, aber es hat nicht so recht geklappt.
Da jetzt mit der ActiveX-Methode das Problem mit dem Aufhängen auch vorhanden ist, habe ich kurzerhand alles wieder auf CopyStruct umgestellt und versuche den Ansatz mit PostMessage.
Nun meine Analysen:
ich habe herausgefunden, dass in meinem Code der PostMessage-Befehl korrekt abgesetzt wird, aber das Subclassing reagiert auf den eingehenden PostMessage nicht.. nachfolgend der relevante Teil meines Codes:
Private Function InternSendData(Data As String, hWnd As Long) As Boolean
On Error GoTo Fehler
Dim DesthWnd As Long, B() As Byte
Dim CD As COPYDATASTRUCT
Dim lRet As Long
DesthWnd = hWnd
If DesthWnd = 0 Then
InternSendData = False
Else
CD.dwData = 1
B = StrConv(Data, vbFromUnicode)
CD.cbData = Len(Data) + 1
CD.lpData = VarPtr(B(0))
DoEvents
lRet = PostMessage(DesthWnd, WM_COPYDATA, 0, CD)
InternSendData = True
End If
Exit Function
Fehler:
InternSendData = False
End Function
....
Private Sub SubClass()
'-------------------------------------------------------------
'Initiates the subclassing of this UserControl's window (hwnd).
'Records the original WinProc of the window in mWndProcOrg.
'Places a pointer to the object in the window's UserData area.
'-------------------------------------------------------------
'Exit if the window is already subclassed.
If mWndProcOrg Then Exit Sub
'Redirect the window's messages from this control's default
'Window Procedure to the SubWndProc function in your .BAS
'module and record the address of the previous Window
'Procedure for this window in mWndProcOrg.
mWndProcOrg = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubWndProc)
'Record your window handle in case SetWindowLong gave you a
'new one. You will need this handle so that you can unsubclass.
mHWndSubClassed = hWnd
'Store a pointer to this object in the UserData section of
'this window that will be used later to get the pointer to
'the control based on the handle (hwnd) of the window getting
'the message.
Call SetWindowLong(hWnd, GWL_USERDATA, ObjPtr(Me))
End Sub
'The address of this function is used for subclassing.
'Messages will be sent here and then forwarded to the
'UserControl's WindowProc function. The HWND determines
'to which control the message is sent.
Public Function SubWndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam _
As Long, ByVal lParam As Long) As Long
On Error Resume Next
'Get pointer to the control's VTable from the
'window's UserData section. The VTable is an internal
'structure that contains pointers to the methods and
'properties of the control.
ptrObject = GetWindowLong(hWnd, GWL_USERDATA)
'Copy the memory that points to the VTable of our original
'control to the shadow copy of the control you use to
'call the original control's WindowProc Function.
'This way, when you call the method of the shadow control,
'you are actually calling the original controls' method.
CopyMemory ctlShadowControl, ptrObject, 4
SubWndProc = ctlShadowControl.WindowProc(hWnd, Msg, wParam, lParam)
CopyMemory ctlShadowControl, 0&, 4
Set ctlShadowControl = Nothing
End Function Danke für Eure Hilfe! 0
Beitrag wurde zuletzt am 29.09.08 um 21:44:10 editiert. |