Picture.FromHandle retourne erreur

I have a problem on this line

pict = Picture.FromHandle(cgImagePtr, Picture.HandleTypes.MacCGImage)

Can you help me, thank you

’ Public Function GetMacAppIcon(f As FolderItem) As Picture
#If TargetMacOS Then
If f = Nil Or Not f.Exists Then Return Nil

// 1. Déclarations des classes Cocoa nécessaires
Soft Declare Function NSClassFromString Lib “Foundation” (aClassName As CFStringRef) As Ptr
Soft Declare Function sharedWorkspace Lib “AppKit” Selector “sharedWorkspace” (classPtr As Ptr) As Ptr
Soft Declare Function iconForFile Lib “AppKit” Selector “iconForFile:” (workspacePtr As Ptr, fullPath As CFStringRef) As Ptr
Soft Declare Function CGImage Lib “AppKit” Selector “CGImageForProposedRect:context:hints:” (nsImagePtr As Ptr, rect As Ptr, context As Ptr, hints As Ptr) As Ptr

// 2. Récupération des pointeurs de classe
Dim nsWorkspaceClass As Ptr = NSClassFromString(“NSWorkspace”)
Dim workspace As Ptr = sharedWorkspace(nsWorkspaceClass)

// 3. Obtenir l’objet NSImage de l’icône via le chemin du fichier
Dim nsImageAsIcon As Ptr = iconForFile(workspace, f.NativePath)

If nsImageAsIcon <> Nil Then
// 4. Convertir l’NSImage en CGImage (requis pour créer une image Xojo)
// On passe Nil aux paramètres pour que macOS choisisse la meilleure résolution
Dim cgImagePtr As Ptr = CGImage(nsImageAsIcon, Nil, Nil, Nil)

If cgImagePtr <> Nil Then
  // 5. Créer et retourner l'image Xojo à partir du CGImage
  Var pict As Picture
  pict = Picture.FromHandle(cgImagePtr, Picture.HandleTypes.MacCGImage)
  Return pict
End If

End If

#EndIf

// Retourne Nil si on n’est pas sur Mac ou si une étape a échoué
Return Nil

Exception err
Break