Extract exe file icon.

  • Thread starter Thread starter Mohammad-Reza
  • Start date Start date
M

Mohammad-Reza

Hi
I want to extract icon of an exe file and want to know how.
I look at the MSDN and find out that I can use ExtractIconEx() Windows API
but in there are some changes to that api in c# I made those changes like
this :
public static extern uint ExtractIconEx(

[MarshalAs(UnmanagedType.LPTStr)]

string szFile,

int nIconIndex,

ref int[] phiconLarge,

ref int[] phiconSmall,

uint nIcons);

but its returns and integer array and not an icon.

I want to know did I do some thing wrong or I must do something further.

Anyway please tell me how I can do this

Thanks in advance

Mohammad-Reza
 
Mohammed

You have to convert to icon using the following statement

Icon largeIcon1 = Icon.FromHandle(phiconLarge[0]);
Icon smallIcon1 = Icon.FromHandle(phiconSmall[0]);
 
Thanks for your answer
In the api I must send pointer if an interger array to it
then I must use that array in the convert code or use phiconLarge or small
directly?

thanks.

Shakir Hussain (C# .NET MCP) said:
Mohammed

You have to convert to icon using the following statement

Icon largeIcon1 = Icon.FromHandle(phiconLarge[0]);
Icon smallIcon1 = Icon.FromHandle(phiconSmall[0]);

--
Shak
C# .NET MCP
(Houston)




Mohammad-Reza said:
Hi
I want to extract icon of an exe file and want to know how.
I look at the MSDN and find out that I can use ExtractIconEx() Windows API
but in there are some changes to that api in c# I made those changes like
this :
public static extern uint ExtractIconEx(

[MarshalAs(UnmanagedType.LPTStr)]

string szFile,

int nIconIndex,

ref int[] phiconLarge,

ref int[] phiconSmall,

uint nIcons);

but its returns and integer array and not an icon.

I want to know did I do some thing wrong or I must do something further.

Anyway please tell me how I can do this

Thanks in advance

Mohammad-Reza
 
After calling the ExtractIconEx api, do this

Icon largeIcon1 = Icon.FromHandle((IntPtr)phiconLarge[0]);

--
Shak
C# / .NET MCP
(Houston)


Mohammad-Reza said:
Thanks for your answer
In the api I must send pointer if an interger array to it
then I must use that array in the convert code or use phiconLarge or small
directly?

thanks.

Shakir Hussain (C# .NET MCP) said:
Mohammed

You have to convert to icon using the following statement

Icon largeIcon1 = Icon.FromHandle(phiconLarge[0]);
Icon smallIcon1 = Icon.FromHandle(phiconSmall[0]);

--
Shak
C# .NET MCP
(Houston)




Mohammad-Reza said:
Hi
I want to extract icon of an exe file and want to know how.
I look at the MSDN and find out that I can use ExtractIconEx() Windows API
but in there are some changes to that api in c# I made those changes like
this :
public static extern uint ExtractIconEx(

[MarshalAs(UnmanagedType.LPTStr)]

string szFile,

int nIconIndex,

ref int[] phiconLarge,

ref int[] phiconSmall,

uint nIcons);

but its returns and integer array and not an icon.

I want to know did I do some thing wrong or I must do something further.

Anyway please tell me how I can do this

Thanks in advance

Mohammad-Reza
 
This link might be of some help... :-)

http://www.pinvoke.net/default.aspx/shell32.ExtractIconEx

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

| Thanks for your answer
| In the api I must send pointer if an interger array to it
| then I must use that array in the convert code or use phiconLarge or small
| directly?
|
| thanks.
|
| | > Mohammed
| >
| > You have to convert to icon using the following statement
| >
| > Icon largeIcon1 = Icon.FromHandle(phiconLarge[0]);
| > Icon smallIcon1 = Icon.FromHandle(phiconSmall[0]);
| >
| > --
| > Shak
| > C# .NET MCP
| > (Houston)
| >
| >
| >
| >
| > | > > Hi
| > > I want to extract icon of an exe file and want to know how.
| > > I look at the MSDN and find out that I can use ExtractIconEx() Windows
| API
| > > but in there are some changes to that api in c# I made those changes
| like
| > > this :
| > > public static extern uint ExtractIconEx(
| > >
| > > [MarshalAs(UnmanagedType.LPTStr)]
| > >
| > > string szFile,
| > >
| > > int nIconIndex,
| > >
| > > ref int[] phiconLarge,
| > >
| > > ref int[] phiconSmall,
| > >
| > > uint nIcons);
| > >
| > > but its returns and integer array and not an icon.
| > >
| > > I want to know did I do some thing wrong or I must do something
further.
| > >
| > > Anyway please tell me how I can do this
| > >
| > > Thanks in advance
| > >
| > > Mohammad-Reza
| > >
| > >
| >
| >
|
|
 
[DllImport("Shell32.dll",EntryPoint="ExtractIconExW",CharSet=CharSet.Unicode,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
public static extern int ExtractIconEx(string sFile,int iIndex, out IntPtr
piLargeVersion, out IntPtr piSmallVersion, int amountIcons);

public class Foo()
{
IntPtr large, small;
Icon extractedIcon;
ArrayList items;

public Foo()
{
items = new ArrayList();

// Extract Normal folder
ExtractIconEx("Shell32.dll", 3, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);

// Extract Open folder
ExtractIconEx("Shell32.dll", 4, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);

// Extract A drive
ExtractIconEx("Shell32.dll", 6, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);

// Extract Harddisk
ExtractIconEx("Shell32.dll", 8, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);

// Extract Network drive
ExtractIconEx("Shell32.dll", 9, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);

// Extract CDROM drive
ExtractIconEx("Shell32.dll", 11, out large,out small, 1);
extractedIcon= Icon.FromHandle(small);
items.Add(extractedIcon);
}
}

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

|I try them but it doesn't work.
| Would you please send me a sample code?
| thanks
|
| | > This link might be of some help... :-)
| >
| > http://www.pinvoke.net/default.aspx/shell32.ExtractIconEx
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > | > | Thanks for your answer
| > | In the api I must send pointer if an interger array to it
| > | then I must use that array in the convert code or use phiconLarge or
| small
| > | directly?
| > |
| > | thanks.
| > |
| > | | > | > Mohammed
| > | >
| > | > You have to convert to icon using the following statement
| > | >
| > | > Icon largeIcon1 = Icon.FromHandle(phiconLarge[0]);
| > | > Icon smallIcon1 = Icon.FromHandle(phiconSmall[0]);
| > | >
| > | > --
| > | > Shak
| > | > C# .NET MCP
| > | > (Houston)
| > | >
| > | >
| > | >
| > | >
| > | > | > | > > Hi
| > | > > I want to extract icon of an exe file and want to know how.
| > | > > I look at the MSDN and find out that I can use ExtractIconEx()
| Windows
| > | API
| > | > > but in there are some changes to that api in c# I made those
| changes
| > | like
| > | > > this :
| > | > > public static extern uint ExtractIconEx(
| > | > >
| > | > > [MarshalAs(UnmanagedType.LPTStr)]
| > | > >
| > | > > string szFile,
| > | > >
| > | > > int nIconIndex,
| > | > >
| > | > > ref int[] phiconLarge,
| > | > >
| > | > > ref int[] phiconSmall,
| > | > >
| > | > > uint nIcons);
| > | > >
| > | > > but its returns and integer array and not an icon.
| > | > >
| > | > > I want to know did I do some thing wrong or I must do something
| > further.
| > | > >
| > | > > Anyway please tell me how I can do this
| > | > >
| > | > > Thanks in advance
| > | > >
| > | > > Mohammad-Reza
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| >
| >
|
|
 
Back
Top