Forum > LCL

[SOLVED] ListView: use of SHGetFileInfoW crashes, only in plugin DLL

(1/2) > >>

d7_2_laz:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// fiFilePath is String, sfi is TSHFileInfoW// --> Leads to exception 'Range check error' from Notepad++   ret := SHGetFileInfoW(PWideChar(WideString(fiFilePath)), 0, sfi, SizeOf(sfi),           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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// --> No exception, but return value 0 (missing results)   ret := SHGetFileInfoW(PWideChar(fiFilePath), 0, sfi, SizeOf(sfi),          SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_ICON or SysIconImageSize or SHGFI_SYSICONINDEX or SHGFI_ATTRIBUTES);
Tried also this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var uFullName: UnicodeString;....   uFullName := UTF8Decode(fiFilePath);   ret := SHGetFileInfoW(PWideChar(uFullName), 0, sfi, SizeOf(sfi),          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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---     ret := SHGetFileInfoW(PWideChar(UTF8ToUTF16(fiFilePath)), 0, sfi, SizeOf(sfi),            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 ...

wp:
How is ret declared? In the win32 widget code of TShellTreeView, ret is a DWORD_PTR.

d7_2_laz:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---     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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---     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'?

wp:
Maybe the plugin library is compiled with range checking, and the normal application is not?

d7_2_laz:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version