code_junkie

Extract Icon from Windows .lnk (shortcut) file

Nov 12th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Path2Link := 'C:StuffTBear S Saver.lnk';
  2. SHGetFileInfo(PChar(Path2Link), 0, ShInfo1, SizeOf(TSHFILEINFO),
  3. SHGFI_ICON);
  4. // this ShInfo1.hIcon will have the Icon Handle for the Link Icon with
  5. // the small ShortCut arrow added}
  6.  
  7. [DllImport("shell32.dll")]
  8. public static extern IntPtr SHGetFileInfo(
  9. string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi,
  10. uint cbSizeFileInfo, uint uFlags);
  11.  
  12. Func _ShellGetAssocIcon(Const $szFile,Const $IconFlags = 0)
  13. Local $tFileInfo = DllStructCreate($tagSHFILEINFO)
  14. If @error Then
  15. Return SetError(1,@extended,0)
  16. EndIf
  17.  
  18. Local $Ret = DllCall("shell32.dll","int","SHGetFileInfo","str",$szFile,"dword",0, _
  19. "ptr",DllStructGetPtr($tFileInfo),"uint",DllStructGetSize($tFileInfo),"uint",BitOr($SHGFI_ICON,$IconFlags))
  20. MsgBox(0,0,@error)
  21. Return DllStructGetData($tFileInfo,"hIcon")
  22. EndFunc
Add Comment
Please, Sign In to add comment