Weird Statment...

This is a discussion on Weird Statment... within the C++ Programming forums, part of the General Programming Boards category; Code: HANDLE h; if ((h=FindFirstFile("*.*", &info) != INVALID_HANDLE_VALUE)) // do something here This line gives me an Error: "Error C2440: ...

  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 01: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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    FindFirstFile("*.*", &info) != INVALID_HANDLE_VALUE
    is bool

    use
    Code:
    ((h=FindFirstFile("*.*", &info) ) != INVALID_HANDLE_VALUE)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,547
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21