You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First some background, as this is probably not very common use case.
I'm writing Namespace extension for windows explorer. As part of it I have own implementation for IShellFolder. Implementation of GetDisplayNameOf() method returns STRRET structure.
I'm replacing some of our native structure declarations with one's provided by Vanara.PInvoke.* libraries and faced issue when I've attempted to replace our declaration of STRRET with one, declared in Vanara.PInvoke.Shell32.STRRET.
Did some investigation and it looks like the issue is caused by the wrong layout of the Vanara structure when it is created in x64 process (in my case inside explorer.exe)
(it is rather simple because I needed only pOleStr member of union for my needs)
Vanara has more generic declaration with all members declared with explicit offset (simplified, as I'm focusing only on layout)
[StructLayout(LayoutKind.Explicit, Size =264)]publicstructSTRRET{[FieldOffset(0)]publicSTRRET_TYPEuType;[FieldOffset(4)]publicStrPtrUnipOleStr;[FieldOffset(4)]publicuintuOffset;// Offset into SHITEMID[FieldOffset(4)]publicStrPtrAnsicStr;}
When I've tried to replace my structure with Vanara - shell stopped rendering display names of objects in my NSE. Once I switch to my structure everything works fine again.
I've written a simple code to check the layout of structures and it appears that in x64 process, in my structure actual offset of pOleStr field is 8, not 4:
(you need to remove Prefer32 check mark in console project build properties)
So I have to stick with our in-house declaration of STRRET structure for the time been. And I propose to eventually fix the declaration of this structure in Vanara.Shell32 library to properly support x64 processes
One possible way to resolve this in Vanara project and support all members of union is to implement union as a substructure, to avoid LayoutKind.Explicit on STRRET. Something like below:
[StructLayout(LayoutKind.Sequential)]publicstructSTRRET2{publicSTRRET_TYPEuType;publicSTRRET_UNIONunion;}[StructLayout(LayoutKind.Explicit, Size =260)]publicstructSTRRET_UNION{[FieldOffset(0)]publicIntPtrpOleStr;[FieldOffset(0)]publicuintuOffset;// Offset into SHITEMID[FieldOffset(0)]publicIntPtrcStr;}
Thanks for great set of libraries, and that you keep evolving! Hope this would help to make them even better.
The text was updated successfully, but these errors were encountered:
First some background, as this is probably not very common use case.
I'm writing Namespace extension for windows explorer. As part of it I have own implementation for IShellFolder. Implementation of GetDisplayNameOf() method returns STRRET structure.
I'm replacing some of our native structure declarations with one's provided by Vanara.PInvoke.* libraries and faced issue when I've attempted to replace our declaration of STRRET with one, declared in Vanara.PInvoke.Shell32.STRRET.
Did some investigation and it looks like the issue is caused by the wrong layout of the Vanara structure when it is created in x64 process (in my case inside explorer.exe)
I have this structure declared as
(it is rather simple because I needed only pOleStr member of union for my needs)
Vanara has more generic declaration with all members declared with explicit offset (simplified, as I'm focusing only on layout)
When I've tried to replace my structure with Vanara - shell stopped rendering display names of objects in my NSE. Once I switch to my structure everything works fine again.
I've written a simple code to check the layout of structures and it appears that in x64 process, in my structure actual offset of pOleStr field is 8, not 4:
(you need to remove Prefer32 check mark in console project build properties)
Results:
So I have to stick with our in-house declaration of STRRET structure for the time been. And I propose to eventually fix the declaration of this structure in Vanara.Shell32 library to properly support x64 processes
One possible way to resolve this in Vanara project and support all members of union is to implement union as a substructure, to avoid LayoutKind.Explicit on STRRET. Something like below:
Thanks for great set of libraries, and that you keep evolving! Hope this would help to make them even better.
The text was updated successfully, but these errors were encountered: