Can't use Win32 SHELLSTATE structure!
Posted: Sat May 10, 2014 1:46 pm
Hi all,
I want to use the SHGetSetSettings Win32 function (see http://msdn.microsoft.com/en-us/library ... 85%29.aspx ), which allows for various interactions with the Windows desktop.
It needs a SHELLSTATE structure, which in almost 15 years of PureBasic Win32 coding is the weirdest, most f***ed-up thing I've ever seen!
It uses bitfields -- fields that are each 1 bit in size. It starts with 17 bits (yes, seventeen), followed by some 32-bit integers, followed by another bunch of bits. From my reading (see URLs in source), it seems these bitfields need to be padded out to 32 bits in C-style languages like PB, but no matter what I try, this crashes when trying to call SHGetSetSettings, with an invalid memory access/write error:
Has anyone ever used this function, or can anyone figure out HOW to use it with this bizarre structure?!
Thanks in advance for any help!
I want to use the SHGetSetSettings Win32 function (see http://msdn.microsoft.com/en-us/library ... 85%29.aspx ), which allows for various interactions with the Windows desktop.
It needs a SHELLSTATE structure, which in almost 15 years of PureBasic Win32 coding is the weirdest, most f***ed-up thing I've ever seen!
It uses bitfields -- fields that are each 1 bit in size. It starts with 17 bits (yes, seventeen), followed by some 32-bit integers, followed by another bunch of bits. From my reading (see URLs in source), it seems these bitfields need to be padded out to 32 bits in C-style languages like PB, but no matter what I try, this crashes when trying to call SHGetSetSettings, with an invalid memory access/write error:
Code: Select all
#SSF_HIDEICONS = $00004000
Structure SHELLSTATE
; Some references...
; http://msdn.microsoft.com/en-us/library/bb759788%28VS.85%29.aspx
; http://www.windows-tech.info/1/31087e8b743a89c2.php
; http://fossies.org/dox/wine-1.7.18/structSHELLSTATE.html
; http://social.msdn.microsoft.com/Forums/vstudio/en-US/c309f758-aa76-423c-9a58-d6d2b6694fe2/reading-from-shellstate-structure-modifying-explorer-settings-and-startmenu?forum=csharpgeneral
; ; 17 bits! WTF?!
;
; fShowAllObjects.bit0
; fShowExtensions.bit1
; fNoConfirmRecycle.bit2
; fShowSysFiles.bit3
; fShowCompColor.bit4
; fDoubleClickInWebView.bit5
; fDesktopHTML.bit6
; fWin95Classic.bit7
; fDontPrettyPath.bit8
; fShowAttribCol.bit9
; fMapNetDrvBtn.bit10
; fShowInfoTip.bit11
; fHideIcons.bit12
; fWebView.bit13
; fFilter.bit14
; fShowSuperHidden.bit15
; fNoNetCrawling.bit16
; Some references suggest this should be padded out to 32 bits...
bits.l
; ^^^ 17 bits + 15 padding = 32 bits...
; 6 x 32-bit integer?
dwWin95Unused.l
uWin95Unused.l
lParamSort.l
iSortDirection.l
version.l
uNotUsed.l
; ^^^ Fair enough... I guess...
; 7 bits...
; fSepProcess.bit0
; fStartPanelOn.bit1
; fShowStartPage.bit2
; fAutoCheckSelect.bit3
; fIconsOnly.bit4
; fShowTypeOverlay.bit5
; fShowStatusBar.bit6
; fSpareFlags.bit0-8 ; 9 bits... holy sh
; Another one that should be padded to 32 bits... ?
bits2.l
; ^^^ 7 bits + 9 padding = 16 bits...
EndStructure
Debug SizeOf (SHELLSTATE)
lib = OpenLibrary (#PB_Any, "shell32.dll")
If lib
; SHGetSetSettings: http://msdn.microsoft.com/en-us/library/bb762200%28VS.85%29.aspx
*SHGetSetSettings = GetFunction (lib, "SHGetSetSettings")
If *SHGetSetSettings
*lpss.SHELLSTATE
If CallFunctionFast (lib, *SHGetSetSettings, *lpss, #SSF_HIDEICONS, #False) ; False means READ the shell settings!
Debug "OK"
Else
Debug GetLastError_ ()
EndIf
Else
Debug "Nope"
EndIf
CloseLibrary (lib)
EndIf
;SHGetSetGettings ()
Thanks in advance for any help!