|
Post by Michael Sync on Feb 23, 2006 5:47:50 GMT -5
How can i use " Marshal.PtrToStructure" in VB6? In my coding, I wrote like that Public Property Get ObjectFromPtr(ByVal lPtr As Long) As EVENTMSG ''Object Dim oTemp As EVENTMSG ' Turn the pointer into an illegal, uncounted interface CopyMemory oTemp, lPtr, 4 ' Do NOT hit the End button here! You will crash! ' Assign to legal reference ObjectFromPtr = oTemp ' Still do NOT hit the End button here! You will still crash! ' Destroy the illegal reference CopyMemory oTemp, 0&, 4 ' OK, hit the End button if you must End Property
But It make crashing my program. It would be great if you help me.
|
|
|
Post by Kelly Ethridge on Feb 23, 2006 14:12:04 GMT -5
If EVENTMSG is the structure defined in the windows API then you're only copying the value in lPtr into the first 4 bytes of the EVENTMSG structure. There is no object in there.
So I have no idea what you are trying to accomplish with this code. What does lPtr point to?
|
|
|
Post by Michael Sync on Feb 23, 2006 22:49:12 GMT -5
I got it. Public Property Get ObjectFromPtr(ByVal lPtr As Long) As EVENTMSG ''Object Dim oTemp As EVENTMSG ' Turn the pointer into an illegal, uncounted interface CopyMemory oTemp, lPtr, Len(oTemp) ' Do NOT hit the End button here! You will crash! ' Assign to legal reference ObjectFromPtr = oTemp ' Still do NOT hit the End button here! You will still crash! ' Destroy the illegal reference CopyMemory oTemp, 0&, Len(oTemp) ' OK, hit the End button if you must End Property
Actually, lPtr is one the parameters of JournalRecordProc. I 'm writing the program that can recorded a macro and can also play this macro by using JournalRecord Hook and JournalRecordPlayBack. u know, JournalRecordProc function is still running even I have stopped my program. I already used UnhookWindowsHookEx API to uninstall JournalRecord Hook. But it's still running after Form_Unload().
|
|
|
Post by Michael Sync on Feb 26, 2006 23:24:39 GMT -5
Oh. I have resolved this issue also. I used wrong usage for UnhookWindowsHookEx. Thanks.
|
|