Quick Search for:  in language:    
VB6,undocumented,functions,VarPtr,StrPtr,ObjP
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 140,189. lines
 Jobs: 376. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for .Net.
Click here to see a screenshot of this code!Ray Picking for 3d Objects
By Jay1_z on 11/23

(Screen Shot)

Embed Images into Xml Files
By Chris Richards on 11/23


Encryption and Alternate Data Stream
By Philip Pierce on 11/23


Click here to see a screenshot of this code!AddressBook
By Ekong George Ekong on 11/23

(Screen Shot)

Click here to see a screenshot of this code!Command Line Redirection
By kaze on 11/23

(Screen Shot)

Fader
By Ahmad Hammad on 11/23


Click here to see a screenshot of this code!Get content of a web page (simple)
By Tin Trung Dang on 11/22

(Screen Shot)

Retrieve the long path name for a short path name.
By Özgür Aytekin on 11/22


Easy Randomizer
By Christian Müller on 11/22


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

undocumented varptr in vb7

Print
Email
 

Submitted on: 8/9/2002 6:02:19 PM
By: Izek_S 
Level: Intermediate
User Rating: By 5 Users
Compatibility:VB.NET

Users have accessed this article 4702 times.
 
(About the author)
 
     VB6 has 3 undocumented functions. VarPtr, StrPtr, and ObjPtr.StrPtr returns object of a string, VarPtr returns address of any other variable and ObjPtr returns address of an object. In VB.Net these 3 functions are abosolete but their functionality is still avaliable.

 
 
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
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/4/2002 7:03:01 PM:
thnx i needed this
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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??
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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 ~~~~~~
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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 ?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/24/2003 10:14:05 PM:Unruled Boy
how about the other to functions?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | .Net Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.