Notepad++, windows 11 and pythonscript
-
I’ve recently had to replace my windows 10 computer with a windows 11 one. After reinstalling notepad++, pythonscript and python2.7 and the windows api python extension, I’m having problems with this script:
https://github.com/ThosRTanner/python-notepad-scripts/blob/master/statusbar_for_linter.py
The read_statusbar_section function is always returning an empty string as the SendMessage function always returns 0.
I’m at a loss to work out what is happening here, and if anyone has any suggestions I’d be grateful.
(PS I may have posted this twice. the forum is being a bit strange today)
-
@ThosRTanner
Have you posted an issue in the repo? -
@Mark-Olson Which repo?
-
The problem with the code is that it is not clear how SendMessage needs to be called.
Make sure you define a prototype, such asimport ctypes from ctypes.wintypes import ( HWND, UINT, WPARAM, LPARAM ) LRESULT = ctypes.c_ssize_t SendMessage = user32.SendMessageW SendMessage.restype = LRESULT SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
and then use that always.
Python now knows how to handle the parameters and will throw exceptions if they are not specified properly.
HWND is a pointer, while the rest are integer types. -
@Ekopalypse said in Notepad++, windows 11 and pythonscript:
LRESULT = ctypes.c_ssize_t
This is interesting. Previously I believe you recommended:
LRESULT = LPARAM
and indeed that is what I have in my scripts that use this.
Isctypes.c_ssize_t
a better thing to use? -
@Alan-Kilborn said in Notepad++, windows 11 and pythonscript:
Is ctypes.c_ssize_t a better thing to use?
No, they are exactly the same.
I have finally started to migrate my scripts with a single winapi module
and I kept the c_ssize_t variant because it is more descriptive for me.
There is no doubt that it is a signed size_t, while LPARAM cannot tell.
If wintypes had contained LRESULT, I would have taken it. -
it’s now objecting because what create_string_buffer returns isn’t an integer.
-
use ctypes.addressof to get the int representation of the pointer
-
@Ekopalypse working great now. thank you!