locked
return of ExtractIconEX RRS feed

  • Question

  • HICON hIcon;
    const auto &ret = ::ExtractIconEx(L"notexistfile", 0, &hIcon, &nullptr, 1);
    ------------------------------------------------------------------------------------------
    IN this code, variable 'ret' is 4294967295 (32bit UINT_MAX).

    Is This bug??

    I can't find uint max return value in the reference of ExtractIconEx.

    Return reference..↓

    If the nIconIndex parameter is -1, the phiconLarge parameter is NULL, and the phiconSmall parameter is NULL, then the return value is the number of icons contained in the specified file. Otherwise, the return value is the number of icons successfully extracted from the file.

    Monday, June 29, 2020 3:41 AM

Answers

  • Of course it's not a bug.  What would you expect it to return?  The problem with APIs that return a data value is that there is no way to communicate error conditions.  ExtractIconEx happens to do so by returning FFFFFFFF.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by ello29 Monday, June 29, 2020 1:48 PM
    Monday, June 29, 2020 4:52 AM

All replies

  • Of course it's not a bug.  What would you expect it to return?  The problem with APIs that return a data value is that there is no way to communicate error conditions.  ExtractIconEx happens to do so by returning FFFFFFFF.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by ello29 Monday, June 29, 2020 1:48 PM
    Monday, June 29, 2020 4:52 AM
  • Hello ello29,

    &nullptr is an invalid parameter.

    The following code returns 1 for me:

    	const auto &ret = ::ExtractIconEx(L"[pat to]\\test.ico", 0, &hIcon, NULL, 1);
    

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 29, 2020 9:21 AM
  • If the file doesn't exist, it returns (UINT)-1

    and (UINT)-1 = 0xffffffff = 4294967295

    Monday, June 29, 2020 9:46 AM
  • The problem is a documentation issue.  The return of (UINT) -1 upon an error condition is missing. 

    ExtractIconEx(A/W) is not documented to set the thread's last error code.  However, when the specified file cannot be located and the functions return the error value a call to GetLastError() returns 2 (ERROR_FILE_NOT_FOUND).

    Monday, June 29, 2020 10:05 AM
  • sorry, &nullptr is typo.
    Monday, June 29, 2020 1:48 PM
  • &nullptr is invalid.

    You cannot pass the address of any variable and make it part of calculation. It is useless and errorprone.

    Monday, June 29, 2020 3:21 PM