Results 1 to 8 of 8

Thread: Why integer???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Why integer???

    I am trying to learn API. I started out buy using the findwindow fuction.
    It did not work until I changed the return type to integer.

    From:
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    To:
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.       (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    Everywhere I look, its show the return type as Long. If I use long, my results are just random numbers.

    Why?

    VB.NET 2003

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Why integer???

    If you are using VB.NET then you should be using IntPtr rather than Integer.

    FindWindow API returns the handle of the window and handles are stroed in IntPtr datatypes unlike VB 6.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Why integer???

    Are you sure you have not looked at code for Classic VB rather then VB.NET? In classic VB (meaning version 6 and some of the earlier) integer was 16bit, while long was 32bit.

    Today in VB.NET, an integer is finaly 32bit, hence an integer in VB.NET is the same as a long in VB 6.


    PS: DOn't ask me why I know these things. I have never touched VB.NET..


    - ØØ -

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Resolved Re: Why integer???

    Thanks, thats what I needed.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Why integer???

    My esteemed comrade Noteme is right, integers inany .NET language are 32-bit.

    VB6 is at fault here really for perpetuating integers as being signed 16 bits rather than signed 32 bits.

    You will find that there is very little API example code availabe for .NET languages. (C# does fare a little better than VB.net in this respect, but you should be using c# anyway but I'm biased). Roughly speaking if you are going to use Vb6 code to learn from then ... Vb6 long should be replaced with VB.net integer.
    I don't live here any more.

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Why integer???

    Or you can check out APIViewer 2004 in my sig, which has a .NET mode that has the changed declarations for you...

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Why integer???

    Quote Originally Posted by wossname
    My esteemed comrade Noteme is right, integers inany .NET language are 32-bit.

    VB6 is at fault here really for perpetuating integers as being signed 16 bits rather than signed 32 bits.

    You will find that there is very little API example code availabe for .NET languages. (C# does fare a little better than VB.net in this respect, but you should be using c# anyway but I'm biased). Roughly speaking if you are going to use Vb6 code to learn from then ... Vb6 long should be replaced with VB.net integer.

    How did you manage to use that much space to write exactly the same as I had already done?

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Why integer???

    I learned all about talking complete garbage from you m00sy.
    I don't live here any more.

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