Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:30:40+00:00 2026-06-14T22:30:40+00:00

Background: I’m trying to add some UAC shield icons to a few menu options

  • 0

Background: I’m trying to add some UAC shield icons to a few menu options in my wxPython based Python application. Buttons I’ve had no problem, as I can just send the BCM_SETSHIELD message to the buttons and Windows handles the rest.

In the link MSDN article here, it describes calling SHGetStockIconInfo to get the Handle or location for the shield icon. I’m trying to call it via Python using this code:

from ctypes import *

class SHSTOCKICONINFO(Structure):
    _fields_ = [('cbSize',c_ulong),
                ('hIcon',c_void_p),
                ('iSysImageIndex',c_int),
                ('iIcon',c_int),
                ('szPath',c_wchar_p)]

_SHGetStockIconInfo = windll.shell32.SHGetStockIconInfo
_SHGetStockIconInfo.argtypes = [c_uint,c_uint,POINTER(SHSTOCKICONINFO)]
_SHGetStockIconInfo.restype = c_int

# Values copied from shellapi.h
SIID_SHIELD = 77

SHGSI_ICONLOCATION = 0
SHGSI_ICON = 0x100
SHGSI_SMALLICON = 0x1
SHGSI_LARGEICON = 0

def GetIconLocation(id,flags=SHGSI_LARGEICON):
    # Clear _ICON bit and set _ICONLOCATION bit
    flags = ~(~flags|SHGSI_ICON)|SHGSI_ICONLOCATION
    info = SHSTOCKICONINFO()
    info.cbSize = sizeof(SHSTOCKICONINFO)
    result = _SHGetStockIconInfo(id,flags,byref(info)):
    if result != 0:
        raise Exception(result)
    return (info.szPath,info.iIcon)

Now whenever I call it, I get a return result from SHGetStockIconInfo of 0x80070057 (E_INVALIDARG – One or more arguments are not valid).

Can anyone help figure out what’s going wrong here? Or maybe point me to an easier way to get at this icon resource?

Edit: The problem was in my SHSTOCKICONINFO definition, see below. My example above now works correctly with the corrections from below.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:30:42+00:00Added an answer on June 14, 2026 at 10:30 pm

    The final field of the structure is declared incorrectly. Your code declared szPath to be a pointer to null-terminated array. But in fact it should be:

    ('szPath', c_wchar*MAX_PATH)
    

    Take a look at the C++ declaration for that field:

    WCHAR szPath[MAX_PATH];
    

    That’s an inline array of MAX_PATH wide characters. You can get hold of MAX_PATH like this:

    from ctypes.wintypes import MAX_PATH
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background The main application where I work is based heavily on the MUMPS-esque Caché
BACKGROUND: I made an IPhone socket application based on UDP. It works as a
Background: Some time ago, I built a system for recording and categorizing application crashes
Background : I have a .Net 3.5 WPF Prism-based application running on Windows XP
Background: I am trying to add data to a SQL DB with C#. I
Background: We're building an application that allows our customers to supply data in a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background: I have an application with an alternate entry point. It listenes for SMS
Background info I am trying to upgrade a custom CMS to support the HTML5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.