ExtractAssociatedIcon API 
Author Message
 ExtractAssociatedIcon API

Help ! I can't make the ExtractAssociatedIcon API call work. I am
running on NT 4.0 with SP3. I am writing the code in VB6.0. I don't get
any errors it just doesn't do anything. Anyone have any ideas ?

Thanks.
Raymond

PS: ExtractIcon works fine for me so I don't know what the deal is with
ExtractAssociatedIcon....



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
OK after reading my own message I can see I didn't provide anywhere near
enough information...

index = 2
myfile = "c:\test.doc"+string(255,0)
MyReturnCode = ExtractAssociatedIcon(app.hInstance, myfile, index)

In the above example MyReturnCode always = 0 and myfile and index are
unchanged.
I have tried setting index to 0,1, and the length of myfile to no avail.
If anyone out there has gotten this api to work I sure would appreciate
some help.
Thanks.
Raymond

Quote:

> Help ! I can't make the ExtractAssociatedIcon API call work. I am
> running on NT 4.0 with SP3. I am writing the code in VB6.0. I don't get
> any errors it just doesn't do anything. Anyone have any ideas ?

> Thanks.
> Raymond

> PS: ExtractIcon works fine for me so I don't know what the deal is with
> ExtractAssociatedIcon....



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" _
   Alias "ExtractAssociatedIconA" _
  (ByVal hInst As Long, _
   ByVal lpIconPath As String, _
   lpiIcon As Long) As Long

Private Declare Function DrawIcon Lib "user32" _
  (ByVal hdc As Long, _
   ByVal x As Long, _
   ByVal Y As Long, _
   ByVal hIcon As Long) As Long

Private Declare Function DestroyIcon Lib "user32" _
  (ByVal hIcon As Long) As Long

Private Sub Command1_Click()

   Dim index As Long
   Dim hIcon As Long
   Dim myfile  As String

   index = 2
   myfile = "C:\qsptr1.gif"

   Picture1.Cls

   hIcon = ExtractAssociatedIcon(App.hInstance, myfile, index)

   Call DrawIcon(Picture1.hdc, 1, 1, hIcon)
   Call DestroyIcon(hIcon)

End Sub

You do not need to pad the string with 0's when you pass a string .. only
when you are padding a string for a returned value from the API.  You were
requesting icons from a file named:

c:\test.doc000000000000000000000000000000000000000 ... etc

--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


| OK after reading my own message I can see I didn't provide anywhere near
| enough information...
|
| index = 2
| myfile = "c:\test.doc"+string(255,0)
| MyReturnCode = ExtractAssociatedIcon(app.hInstance, myfile, index)
|
| In the above example MyReturnCode always = 0 and myfile and index are
| unchanged.
| I have tried setting index to 0,1, and the length of myfile to no avail.
| If anyone out there has gotten this api to work I sure would appreciate
| some help.
| Thanks.
| Raymond
|
| >
| > Help ! I can't make the ExtractAssociatedIcon API call work. I am
| > running on NT 4.0 with SP3. I am writing the code in VB6.0. I don't get
| > any errors it just doesn't do anything. Anyone have any ideas ?
| >
| > Thanks.
| > Raymond
| >
| > PS: ExtractIcon works fine for me so I don't know what the deal is with
| > ExtractAssociatedIcon....



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
Thanks for the response. Man I wished thats all it was. I only added the
padding after it didn't work and because Appleman's book said in the
comments for this api that lpIconPath should be at least MAX_PATH
long...

Just for grins I put it back and tried a test bitmap file with no
change. Are you running the below code on an NT machine or 9X ?
When this runs and works does your myfile string change to the exe file
name ?

Thanks.
Raymond

Quote:

> Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" _
>    Alias "ExtractAssociatedIconA" _
>   (ByVal hInst As Long, _
>    ByVal lpIconPath As String, _
>    lpiIcon As Long) As Long

> Private Declare Function DrawIcon Lib "user32" _
>   (ByVal hdc As Long, _
>    ByVal x As Long, _
>    ByVal Y As Long, _
>    ByVal hIcon As Long) As Long

> Private Declare Function DestroyIcon Lib "user32" _
>   (ByVal hIcon As Long) As Long

> Private Sub Command1_Click()

>    Dim index As Long
>    Dim hIcon As Long
>    Dim myfile  As String

>    index = 2
>    myfile = "C:\qsptr1.gif"

>    Picture1.Cls

>    hIcon = ExtractAssociatedIcon(App.hInstance, myfile, index)

>    Call DrawIcon(Picture1.hdc, 1, 1, hIcon)
>    Call DestroyIcon(hIcon)

> End Sub

> You do not need to pad the string with 0's when you pass a string .. only
> when you are padding a string for a returned value from the API.  You were
> requesting icons from a file named:

> c:\test.doc000000000000000000000000000000000000000 ... etc

> --
> Randy Birch, MVP Visual Basic

> http://www.mvps.org/vbnet/
> http://www.mvps.org/ccrp/

> Please correspond only using the newsgroups so all can benefit.



> | OK after reading my own message I can see I didn't provide anywhere near
> | enough information...
> |
> | index = 2
> | myfile = "c:\test.doc"+string(255,0)
> | MyReturnCode = ExtractAssociatedIcon(app.hInstance, myfile, index)
> |
> | In the above example MyReturnCode always = 0 and myfile and index are
> | unchanged.
> | I have tried setting index to 0,1, and the length of myfile to no avail.
> | If anyone out there has gotten this api to work I sure would appreciate
> | some help.
> | Thanks.
> | Raymond
> |

> | >
> | > Help ! I can't make the ExtractAssociatedIcon API call work. I am
> | > running on NT 4.0 with SP3. I am writing the code in VB6.0. I don't get
> | > any errors it just doesn't do anything. Anyone have any ideas ?
> | >
> | > Thanks.
> | > Raymond
> | >
> | > PS: ExtractIcon works fine for me so I don't know what the deal is with
> | > ExtractAssociatedIcon....



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
NT4 SP6a, VB6 SP3.  Copied and pasted that exact code into a new project,
and it worked. Make sure you are using my declares.

In rereading the MSDN on this call, I can see where it says "If the icon
handle is obtained from an executable file, the function stores the full
path and file name of that executable in the string pointed to by
lpIconPath." But no file tried thus far retrieved the exe name ... the
passed filename was always returned. Is that all you're after .. the
associated exe? If so, pass that same file to FindExecutable .. it returns
the full path to the associated app. .....
http://www.mvps.org/vbnet/code/system/findexecutable.htm

--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
My declare matches your exactly. I actually want the icon not the exe. I
am actually using findexecutable in another place in the code. Between
findexecutable and extracticon I almost have the same thing as
extractassociatedicon but I am worried that the index for the icon
associated may not always be 1 although everything I have seen so far is
1. It just bugs me that this api call doesn't work when all the others
do....
I have step through the code in debug mode to make sure all the varibles
are populated the way I think they should be so I'm farely certain I
don't have anything too stupid going on. Do you think that using an
index of 1 with extracticon against the exe returned by find executable
would be reliable in all cases ?

I really appreciate your thought and time on this.
Thanks.
Raymond

Quote:

> NT4 SP6a, VB6 SP3.  Copied and pasted that exact code into a new project,
> and it worked. Make sure you are using my declares.

> In rereading the MSDN on this call, I can see where it says "If the icon
> handle is obtained from an executable file, the function stores the full
> path and file name of that executable in the string pointed to by
> lpIconPath." But no file tried thus far retrieved the exe name ... the
> passed filename was always returned. Is that all you're after .. the
> associated exe? If so, pass that same file to FindExecutable .. it returns
> the full path to the associated app. .....
> http://www.mvps.org/vbnet/code/system/findexecutable.htm

> --
> Randy Birch, MVP Visual Basic

> http://www.mvps.org/vbnet/
> http://www.mvps.org/ccrp/

> Please correspond only using the newsgroups so all can benefit.



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
| index of 1 with ExtractIcon against the exe returned by find executable
| would be reliable in all cases ?

Icon positions start at 0, not 1.

Why not use the SHGetFileInfo API instead. It always returns the handle to
the icon that is displayed for the file type, regardless of the position of
the icon in the file. However, if the file type is not registered, it
returns the default Unknown icon. You can extract the code from
http://www.mvps.org/vbnet/code/icon/icon16simple.htm or
http://www.mvps.org/vbnet/code/icon/icon1632simple.htm

--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


| My declare matches your exactly. I actually want the icon not the exe. I
| am actually using findexecutable in another place in the code. Between
| findexecutable and extracticon I almost have the same thing as
| extractassociatedicon but I am worried that the index for the icon
| associated may not always be 1 although everything I have seen so far is
| 1. It just bugs me that this api call doesn't work when all the others
| do....
| I have step through the code in debug mode to make sure all the varibles
| are populated the way I think they should be so I'm farely certain I
| don't have anything too stupid going on. Do you think that using an
| index of 1 with extracticon against the exe returned by find executable
| would be reliable in all cases ?
|
| I really appreciate your thought and time on this.
| Thanks.
| Raymond
|
| >
| > NT4 SP6a, VB6 SP3.  Copied and pasted that exact code into a new
project,
| > and it worked. Make sure you are using my declares.
| >
| > In rereading the MSDN on this call, I can see where it says "If the icon
| > handle is obtained from an executable file, the function stores the full
| > path and file name of that executable in the string pointed to by
| > lpIconPath." But no file tried thus far retrieved the exe name ... the
| > passed filename was always returned. Is that all you're after .. the
| > associated exe? If so, pass that same file to FindExecutable .. it
returns
| > the full path to the associated app. .....
| > http://www.mvps.org/vbnet/code/system/findexecutable.htm
| >
| > --
| > Randy Birch, MVP Visual Basic
| >
| > http://www.mvps.org/vbnet/
| > http://www.mvps.org/ccrp/

| >
| > Please correspond only using the newsgroups so all can benefit.



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
I must not express myself very well because I keep having to clarify and
each time I do I see why you were asking your question. I know the icon
index starts at 0. The first icon seems to always be the icon for the
exe. The second icon seems to always be an icon that represents the
document which is what I want. I am unfamiliar with SHGetFileInfo. I
will go check it out. It sounds like it will fit the bill perfectly.
Thanks for your time and patience.

Raymond

Quote:

> | index of 1 with ExtractIcon against the exe returned by find executable
> | would be reliable in all cases ?

> Icon positions start at 0, not 1.

> Why not use the SHGetFileInfo API instead. It always returns the handle to
> the icon that is displayed for the file type, regardless of the position of
> the icon in the file. However, if the file type is not registered, it
> returns the default Unknown icon. You can extract the code from
> http://www.mvps.org/vbnet/code/icon/icon16simple.htm or
> http://www.mvps.org/vbnet/code/icon/icon1632simple.htm

> --
> Randy Birch, MVP Visual Basic

> http://www.mvps.org/vbnet/
> http://www.mvps.org/ccrp/

> Please correspond only using the newsgroups so all can benefit.



> | My declare matches your exactly. I actually want the icon not the exe. I
> | am actually using findexecutable in another place in the code. Between
> | findexecutable and extracticon I almost have the same thing as
> | extractassociatedicon but I am worried that the index for the icon
> | associated may not always be 1 although everything I have seen so far is
> | 1. It just bugs me that this api call doesn't work when all the others
> | do....
> | I have step through the code in debug mode to make sure all the varibles
> | are populated the way I think they should be so I'm farely certain I
> | don't have anything too stupid going on. Do you think that using an
> | index of 1 with extracticon against the exe returned by find executable
> | would be reliable in all cases ?
> |
> | I really appreciate your thought and time on this.
> | Thanks.
> | Raymond
> |

> | >
> | > NT4 SP6a, VB6 SP3.  Copied and pasted that exact code into a new
> project,
> | > and it worked. Make sure you are using my declares.
> | >
> | > In rereading the MSDN on this call, I can see where it says "If the icon
> | > handle is obtained from an executable file, the function stores the full
> | > path and file name of that executable in the string pointed to by
> | > lpIconPath." But no file tried thus far retrieved the exe name ... the
> | > passed filename was always returned. Is that all you're after .. the
> | > associated exe? If so, pass that same file to FindExecutable .. it
> returns
> | > the full path to the associated app. .....
> | > http://www.mvps.org/vbnet/code/system/findexecutable.htm
> | >
> | > --
> | > Randy Birch, MVP Visual Basic
> | >
> | > http://www.mvps.org/vbnet/
> | > http://www.mvps.org/ccrp/

> | >
> | > Please correspond only using the newsgroups so all can benefit.



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API

<snip>

Quote:
> http://www.mvps.org/vbnet/code/icon/icon1632simple.htm

<snip>

Hey I went and looked at this example and I got it to work perfectly for
what I am trying to do. I thought I would let you know that I had to
make a change to it to make it work though. I removed the SHGFI_EXETYPE
flag and added the SHGFI_ICON flag. I think it was the SHGFI_EXETYPE
flag that was the problem but I never went back to prove it. Originally
I kept getting a 1402 error from DrawIcon which is a invalid cursor type
error. I also had to change the code to use the hIcon element from the
structure instead of the returncode. I didn't look at the other example
you provided in the last email so it may be right....

Thank you very much. You have solved my problem and I am off and
running.

Raymond



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
Great. The exe flag alone would give a problem, unless it was OR'd with the
Icon flag. This API lets you selectively retrieve various bits of info from
a file, based on the flags set.

--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


|
|
| <snip>
| > http://www.mvps.org/vbnet/code/icon/icon1632simple.htm
| <snip>
|
| Hey I went and looked at this example and I got it to work perfectly for
| what I am trying to do. I thought I would let you know that I had to
| make a change to it to make it work though. I removed the SHGFI_EXETYPE
| flag and added the SHGFI_ICON flag. I think it was the SHGFI_EXETYPE
| flag that was the problem but I never went back to prove it. Originally
| I kept getting a 1402 error from DrawIcon which is a invalid cursor type
| error. I also had to change the code to use the hIcon element from the
| structure instead of the returncode. I didn't look at the other example
| you provided in the last email so it may be right....
|
|
| Thank you very much. You have solved my problem and I am off and
| running.
|
| Raymond



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
You might want to DL the demo code
http://www.mvps.org/vbnet/code/icon/extracticonadvlv.htm Although it uses
ExtractIcon and not ExtractAssociatedIcon, you can see what all the icons in
a given dll or exe are in one call, and determine for yourself whether the
question of icon index 1 being always viable is true.

--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


| I must not express myself very well because I keep having to clarify and
| each time I do I see why you were asking your question. I know the icon
| index starts at 0. The first icon seems to always be the icon for the
| exe. The second icon seems to always be an icon that represents the
| document which is what I want. I am unfamiliar with SHGetFileInfo. I
| will go check it out. It sounds like it will fit the bill perfectly.
| Thanks for your time and patience.



Wed, 18 Jun 1902 08:00:00 GMT  
 ExtractAssociatedIcon API
I already have working code that uses ExtractIcon and will pull all
icons out of exe's or dll's. The exe's or dll's that I have looked at
all seem to use the second icon for the associated file type but I
didn't know if that was a coincidence or some kind of standard. You know
I have solved my immediate problem but I still don't know why
ExtractAssociatedIcon didn't work....

Thanks again for your help.
Raymond

Quote:

> You might want to DL the demo code
> http://www.mvps.org/vbnet/code/icon/extracticonadvlv.htm Although it uses
> ExtractIcon and not ExtractAssociatedIcon, you can see what all the icons in
> a given dll or exe are in one call, and determine for yourself whether the
> question of icon index 1 being always viable is true.

> --
> Randy Birch, MVP Visual Basic

> http://www.mvps.org/vbnet/
> http://www.mvps.org/ccrp/

> Please correspond only using the newsgroups so all can benefit.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. ExtractAssociatedIcon API Help

2. ExtractAssociatedIcon API, help needed!!!

3. ExtractAssociatedIcon API call

4. ExtractAssociatedIcon API

5. ExtractAssociatedIcon API call

6. API: ExtractAssociatedIcon Error etc.

7. API: ExtractAssociatedIcon Error etc.

8. ExtractAssociatedIcon

9. Nobody knows how to use ExtractAssociatedIcon ??!!

10. how to use ExtractAssociatedIcons in VB5?

11. EXTRACTASSOCIATEDICON - Help required ..PLS

12. ExtractAssociatedIcon

 

 
Powered by phpBB® Forum Software