Antonariy писал(а):В принципе подойдет, но с интерфейсами как-то красивее.
VB6 по запросу IDispatch отдаст только главный диспинтерфейс, сколько бы ни было дополнительных.
Т.е. красиво-то красиво, только это тупик
Antonariy писал(а):А как это будет выглядеть для двух и более методов? Или метода и свойства? К примеру Public Property Input.
Для двух методов:
- Код: Выделить всё
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Private Declare Function lstrcmpiW Lib "kernel32" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
Private Const PAGE_EXECUTE_READWRITE = &H40
Public Function Anything() As String
Anything = "Mary had a little lamb"
End Function
Public Sub Write_(ByVal vStr As Variant)
MsgBox vStr
End Sub
Public Sub Close_()
MsgBox "Closed"
End Sub
Private Sub GetIDsOfNamesReplacement(ByVal riid As Long, rgszNames As Long, ByVal cNames As Long, ByVal lcid As Long, ByVal rgDispId As Long)
If 0 = lstrcmpiW(rgszNames, StrPtr("Write")) Then
ReDim Names(cNames) As Long
CopyMemory Names(0), rgszNames, cNames * 4
Names(0) = StrPtr("Write_")
Call GetIDsOfNamesOriginal(riid, Names(0), cNames, lcid, rgDispId)
ElseIf 0 = lstrcmpiW(rgszNames, StrPtr("Close")) Then
ReDim Names(cNames) As Long
CopyMemory Names(0), rgszNames, cNames * 4
Names(0) = StrPtr("Close_")
Call GetIDsOfNamesOriginal(riid, Names(0), cNames, lcid, rgDispId)
Else
Call GetIDsOfNamesOriginal(riid, rgszNames, cNames, lcid, rgDispId)
End If
End Sub
Private Sub GetIDsOfNamesOriginal(ByVal riid As Long, rgszNames As Long, ByVal cNames As Long, ByVal lcid As Long, ByVal rgDispId As Long)
'Never called
End Sub
Private Sub Class_Initialize()
Dim pVTbl As Long, OldProtect As Long
CopyMemory pVTbl, ByVal ObjPtr(Me), 4
VirtualProtect ByVal pVTbl, 44, PAGE_EXECUTE_READWRITE, OldProtect
If OldProtect = PAGE_EXECUTE_READWRITE Then Exit Sub
CopyMemory ByVal pVTbl + 44, ByVal pVTbl + 20, 4
CopyMemory ByVal pVTbl + 20, ByVal pVTbl + 40, 4
End Sub
Далее аналогично.
Поскольку это простая подмена имени, то тип метода (свойство, не свойство) ни на что не влияет.