You could make CopyMemory 64bit-friendly by changing the "Length" parameter to "LenB(LongPtr)" but yeah, "Set" works the same provided you change the variant type to "VT_STREAM" afterwards.
Most compact version yet:
Code:Private Function WriteCover(sJPG As String, sMP3 As String, Optional sTitle As String) As Long Dim vpr As Variant, si2 As IShellItem2, pps As IPropertyStore Set vpr = SHCreateStreamOnFile(sJPG, STGM_READ) If Not IsEmpty(vpr) Then CopyMemory vpr, VT_STREAM, 2 If SHCreateItemFromParsingName(StrPtr(sMP3), Nothing, IID_IShellItem2, si2) = S_OK Then si2.GetPropertyStore GPS_OPENSLOWITEM Or GPS_READWRITE, IID_IPropertyStore, pps If Not pps Is Nothing Then If pps.SetValue(PKEY_ThumbnailStream, vpr) = S_OK Then If Len(sTitle) Then pps.SetValue PKEY_Music_AlbumTitle, CVar(sTitle) pps.Commit End If End If End If WriteCover = Err.LastHResult End Function




Reply With Quote
