Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Picicon auslesen mit Office 64

Forumthread: Picicon auslesen mit Office 64

Picicon auslesen mit Office 64
15.04.2024 11:55:15
marspoki2
Hallo,

ich habe ein kleines Problem. Ich habe eine Tabelle mit der ich die Programicons auslesen kann. Mitt office 32 bit hat das funktioniert. Jetzt wurde auf 64 bit umgestellt und ich bekommen das Icon nicht geladen.

Hier mal die Datei: https://www.herber.de/bbs/user/168732.xlsm

der Excel 32bit code war:



Option Explicit

Private Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _
ByRef pDicDesc As IconType, _
ByRef riid As CLSIdType, _
ByVal fown As Long, _
ByRef lpUnk As Object) As Long
Private Declare Function SHGetFileInfoA Lib "shell32.dll" ( _
ByVal pszPath As String, _
ByVal dwFileAttributes As Long, _
ByRef psfi As ShellFileInfoType, _
ByVal cbFileInfo As Long, _
ByVal uFlags As Long) As Long

Private Const ICON_BIG As Long = &H100&
Private Const ICON_SMALL As Long = &H101&
Private Const MAX_PATH As Long = 260&
Private Const vbPicTypeIcon As Long = 3&

Private Type IconType
cbSize As Long
picType As Long
hIcon As Long
End Type

Private Type CLSIdType
id(16) As Byte
End Type

Private Type ShellFileInfoType
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * MAX_PATH
szTypeName As String * 80
End Type


Private Function LoadIcon(ByVal pvstrFile As String) As IPictureDisp
Dim objUnknown As IUnknown
Dim udtIcon As IconType
Dim udtCLSID As CLSIdType
Dim udtShellInfo As ShellFileInfoType
Call SHGetFileInfoA(pvstrFile, 0, udtShellInfo, Len(udtShellInfo), ICON_BIG)
udtIcon.cbSize = Len(udtIcon)
udtIcon.picType = vbPicTypeIcon
udtIcon.hIcon = udtShellInfo.hIcon
udtCLSID.id(8) = &HC0
udtCLSID.id(15) = &H46
Call OleCreatePictureIndirect(udtIcon, udtCLSID, 1, objUnknown)
Set LoadIcon = objUnknown
Set objUnknown = Nothing
End Function





'PicIcon laden

Sub Picon_laden()

UserForm1.Controls("Image1").Picture = LoadIcon(CStr("C:\Windows\notepad.exe"))


End Sub





hat jemand eine Idee wie ich das Icon mit 64 bit wieder in das Userform laden kann?

Vielen Dank und viele Grüße
Sebastian
Anzeige

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Picicon auslesen mit Office 64
15.04.2024 12:15:55
Onur
Mach aus jedem
Declare Function

ein
Declare PtrSafe Function
AW: Picicon auslesen mit Office 64
15.04.2024 13:01:48
volti
Hallo marspoki2,

das würde mich sehr wundern, wenn die Ergänzung des PtrSafe in den Declares Dein Problem lösen würde.

Falls es weiterhin nicht funktioniert:
Es müssen auch alle Pointer (Handle) auf LongPtr angepasst werden und ggf. weitere Strukturen im Code angepasst werden.

Hier mal (m)eine (ungetestete) Version für 64-Bit. Ich habe Deinen Code weitestgehend beigehalten, bei mir sieht es meist leicht anders aus.
Teste es einfach mal:

Code:


Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _ ByRef pDicDesc As IconType, ByRef riid As CLSIdType, _ ByVal fown As LongPtr, ByRef lpUnk As Object) As Long Private Declare PtrSafe Function SHGetFileInfoA Lib "Shell32.dll" ( _ ByVal pszPath As String, ByVal dwFileAttributes As Long, _ ByRef psfi As ShellFileInfoType, ByVal cbFileInfo As Long, _ ByVal uFlags As Long) As LongPtr Private Const ICON_BIG As Long = &H100& Private Const ICON_SMALL As Long = &H101& Private Const MAX_PATH As Long = 260& Private Const vbPicTypeIcon As Long = 3& Private Type IconType cbSize As Long picType As Long hIcon As LongPtr End Type Private Type CLSIdType id(16) As Byte End Type Private Type ShellFileInfoType hIcon As LongPtr iIcon As Long dwAttributes As Long szDisplayName(0 To MAX_PATH - 1) As Byte szTypeName(0 To 79) As Byte End Type Private Function LoadIcon(ByVal pvstrFile As String) As IPictureDisp Dim objUnknown As IUnknown Dim udtIcon As IconType Dim udtCLSID As CLSIdType Dim udtShellInfo As ShellFileInfoType Call SHGetFileInfoA(pvstrFile, 0, udtShellInfo, LenB(udtShellInfo), ICON_BIG) udtIcon.cbSize = LenB(udtIcon) udtIcon.picType = vbPicTypeIcon udtIcon.hIcon = udtShellInfo.hIcon udtCLSID.id(8) = &HC0 udtCLSID.id(15) = &H46 Call OleCreatePictureIndirect(udtIcon, udtCLSID, 1, objUnknown) Set LoadIcon = objUnknown Set objUnknown = Nothing End Function

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz
Anzeige
AW: Picicon auslesen mit Office 64
15.04.2024 12:17:45
marspoki2
Oh man du hast recht - das hatte ich schon aber dafür war es wohl ein falscher DIM :-(

Danke für deine Hilfe.

Alles ist OK
Gerne !
15.04.2024 12:19:13
Onur
;

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Entdecke mehr
Finde genau, was du suchst

Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

Suche nach den besten Antworten
Unsere beliebtesten Threads

Entdecke unsere meistgeklickten Beiträge in der Google Suche

Top 100 Threads jetzt ansehen
Anzeige