ExtractAssociatedIcon 
Author Message
 ExtractAssociatedIcon

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



Wed, 28 Dec 2005 22:44:41 GMT  
 ExtractAssociatedIcon

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/



Wed, 28 Dec 2005 23:10:09 GMT  
 ExtractAssociatedIcon
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



Thu, 29 Dec 2005 01:26:01 GMT  
 ExtractAssociatedIcon
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/



Thu, 29 Dec 2005 01:36:34 GMT  
 ExtractAssociatedIcon
Works fine now, thanks.

Chris



Thu, 29 Dec 2005 03:34:59 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ExtractAssociatedIcon API Help

2. ExtractAssociatedIcon API

3. ExtractAssociatedIcon

4. ExtractAssociatedIcon API, help needed!!!

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

6. how to use ExtractAssociatedIcons in VB5?

7. ExtractAssociatedIcon API call

8. EXTRACTASSOCIATEDICON - Help required ..PLS

9. ExtractAssociatedIcon

10. ExtractAssociatedIcon

11. ExtractAssociatedIcon

12. ExtractAssociatedIcon like Windows Explorer

 

 
Powered by phpBB® Forum Software