Thread: Weird Statment...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Weird Statment...

    Code:
    HANDLE h;
    
    if ((h=FindFirstFile("*.*", &info) != INVALID_HANDLE_VALUE))
      // do something here
    This line gives me an Error: "Error C2440: '=' : cannot convert from 'bool' to 'HANDLE'".
    But the function returns HANDLE.

    Also when I do this, everything is fine:
    Code:
    HANDLE h;
    
    h = FindFirstFile("*.*", &info);
    if (h != INVALID_HANDLE_VALUE)
      // do something here
    Can anyone please explain to me how could the same function return different types???


    Thank you.
    Last edited by Devil Panther; 11-17-2006 at 02:46 PM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    FindFirstFile("*.*", &info) != INVALID_HANDLE_VALUE
    is bool

    use
    Code:
    ((h=FindFirstFile("*.*", &info) ) != INVALID_HANDLE_VALUE)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your () are in the wrong place

    if ((h=FindFirstFile("*.*", &info) != INVALID_HANDLE_VALUE))
    should be
    if ((h=FindFirstFile("*.*", &info) ) != INVALID_HANDLE_VALUE )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Oops...
    Not a good idea to work into the night

    Thanks guys.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 11:23 PM
  2. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  3. Weird Characters With GetDlgItemText
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2006, 04:53 PM
  4. weird error
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 07-17-2005, 07:32 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM