I want to save the address of an Object in a long and then access it by using another Object variable of the same type but Windows is always closing the app for illegal memory access. The code is similar to:
dim o as New <some-class>
o.<some-property>=123 'say
dim lng as Long
lng = ObjPtr(o)
dim o2 as <some-class>
CopyMemory o2, lng, 4 'Win32 API
debug.Print o2.<some-property> 'expect 123
In a test program I get the error after the function ( main ) executes, but the expected output does appear; on the production program I get on the CopyMemory line itself. What is the correct way to do this?
dim o as New <some-class>
o.<some-property>=123 'say
dim lng as Long
lng = ObjPtr(o)
dim o2 as <some-class>
CopyMemory o2, lng, 4 'Win32 API
debug.Print o2.<some-property> 'expect 123
In a test program I get the error after the function ( main ) executes, but the expected output does appear; on the production program I get on the CopyMemory line itself. What is the correct way to do this?