Recent

Author Topic: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL  (Read 4936 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
That's first as an info:
I noticed crashes (exception 'Range check error') when running a code part within a (virtual) ListView's OnGetData - but not when applied for a Treeview or somewhere else. Only in listview's OnGetData, and only when this is executed withini a Notepad++ plugin DLL.

For the ShellListView i saw such a crash just in the moment when i assign it to a ShellTreeView - resp.: when providing aa "Path" for it.

Example: this one normally causes no problems - only within the given scenario:

Code: Pascal  [Select][+][-]
  1. // fiFilePath is String, sfi is TSHFileInfoW
  2. // --> Leads to exception 'Range check error' from Notepad++
  3.    ret := SHGetFileInfoW(PWideChar(WideString(fiFilePath)), 0, sfi, SizeOf(sfi),
  4.            SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_ICON or SysIconImageSize or SHGFI_SYSICONINDEX or SHGFI_ATTRIBUTES);

This one does Not cause a Range check exception, but "ret" is 0, and so there won't be usable results:
Code: Pascal  [Select][+][-]
  1. // --> No exception, but return value 0 (missing results)
  2.    ret := SHGetFileInfoW(PWideChar(fiFilePath), 0, sfi, SizeOf(sfi),
  3.           SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_ICON or SysIconImageSize or SHGFI_SYSICONINDEX or SHGFI_ATTRIBUTES);

Tried also this:
Code: Pascal  [Select][+][-]
  1. var uFullName: UnicodeString;
  2. ....
  3.    uFullName := UTF8Decode(fiFilePath);
  4.    ret := SHGetFileInfoW(PWideChar(uFullName), 0, sfi, SizeOf(sfi),
  5.           SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_ICON or SysIconImageSize or SHGFI_SYSICONINDEX or SHGFI_ATTRIBUTES);

-> Range check exception ...

Edit: same also with:
Code: Pascal  [Select][+][-]
  1.      ret := SHGetFileInfoW(PWideChar(UTF8ToUTF16(fiFilePath)), 0, sfi, SizeOf(sfi),
  2.             SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_ICON or SysIconImageSize or SHGFI_SYSICONINDEX or SHGFI_ATTRIBUTES);

Why this happens only in a plugin DLL, and solely in ListView's context, appears to be a mystery ...
« Last Edit: December 22, 2024, 06:25:09 pm by d7_2_laz »
Lazarus 3.8  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 12575
How is ret declared? In the win32 widget code of TShellTreeView, ret is a DWORD_PTR.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
Yep wp (thanks for your reply!) ... just 10 minutes ago i'd realized that.   :o
So i can give an update:

Step forwards after a couple of trials with doing:

1. defining return value ("ret") as DWord_Ptr (which is correct!) does remove the crash. Before it was Cardinal (which had never played a role before resp. in the stand-alone exe, but now crashes within the plugin!)

2. I inspect the castings now:
 a)
Code: Pascal  [Select][+][-]
  1.      ret := SHGetFileInfoW(PWideChar(WideString(fiFilePath)), 0, sfi, SizeOf(sfi),  ...
.
--> "ret" is ok now, sfi.hIcon is > 0, but i don't see any icon (*)

 b)
Code: Pascal  [Select][+][-]
  1.      ret := SHGetFileInfoW(Pointer(WideString(fiFilePath)), 0, sfi, SizeOf(sfi),    ....

--> "ret" is ok now, sfi.hIcon is > 0, and i can see an icon ... at least if i click onto the item icon's area, else not   (*)

(*) This is probably by the dark theme painting reps. my uplaying code, and not a chapter for here. I'll dig elsewhere.
Btw.: actually, in the NPP's default (light) theme, i don't see the listview icons painted at all yet. Need to dig.
What i can say: they are retrieved and i can SaveToFile them for test  ....
But the icons i retrieved via "PWideChar(WideString(" differ physically from those retrieved via "Pointer(WideString(". Strange crawling ...

wp, do you have any idea why it might - within a plugin -  such a sensible reaction on the type of ret if it is not DWord_Ptr, differently to a 'normal app'?
Lazarus 3.8  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 12575
Maybe the plugin library is compiled with range checking, and the normal application is not?

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
That i had already aligned before, the settings don't differ.

But anyhow, it's more theoretical ...  I applied the correct type (DWord_Ptr) to both plugin dll and exe, and for the plugin the crash went away.

Lazarus 3.8  FPC 3.2.2 Win10 64bit

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
Re: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL
« Reply #5 on: December 25, 2024, 11:34:23 am »
Just for interest i looked a bit if the crash with ShellListView is caused by something similar.
Instead of many words i attach a screenshot that shows up the context.

It's of course again about the icon retrieval (so that crash won't not appear when setting the property 'UseBuiltinIcons' to false).

Code: Pascal  [Select][+][-]
  1. class function TWin32WSCustomShellListView.GetBuiltInImageIndex(
  2. ....
  3.   if ListView_GetImageList(ListHandle, lvsil) = 0 then
  4.   begin
  5.     SetWindowLongPtrW(listHandle, GWL_STYLE,
  6.       GetWindowLong(listHandle, GWL_STYLE) or LVS_SHAREIMAGELISTS);
  7.  
  8.     // --> Crash now triggered by:
  9.     ListView_SetImageList(listHandle, sysImageHandle, lvsil);
  10.   end;

Just for info (i'll not go more indepth here).
Lazarus 3.8  FPC 3.2.2 Win10 64bit

jamie

  • Hero Member
  • *****
  • Posts: 6798
Re: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL
« Reply #6 on: December 25, 2024, 02:50:05 pm »
how about using "GetWindowLongPtr" makes no sense using only half correct code.
The only true wisdom is knowing you know nothing

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
Re: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL
« Reply #7 on: December 25, 2024, 03:07:57 pm »
Good point jamie!
But ... still SIGSEV's

Edit: but obviously it's something different like the original topic for the (custom) listview and would need some dedicated investigation.
« Last Edit: December 25, 2024, 03:19:53 pm by d7_2_laz »
Lazarus 3.8  FPC 3.2.2 Win10 64bit

jamie

  • Hero Member
  • *****
  • Posts: 6798
Re: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL
« Reply #8 on: December 26, 2024, 01:49:11 am »
are you trying to run this in a different thread ?

Jamie
The only true wisdom is knowing you know nothing

d7_2_laz

  • Hero Member
  • *****
  • Posts: 605
Re: [SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL
« Reply #9 on: December 26, 2024, 01:22:27 pm »
No jamie, no threading at all at least not in this small demo for a Notepad++ plugin DLL
(where i don't know what NPP itself is doing behind the scenes).
Lazarus 3.8  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018