ExtractAssociatedIcon

ExtractAssociatedIcon

Post by Chri » Sun, 13 Jul 2003 23:44:41



Hi

I've just started using API calls. I used ExtractIcon
(copied straight out of a book) and got the expected
result. Then I tried to use ExtractAssociatedIcon using
the following code.

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

Sub hIconToPicture()

Dim strIconFilePath As String
Dim hIcon As Long
Dim intLpiIcon As Integer

strIconFilePath = "C:\Program Files\Microsoft
Office\Office10\excel.exe"
intLpiIcon = 0

hIcon = MyExtractAssociatedIcon(0, strIconFilePath,
intLpiIcon)

Form1.Picture1.Picture = GPicTool.IconToPicture(hIcon)

End Sub

And VB returned the following error:

'453' Can't find DLL entry point ExtractAssociatedIcon in
shell32.dll

Is this because of syntax, logic .?

Thanks

 
 
 

ExtractAssociatedIcon

Post by Mike D Sutto » Mon, 14 Jul 2003 00:10:09


Quote:> I've just started using API calls. I used ExtractIcon
> (copied straight out of a book) and got the expected
> result. Then I tried to use ExtractAssociatedIcon using
> the following code.
<code snipped>
> Is this because of syntax, logic .?

The problem here is that there is no function called ExtractAssociatedIcon()
in the .DLL file you're referencing to, instead there's two functions called
ExtractAssociatedIconA() and ExtractAssociatedIconW() requiring ASCII and
Unicode (Wide) strings respectively.  In VB it's easiest to use the ASCII
version of the function even though VB's string are stored at unicode
internally, since it handles the ASCII <-> Unicode conversion behind the
scenes for us.
Simply declare your API call with an alias of "ExtractAssociatedIconA" and
it should be able to recognise the function:

'***
Private Declare Function MyExtractAssociatedIcon Lib "shell32.dll" _
    Alias "ExtractAssociateIconA" (ByVal hInst As Long, _
    ByVal lpIconPath As String, lpiIcon As Long) As Long
'***

Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -

WWW: Http://www.mvps.org/EDais/

 
 
 

ExtractAssociatedIcon

Post by Chri » Mon, 14 Jul 2003 02:26:01


Thanks Mike

I've changed function as described but now VB 'encounters
problem and needs to close' - urm any other ideas.

Program is currently:-

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

Sub hIconToPicture()

Dim strIconFilePath As String
Dim hIcon As Long
Dim intLpiIcon As Long

strIconFilePath = "C:\Program Files\Microsoft
Office\Office10\excel.exe"
intLpiIcon = 0
hIcon = MyExtractAssociatedIcon(0, strIconFilePath,
intLpiIcon)

Form1.Picture1.Picture = GPicTool.IconToPicture(hIcon)

End Sub

 
 
 

ExtractAssociatedIcon

Post by Mike D Sutto » Mon, 14 Jul 2003 02:36:34


Quote:> I've changed function as described but now VB 'encounters
> problem and needs to close' - urm any other ideas.

<code snipped>

Use the declaration in my last post, the last parameter should be declared
ByRef - You want to pass a pointer rather than a value, as such the API is
trying to read from memory address 0x0..

<quote src=
"http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterf...
sources/icons/iconreference/iconfunctions/extractassociatedicon.asp" >
lpiIcon
[in] Pointer to a WORD that specifies the index of the icon whose handle is
to be obtained. If the icon handle is obtained from an executable file, the
function stores the icon's identifier in the WORD pointed to by lpiIcon.
</quote>

Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -

WWW: Http://www.mvps.org/EDais/

 
 
 

ExtractAssociatedIcon

Post by Chri » Mon, 14 Jul 2003 04:34:59


Works fine now, thanks.

Chris

 
 
 

1. ExtractAssociatedIcon into ImageList?

Hi,

I am building an "Explorer" type view of files using the Listview control.
I would like it to display not only the file's name, etc, but also its
associated icon.  To use icons in the Listview control they must come from
an ImageList control. I can extract the associated icon and display it in a
PictureBox control.  My trouble is that when I try to add the picture to an
ImageList control I get an "Out of memory" error.  I suspect that perhaps my
original picture extracted from the associated icon is somehow corrupt but
that the PictureBox control overcomes it well enough to display the image,
however the ImageList control can't overcome it and fails.    Included below
are the function I am using to extract the associated icon and the notation
I am using in my attempt to add it to the ImageList.  If anyone has any
ideas about what I could be doing wrong, or should be doing, or ???

Any and all help truly appreciated.

Thanks, Jon Anderson

<snip>
Set Picture1.Picture = GetIconForFile("c:\foo.html")   ' works - IE icon
displays
Set o = ImageList1.ListImages.Add(,,GetIconForFile("c:\foo.html"))   '
fails - Out of memory
Set o = ImageList1.ListImages.Add(,,Picture1.Picture)   ' also fails - Out
of memory
<snip>

Public Function GetIconForFile(ByVal sFileName As String) As IPictureDisp

    Dim hIcon As Long
    Dim Pic As PicBmp
    Dim IPic As IPicture
    Dim IID_IDispatch As GUID

    hIcon = ExtractAssociatedIcon(App.hInstance, sFileName, 2)
    If (hIcon > 0) Then
        ' Fill in with IDispatch Interface ID.
        With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        ' Fill Pic with necessary parts.
        With Pic
            .Size = Len(Pic) ' Length of structure.
            .Type = vbPicTypeIcon ' Type of Picture (bitmap).
            .hBmp = hIcon ' Handle to bitmap.
        End With

        ' Create Picture object.
        Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)

        ' Return the new Picture object.
        Set GetIconForFile = IPic

        Call DestroyIcon(hIcon)
    End If
End Function

2. OpenGL acceleration under Windows 95?

3. ExtractAssociatedIcon and ListView

4. Problem: GDI-Ressources and Metafiles

5. API: ExtractAssociatedIcon Error etc.

6. Mac Modellers

7. ExtractAssociatedIcon

8. Sterio FLI Plugin

9. ExtractAssociatedIcon() to picture object?

10. ExtractAssociatedIcon

11. Something Like ExtractAssociatedIcon

12. ExtractAssociatedIcon