- Код: Выделить всё
Declare Function PutMemVar Lib "msvbvm60" _
(ByVal pDst As Long, ByRef NewVar As Variant) As Long
Declare Function PutMemStr Lib "msvbvm60" _
(ByVal pDst As Long, ByRef NewStr As String) As Long
Declare Function PutMemObj Lib "msvbvm60" _
(ByVal pDst As Long, ByRef NewObj As Object) As Long
Declare Function GetMemVar Lib "msvbvm60" _
(ByVal pSrc As Long, ByRef MyVar As Variant) As Long
Declare Function GetMemStr Lib "msvbvm60" _
(ByVal pSrc As Long, ByRef MyStr As String) As Long
Declare Function GetMemObj Lib "msvbvm60" _
(ByVal pSrc As Long, ByRef MyObj As Object) As Long
Sub Main()
Dim var As Variant
Dim new_var As Variant
Dim str As String
Dim new_str As String
Dim obj As Object
Dim new_obj As Object
var = 1
new_var = 2
PutMemVar VarPtr(var), new_var
Debug.Print var 'Работает. Вернул 2
Set obj = New Collection
Set new_obj = New StdPicture
PutMemObj ObjPtr(obj), new_obj
Debug.Print TypeName(obj) 'Не работает. Вернул "Collection"
'вместо "StdPicture"
Set obj = Nothing
Set new_obj = Nothing
' str = "A"
' new_str = "B"
' 'Дальше Run-time error '0'
' PutMemStr StrPtr(str), new_str
' Debug.Print str 'Хочу получить "B"
var = 1
new_var = 2
GetMemVar VarPtr(new_var), var
Debug.Print var 'Работает. Вернул 2
' Set obj = New Collection
' Set new_obj = New StdPicture
' 'Дальше Run-time error '0'
' GetMemObj ObjPtr(new_obj), obj
' Debug.Print TypeName(obj) 'Хочу получить "StdPicture"
' Set obj = Nothing
' Set new_obj = Nothing
' str = "A"
' new_str = "B"
' 'Дальше Run-time error '0'
' GetMemStr StrPtr(new_str), str
' Debug.Print str 'Хочу получить "B"
End Sub
Как заставить эти функции работать?
PS
Если кому-то известно как работать с SetMemObj, SetMemVar, SetMemEvent, GetMemEvent, PutMemEvent, GetMemNewObj, PutMemNewObj, SetMemNewObj, о которых упоминал Viper, пишите сюда же.