By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

Extract exe file icon.

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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" <mr********@hotmail.com> wrote in message
news:#P**************@TK2MSFTNGP12.phx.gbl...
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

Nov 16 '05 #2

P: n/a
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)" <sh**@fakedomain.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
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" <mr********@hotmail.com> wrote in message
news:#P**************@TK2MSFTNGP12.phx.gbl...
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


Nov 16 '05 #3

P: n/a

After calling the ExtractIconEx api, do this

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

--
Shak
C# / .NET MCP
(Houston)
"Mohammad-Reza" <mr********@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
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)" <sh**@fakedomain.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
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" <mr********@hotmail.com> wrote in message
news:#P**************@TK2MSFTNGP12.phx.gbl...
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



Nov 16 '05 #4

P: n/a
This link might be of some help... :-)

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

--
HTH

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

"Mohammad-Reza" <mr********@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
| 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)" <sh**@fakedomain.com> wrote in message
| news:uj**************@tk2msftngp13.phx.gbl...
| > 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" <mr********@hotmail.com> wrote in message
| > news:#P**************@TK2MSFTNGP12.phx.gbl...
| > > 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
| > >
| > >
| >
| >
|
|
Nov 16 '05 #5

P: n/a
I try them but it doesn't work.
Would you please send me a sample code?
thanks

"Kyril Magnos" <ky**********@yahoo.com> wrote in message
news:#b**************@TK2MSFTNGP11.phx.gbl...
This link might be of some help... :-)

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

--
HTH

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

"Mohammad-Reza" <mr********@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
| 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)" <sh**@fakedomain.com> wrote in message
| news:uj**************@tk2msftngp13.phx.gbl...
| > 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" <mr********@hotmail.com> wrote in message
| > news:#P**************@TK2MSFTNGP12.phx.gbl...
| > > 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
| > >
| > >
| >
| >
|
|

Nov 16 '05 #6

P: n/a
[DllImport("Shell32.dll",EntryPoint="ExtractIconExW ",CharSet=CharSet.Unicode,
ExactSpelling=true,CallingConvention=CallingConven tion.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!" :-)

"Mohammad-Reza" <mr********@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
|I try them but it doesn't work.
| Would you please send me a sample code?
| thanks
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:#b**************@TK2MSFTNGP11.phx.gbl...
| > This link might be of some help... :-)
| >
| > http://www.pinvoke.net/default.aspx/....ExtractIconEx
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Mohammad-Reza" <mr********@hotmail.com> wrote in message
| > news:eV**************@TK2MSFTNGP11.phx.gbl...
| > | 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)" <sh**@fakedomain.com> wrote in message
| > | news:uj**************@tk2msftngp13.phx.gbl...
| > | > 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" <mr********@hotmail.com> wrote in message
| > | > news:#P**************@TK2MSFTNGP12.phx.gbl...
| > | > > 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
| > | > >
| > | > >
| > | >
| > | >
| > |
| > |
| >
| >
|
|
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.