CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2008
    Posts
    90

    [RESOLVED] Equivalent of IntPtr.

    What is the equivalent of IntPtr of Vb.Net in Vb6? For example what'll be the equivalent of the following 2 lines in Vb6?
    Dim htok As IntPtr
    htok = IntPtr.Zero

    Thanks.

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Equivalent of IntPtr.

    IntPtr in VB 6 would mean Long, so your code would look like this
    Code:
    Dim htok As Long
    htok = 0

  3. #3
    Join Date
    Sep 2008
    Posts
    90

    Thumbs up Re: Equivalent of IntPtr.

    Thanks!

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: [RESOLVED] Equivalent of IntPtr.

    That took long time to say thankya.
    I'm not even sure if the answer is correct. Isn't IntPtr a pointer?
    Ok, well forget I asked.

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] Equivalent of IntPtr.

    Quote Originally Posted by WoF View Post
    Isn't IntPtr a pointer?
    No; it's an integral type with the size of a pointer, IOW the machine word size. (See http://msdn.microsoft.com/en-us/libr...em.intptr.aspx) Actually, I always found the name a bit misleading...

    Ok, well forget I asked.
    No.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: [RESOLVED] Equivalent of IntPtr.

    Well, you live and learn.

    But reading the description you pointed out, it rather seems to be an object with many methods.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] Equivalent of IntPtr.

    Quote Originally Posted by WoF View Post
    [...] it rather seems to be an object with many methods.
    That's not uncommon in .NET. Even the plain vanilla Int32 has lots of them as well.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: [RESOLVED] Equivalent of IntPtr.

    Yeah, when I got in touch with .Net stuff, I read about those base classes and how classes can share common methods. It makes a plain memory variable look and operate like any other object and integrates perfectly into the philosophy and conventions of the language.

    Yet, it's a bit bewildering at the first glimpse.
    I suppose var.ToString is then the equivalent of Str(var) and var.GetType replaces the TypeOf var is construct.

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: [RESOLVED] Equivalent of IntPtr.

    Quote Originally Posted by WoF View Post
    I suppose var.ToString is then the equivalent of Str(var) [...]
    I have no experience with VB .NET, but yes, I think it will internally compile the latter as the former.

    [...] and var.GetType replaces the TypeOf var is construct.
    I wouldn't bet on that, however. In my primary (or rather only) .NET language C++/CLI there's a difference between var::typeid and var->GetType() (syntax based on the assumption that var is of a reference type). The former is evaluated at compile-time, the latter at runtime. And that doesn't just make a difference in terms of runtime performance, is may also yield a different result if var refers to an object of a type that is derived from that var originally was declared as.

    EDIT: Ok, there actually is the difference pointed out above, but you're probably right; a TypeOf var is construct wouldn't make much sense if it was evaluated at compile-time...
    Last edited by Eri523; September 21st, 2011 at 10:11 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: [RESOLVED] Equivalent of IntPtr.

    I think this topic might help you understand the whole casting to strings etc. in .NET, WoF :

    http://www.codeguru.com/forum/showthread.php?t=443873

  11. #11
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: [RESOLVED] Equivalent of IntPtr.

    Yes, thanks, Hannes. That explains the ToString() so far.
    Since I've noticed that all (or nearly all) .net objects have a ToString() method, you can get a string out from any object, whereas a VB6 Str() function always expects a numerical argument.

    Though, the casting "as string" becomes not immediately obvious to me. I know type casting from C++ (not .net) which serves mostly to change a pointer's quality for the compiler. You might have a pointer to an array of integers or a struct of some type and might further want to treat this as an array of bytes, so you do a cast for the compiler to know how to treat a ptr++ or what a *ptr finally is.

    Casting some object like a CommandButton as string doesn't sound so useful, whereas I think CommandButton.ToSring() might return the caption?

    Mainly, what I wanted to know was, that if although the syntax like var.ToString() or var.GetType() suggests that var is some complex object having own methods which consume memory space, var indeed might still be a simple integer, consuming 4 bytes only, but sharing those common properties which in fact are equivalents to stuff we would do with functions or other constructs in VB6.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured