Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

While migrating my code for VS 2008 to VS 2017 i am experiencing following warning for the ExtractIcon function. The code fragment goes like this,

C++
HMODULE hExeModule = ::GetModuleHandle(NULL);
HICON  hIcon = ::ExtractIcon(hExeModule, iconFileName, iconIndex);

The warning i am getting is
warning C6388: 'hExeModule' might not be '0': this does not adhere to the specification for the function 'ExtractIconW'.
It seems that the prototype for the ExtractIcon function is like this.

C++
SHSTDAPI_(HICON) ExtractIconW(_Reserved_ HINSTANCE hInst, _In_ LPCWSTR pszExeFileName, UINT nIconIndex);

Here the first parameter is _Reserved_ . I think it is causing the problem. Any idea what i should be doing to get it running.

What I have tried:

I have tried following code.

C++
HICON hIcon = NULL;
    HMODULE hExeModule = ::GetModuleHandle(NULL);
	if (hExeModule != NULL)
	{
		hIcon = ::ExtractIcon(hExeModule, iconFileName, iconIndex);
       }
Posted
Updated 6-Dec-17 21:19pm

The warning is thrown because the parameter is declared as _Reserved_. In such cases NULL should be passed.

The ExtractIcon function (Windows)[^] documentation is unclear here. With other functions, the documentation usually states explicitly that the parameter should be NULL.

I suggest to pass NULL and check if an icon handle is returned. I expect that it will work because the "Handle to the instance of the application that calls the function" should be not required to load an icon from a specific file.
 
Share this answer
 
Comments
PrafullaVedante 7-Dec-17 3:34am    
The unclear documentation is creating some suspicion here. I am checking it by passing the NULL. Will update thread shortly.
See here: MSDN - C6388[^].
 
Share this answer
 
Comments
PrafullaVedante 7-Dec-17 3:13am    
Does that mean first parameter is redundant and should always sent as a NULL ?
CPallini 7-Dec-17 3:30am    
Well, the _Reserved_ declaration, in sal.h header, gives a hint:
// Reserved pointer parameters, must always be NULL.
#define _Reserved_ _SAL2_Source_(_Reserved_, (), _Pre1_impl_(__null_impl))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900