|
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)
Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return ret
End Function | |
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
9/4/2002 7:03:01 PM: thnx i needed this
|
9/6/2002 10:52:12 PM:khairil anwar how about
this?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~
Private Declare Function GetProp Lib
"user32" Alias "GetPropA"(ByVal hwnd
As Integer, ByVal lpString As String)
As Integer
Private objProcClass As
New cProc
If (GetProp(hwnd, hwnd &
"#" & iMsg & "#" & iC) =
ObjPtr(objProcClass)) Then
...
...
...
End
If
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c
an you help me figure this out?
|
9/7/2002 2:58:46 AM: basicaly that checks
"<hwnd>#<imsg>#<ic>" property of the
virtual property bag associated with
the window handle for a certain value
and then checks if that value is the
address of some user object
|
9/13/2002 10:22:46 AM:David Bue Pedersen Great code! 5 globes from here! But I
need to use all of the good ol'
undocumented functions; VarPtr, StrPtr,
and ObjPtr. Have any of you redone
these?!? Then please post them to help
us all :-) Best regards! David!
|
9/13/2002 4:00:13 PM: varptr tat i posted handles everything,
strings, objects, variables, so it
repalces all 3 vb6 functions varptr,
strptr and objptr
|
10/9/2002 8:05:39 PM:tdtomlins Great code but how do you reverse it by
getting the Item from the location of
the pointer??
|
11/19/2002 11:36:27 PM:Andrew Christiansen The only time I've ever had to use
VarPtr is when sending a message to a
textbox to have the Windows XP pop up
balloon point to it. When I moved to
VB.net I couldn't figure out how to get
VarPtr's functionality in VB.net.
Obviously I found it :-) 5 globes from
me.
|
12/17/2002 5:02:40 PM:Syko9000 Best I can figure, a GCHandle is not
the actual pointer to the
object(sadly). It's a handle to a
pointer to an object...or something,
but...if you call GC.Free() the handle
that this "VarPtr" function returns is
invalid and no use to anyone. so
comment out the "GC.Free()" and to get
the object back do ~~~~~~ Dim GC As
GCHandle = New GCHandle(New
IntPtr(VarPtrReturnValue)) : Dim
TheObject = GC.Target ~~~~~~
|
12/17/2002 5:37:26 PM:Syko9000 Opps...the code in that is wrong, and
now I can't get VB.NET to open to work
out the correction...LOL...So just
ignore most of that... using the
"op_Explicit" function and not
"Pinning" an object is ... better...
cause it works on all Objects...not
just the "Pinnable" ones...(Forms and
userdefined class are apparently not
pinnable)... just don't "Free" it till
you're done with it...
|
1/16/2003 4:31:06 AM: I have tried using this when using the
TTM_SETTITLE Api call for balloon
tooltips however only the first
characater appears. Are you aware of
any issues with strings. I have tries
declaring the string in different ways
(public, const). The project is a COM
dll, could this affect it ?
|
7/2/2003 4:29:59 PM: Thats because the text is stored as
unicode, which in high byte/low byte
order, makes the second byte 'zero',
(a.k.a. end-of-string). Use the
System.Text classes to build an ASCII
string instead.
|
7/8/2003 11:56:06 AM: When I try to build it (VB .NET 2003) I
get the error message:An unhandled
exception of type
'System.ArgumentException' occurred in
mscorlib.dll
Additional information:
Object contains non-primitive or
non-blittable data.
|
7/8/2003 12:06:24 PM: Try for example:
VarPtr(me)
in a
form.
I'm trying to do a memory
redirect:
Private Property Let
VirtualTableEntry(ByVal FarPointer As
Long)
CopyMemory PtrToMyself,
ByVal ObjPtr(Me), 4 'get pointer to
object (Me)
CopyMemory ByVal
PtrToMyself + &H1C + VTIndex * 4,
FarPointer, 4 'put VT entry
End
Property
|
7/24/2003 10:14:05 PM:Unruled Boy how about the other to functions?
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|