472,127 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Extract exe file icon.

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
6 10305
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
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

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
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
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
[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.

Similar topics

4 posts views Thread by Mehdi Mousavi | last post: by
2 posts views Thread by Steve | last post: by
3 posts views Thread by VP Borza | last post: by
6 posts views Thread by Udi | last post: by
7 posts views Thread by =?Utf-8?B?QmVu?= | last post: by
reply views Thread by Sathyaish | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.