Change icon for console applications 2

Change icon for console applications 2

This is a continuation of this topic: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/276032

I had been using the code in that topic to change icons for a couple years but recently got a new computer/OS/VS/IVF and the code no longer works.  Initially when i opened the resource file (ci.rc) in visual studio i received an error that rcdll.dll could not be found in "C:\Program Files (x86)\Windows Kits\10\bin\x86", so i copied it from "C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" to that location and the error went away.

I now have:

Windows 10 Pro

Microsoft Visual Studio Community 2017
Version 15.2 (26430.13) Release
VisualStudio.15.Release/15.2.0+26430.13
Microsoft .NET Framework
Version 4.6.01586

Visual C++ 2017   00369-60000-00001-AA511

Microsoft Visual C++ 2017

Intel® Advisor 2017 Update 3   

Intel® Advisor 2017 Update 3, (build 510716), Copyright © 2009-2017 Intel Corporation. All rights reserved.

Intel® Inspector 2017 Update 3   
Intel® Inspector 2017 Update 3, (build 510645), Copyright © 2009-2017 Intel Corporation. All rights reserved.

Intel® Parallel Studio XE 2017 Update 4 Composer Edition for C++ Windows*   Package ID: w_comp_lib_2017.4.210
Intel® Parallel Studio XE 2017 Update 4 Composer Edition for C++ Windows* Integration for Microsoft* Visual Studio* 2017, Version 17.0.76.15, Copyright © 2002-2017 Intel Corporation. All rights reserved.
* Other names and brands may be claimed as the property of others.

Intel® Parallel Studio XE 2017 Update 4 Composer Edition for Fortran Windows*   Package ID: w_comp_lib_2017.4.210
Intel® Parallel Studio XE 2017 Update 4 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2017, Version 17.0.0047.15, Copyright © 2002-2017 Intel Corporation. All rights reserved.
* Other names and brands may be claimed as the property of others.

Here is the code:

SUBROUTINE ci(i)
! Interface to the SetConsoleIcon function
USE ISO_C_BINDING
USE IFWIN
IMPLICIT NONE

INTEGER(WORD), INTENT(IN) :: i										! index of ico to load
POINTER SetConsoleIcon

INTERFACE
INTEGER FUNCTION SetConsoleIcon(hIcon)
!DEC$ ATTRIBUTES DEFAULT, STDCALL :: SetConsoleIcon
USE ISO_C_BINDING
INTEGER(KIND=C_INTPTR_T) :: hIcon
ENDFUNCTION SetConsoleIcon
END INTERFACE

!----------------------------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------- begin define local variables ------------------------------------------------------------
INTEGER(KIND=HANDLE) :: hMainMod									! the handle of the executable
INTEGER(KIND=HANDLE) :: hIcon										! the handle of the icon
INTEGER(KIND=HANDLE) :: hLib										! the handle of the library that contains the function
INTEGER(KIND=HANDLE) :: SetConsoleIcon_Address						! the address of the function
INTEGER(KIND=HANDLE) ::	iResult
!------------------------------------------------------------ end define local variables ------------------------------------------------------------
!----------------------------------------------------------------------------------------------------------------------------------------------------

! Obtain the module handle; the icon handle, the library handle
hMainMod = GetModuleHandle(NULL)
!hIcon = LoadIcon(hMainMod, i)
hIcon = LoadIcon(hMainMod, MAKEINTRESOURCE(i))
hLib = LoadLibrary("Kernel32.dll"//C_NULL_CHAR)

! obtain the address to the function and obtain the function itself
SetConsoleIcon_Address = GetProcAddress(hLib, "SetConsoleIcon"//C_NULL_CHAR)
CALL C_F_PROCPOINTER(TRANSFER(SetConsoleIcon_Address, C_NULL_FUNPTR), SetConsoleIcon)

! display the console with the new icon
iResult = SetConsoleIcon(hIcon)

ENDSUBROUTINE ci

 

When i run it i don't get any errors, but the icon doesn't change anymore (like it did before the hardware/software changes).  Here are the LHS values at the end of this sub on my new machine:

        hMainMod    140699780251648    INTEGER(8)
        hIcon    40244361    INTEGER(8)
        hLib    140730640760832    INTEGER(8)
        SetConsoleIcon_Address    140730641171104    INTEGER(8)
        iResult    0    INTEGER(4)

And here they are on my old machine:

        hMainMod          5366677504         INTEGER(8)

        hIcon     -1977796927       INTEGER(8)

        hLib       2004287488         INTEGER(8)

        SetConsoleIcon_Address             2004552288         INTEGER(8)

        iResult  1              INTEGER(4)

 

It seems an iResult of 1 is success and 0 is failure.  The LHS values for some of the calls seem to be many orders of magnitude larger on the new machine than the old.  Maybe it's time to stop using 32bit stuff?  Any ideas?

thanks,

rob

Zone: 

Thread Topic: 

Help Me
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply
        hIcon    =  LoadIcon( ghInstance, MAKEINTRESOURCE(int(IDI_ICON2,word)))
        hConsole = GetConsoleWindow()
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_SMALL,KIND=fWPARAM), hIcon)
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_BIG,KIND=fWPARAM),   hIcon)

You don't need to load library for kernel32, I found SetConsoleIcon unreliable and use the sendmessage method.

Thank you andrew! it works now.

I did some searching with what you provided which turned up this: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/721841

Leave a Comment

Please sign in to add a comment. Not a member? Join today