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 8670447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:42:35+00:00 2026-06-12T18:42:35+00:00

I’m working with Python and trying to talk to this simple USB device using

  • 0

I’m working with Python and trying to talk to this simple USB device using WinUSB (from Microsoft). I’m having a problem since in order to find the device, calling the setupAPI function SetupDiEnumDeviceInterfaces takes a struct object, which I defined as a class:

class _SP_DEVINFO_DATA:
    def __init__(self, ClassGUID, DevInst = ""):        
        '''flags = SPINT_DEFAULT, SPINT_REMOVED, or SPINT_ACTIVE'''
        self._ClassGUID = None
        self._DevInst = None
        self._Reserved = None
        self._cbSize = None

    ###Getters:
    def getClassGUID(self):
        return self._ClassGUID
    def getDevInst(self):
        return self._DevInst
    def getReserved(self):
        return self._Reserved
    def getcbSize(self):
        return self._cbSize

    ###Setters:
    def setClassGUID(self, value):
        self._ClassGUID = value
    def setDevInst(self, value):
        self._DevInst = value
    def setReserved(self, value):
        self._Reserved = value
    def setcbSize(self):
        self._cbSize = sys.getsizeinfo(self)       

    ClassGUID = property(getClassGUID, setClassGUID, None, "Class GUID")
    DevInst = property(getDevInst, setDevInst, None, "Device Instance")
    Reserved = property(getReserved, setReserved, None, "RESERVED: DO NOT USE")
    cbSize = property(getcbSize, setcbSize, None, "CB Size. Set automatically")

I tried using the property because it gave me the error :

<type 'exceptions.TypeError'>: Don't know how to convert parameter

otherwise, and I’d read that defining parameters like this would resolve the problem, but it doesn’t, and I’m not certain what to do here.

I want to use WinUSB because I only need to read from the device and write to the device, and that’s it, and WinUSB seems to have what I need, but until I can get past this problem, I’m kind of stuck

Any suggestions? How do I pass a class object to a DLL function loaded with ctypes.windll.LoadLibrary(DLL)?

And if there’s an easier way to do this, I’m all for that too.

Thanks.

  • 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-12T18:42:37+00:00Added an answer on June 12, 2026 at 6:42 pm

    As @Roland said, you must derive from ctypes.Structure. Here’s a working version:

    import ctypes
    from ctypes import wintypes
    import uuid
    
    class _SP_DEVINFO_DATA(ctypes.Structure):
        _fields_ = [("cbSize", wintypes.DWORD),
                    ("ClassGuid", ctypes.c_char * 16),
                    ("DevInst", wintypes.DWORD),
                    ("Reserved", wintypes.LPVOID)]
    
        def __init__(self, guid, inst):
            self.cbSize = ctypes.sizeof(_SP_DEVINFO_DATA)
            self.ClassGuid = uuid.UUID(guid).get_bytes()
            self.DevInst = (ctypes.c_ulong)(inst)
            self.Reserved = None
    
        def __repr__(self):
            return "_SP_DEV_INFO_DATA(cbsize={},ClassGuid={},DevInst={})".format(
                self.cbSize,uuid.UUID(bytes=self.ClassGuid),hex(self.DevInst))
    
    sp = _SP_DEVINFO_DATA('08751880-13bb-11e2-96f0-402cf4ca5e51',0x12345678)
    print sp
    

    Output:

    _SP_DEV_INFO_DATA(cbsize=28,ClassGuid=08751880-13bb-11e2-96f0-402cf4ca5e51,DevInst=0x12345678L)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.