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

  • Home
  • SEARCH
  • 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 4039306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:35:30+00:00 2026-05-20T12:35:30+00:00

I am trying to read from Python the WM_COPYDATA message some applications (I’m trying

  • 0

I am trying to read from Python the WM_COPYDATA message some applications (I’m trying with Spotify) send to WindowsLiveMessenger to update the “What I’m listening to…” phrase.

From what I have been able to find, WM_COPYDATA messages come in a COPYDATASTRUCT with the following structure:

  • dwData in our case 0x547 so that it access the listening now feature
  • cbData with the length of the string received
  • lpData with a pointer to the string itself, may include Unicode characters

The string should have the following format: \0Music\0status\0format\0song\0artist\0album\0 as stated by ListeningNowTracker

What we receive in a WM_COPYDATA event is a pointer for lParam that contains the COPYDATASTRUCT.

I started tinkering with pywin32 functions and I remembered that they do not accept Unicode characters from past experience, then I switched to ctypes. Despite this being an almost new world in Python for me, I tried with POINTER() and all I got was unknown objects for me or access violations.

I think that the code should create a COPYDATASTRUCT:

class CopyDataStruct(Structure):
    _fields_ = [('dwData', c_int),
                ('cbData', c_int),
                ('lpData', c_void_p)]

Then make the lParam be a pointer to that structure, get the string pointer from lpData and finally get the string with ctypes.string_at(lpData,cbData).

Any tips?

UPDATE 1

The WM_COPYDATA event is received by a hidden window built with win32gui just for this purpose. The copydata event is connected to a function called OnCopyData and this is its header:
def OnCopyData(self, hwnd, msg, wparam, lparam):
The values the function delivers are correct as compared with the ones from the Spy++ messages log.

UPDATE 2

This should be close to what I want, but gives a NULL pointer error.

class CopyDataStruct(ctypes.Structure):
    _fields_ = [('dwData', c_int),
                ('cbData', c_int),
                ('lpData', c_wchar_p)]

PCOPYDATASTRUCT = ctypes.POINTER(CopyDataStruct)
pCDS = ctypes.cast(lparam,  PCOPYDATASTRUCT)
print ctypes.wstring_at(pCDS.contents.lpData)
  • 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-20T12:35:31+00:00Added an answer on May 20, 2026 at 12:35 pm

    I wrote the following trivial win32gui app:

    import win32con, win32api, win32gui, ctypes, ctypes.wintypes
    
    class COPYDATASTRUCT(ctypes.Structure):
        _fields_ = [
            ('dwData', ctypes.wintypes.LPARAM),
            ('cbData', ctypes.wintypes.DWORD),
            ('lpData', ctypes.c_void_p)
        ]
    PCOPYDATASTRUCT = ctypes.POINTER(COPYDATASTRUCT)
    
    class Listener:
    
        def __init__(self):
            message_map = {
                win32con.WM_COPYDATA: self.OnCopyData
            }
            wc = win32gui.WNDCLASS()
            wc.lpfnWndProc = message_map
            wc.lpszClassName = 'MyWindowClass'
            hinst = wc.hInstance = win32api.GetModuleHandle(None)
            classAtom = win32gui.RegisterClass(wc)
            self.hwnd = win32gui.CreateWindow (
                classAtom,
                "win32gui test",
                0,
                0, 
                0,
                win32con.CW_USEDEFAULT, 
                win32con.CW_USEDEFAULT,
                0, 
                0,
                hinst, 
                None
            )
            print self.hwnd
    
        def OnCopyData(self, hwnd, msg, wparam, lparam):
            print hwnd
            print msg
            print wparam
            print lparam
            pCDS = ctypes.cast(lparam, PCOPYDATASTRUCT)
            print pCDS.contents.dwData
            print pCDS.contents.cbData
            print ctypes.wstring_at(pCDS.contents.lpData)
            return 1
    
    l = Listener()
    win32gui.PumpMessages()
    

    I then sent the window a WM_COPYDATA message from another app (written in Delphi):

    Text := 'greetings!';
    CopyData.cbData := (Length(Text)+1)*StringElementSize(Text);
    CopyData.lpData := PWideChar(Text);
    SendMessage(hwnd, WM_COPYDATA, Handle, NativeInt(@CopyData));
    

    The output was:

    461584
    461584
    74
    658190
    2620592
    42
    22
    greetings!
    

    So it seems that it works trivially, pretty much as you coded it.

    The only thing that I can think of is that the text in Spotify’s COPYDATASTRUCT is not null-terminated. You should be able to check that quite easily by reading out the data. Make use of the cbData member.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I'm trying to read variables from a batch file for later use in the
I'm trying to read data from a.csv file to ouput it on a webpage
I am trying to read data from excel files using datatable. The command select
I'm trying to read a value from a file and use it in a
I'm trying to read a feed from Yahoo Pipes into a Silverlight Application. I
I am trying to read queue messages from a private queue in the local
I'm trying to create classes to read from my config file using ConfigurationSection and
I'm trying to open and read from a serial port using the System.IO.Ports.SerialPort class.
I'm trying to create a Zip file from .Net that can be read from

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.