Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In which scenario can SHAppBarMessage give win32 exception.


I am having issue with SHAppBarMessage, I am trying to get the TaskBar Position but the code is throwing win32 error.
C#
public static .APPBARDATA GetSHAppBarMessage() 
{ 
    var data = new APPBARDATA { hWnd = IntPtr.Zero }; 
    data.cbSize = Marshal.SizeOf(data); 

    var result = SHAppBarMessage(ABM_GETTASKBARPOS, ref data); 
    if (result == IntPtr.Zero) Win32.ThrowIfWin32Error(); 
    
    return data; 
}


What I have tried:

Tried the same app in different machine the issue is observed in some machine but not always.
Posted
Updated 14-Jul-21 22:07pm
v2

1 solution

This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. Links to those documents are given in the See Also section.
Returns TRUE if successful; otherwise, FALSE.
The documentation doesn't provide any useful information about why the call might fail.

According to this SO answer[^], an older version of the documentation said that you have to pass the hWnd of the Shell_TrayWnd window as well as the cbSize; maybe older versions of Windows required that?

But since you haven't told us what error you're getting, we can only guess at this point.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900