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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:27:47+00:00 2026-05-24T23:27:47+00:00

Here is the thing, I wrote a program using windows api EnumWindows which requires

  • 0

Here is the thing, I wrote a program using windows api EnumWindows which requires a callback func as the first arg, my poor code is as follows:

User32 = WinDLL('User32.dll')
LPARAM = wintypes.LPARAM

HWND = wintypes.HWND
BOOL = wintypes.BOOL

def Proc(hwnd, lparam):
    print("hwnd = {}, lparam = {}".format(hwnd, cast(lparam, c_char_p)))
    return True

WNDPROCFUNC = WINFUNCTYPE(BOOL, HWND, LPARAM)  #用winfunctype 比cfunctype 好
cb_proc = WNDPROCFUNC(Proc)

EnumWindows = User32.EnumWindows
EnumWindows.restype = BOOL

EnumWindows(cb_proc, 'abcd')

then I ran the program, but it just print

hwnd = 65820, lparam = c_char_p(b'a')
hwnd = 65666, lparam = c_char_p(b'a')
hwnd = 65588, lparam = c_char_p(b'a')
hwnd = 65592, lparam = c_char_p(b'a')
hwnd = 1311670, lparam = c_char_p(b'a')
hwnd = 591324, lparam = c_char_p(b'a')
hwnd = 66188, lparam = c_char_p(b'a')
hwnd = 393862, lparam = c_char_p(b'a')

why not b’abcd’?

  • 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-05-24T23:27:48+00:00Added an answer on May 24, 2026 at 11:27 pm

    Because you are using Python 3 which is treating abcd as a Unicode string which ctypes encodes with UTF-16. But you then cast it assuming it is a single byte ANSI string.

    You can make the program behave the way you want by one of the following methods:

    1. Use Python 2.x
    2. Call EnumWindows like so: EnumWindows(cb_proc, b'abcd')
    3. Use c_wchar_p in the case: cast(lparam, c_wchar_p)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a program using Scala's remote actors. My first step was to create
I wrote a c++ program using boost library in Xcode. Here is my code.
I wrote and tested some code in a Windows XP (Qt 4.7.2) using Visual
This is my first program using Haskell. I'm writing it to put into practice
I wrote a little program to calculate the first 18 triples (x,y,z) with x<y<z
Here's the thing: I have two applications, written in C++ and running on two
Here's the thing: object[] arrayText = new object[1]; if (arrayText[1] == null) { MessageBox.Show(Is
Here is the thing. Right now I have this e-commerce web site where people
I'm triying to do exactly the same thing described here , but in VB.NET
Here's a coding problem for those that like this kind of thing. Let's see

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.