Hi,
I’ve created a Plugin named “Test”. It calls from Win32.api the MessageboxA.
If I execute the api-call with Ctrl+B it works like expected.
But if I bind the call inside a ApplicationCommand class, I get an error.
This code works with Ctrl+B[code]
from ctypes import *
MB_DEFBUTTON1 = 0x0
MB_DEFBUTTON2 = 0x100
MB_DEFBUTTON3 = 0x200
MB_ICONASTERISK = 0x40
MB_ICONEXCLAMATION = 0x30
MB_ICONHAND = 0x10
MB_ICONINFORMATION = MB_ICONASTERISK
MB_ICONQUESTION = 0x20
MB_ICONSTOP = MB_ICONHAND
MB_OK = 0x0
MB_OKCANCEL = 0x1
MB_YESNO = 0x4
MB_YESNOCANCEL = 0x3
MB_ABORTRETRYIGNORE = 0x2
MB_RETRYCANCEL = 0x5
class MessageBox:
def box_a(self, text, title=‘Message Box’, utype=MB_OK, hwnd=None):
mb = windll.user32.MessageBoxA
mb(hwnd, c_char_p(text), c_char_p(title), c_long(utype))
msg = MessageBox()
msg.box_a(‘Thats a message’)[/code]
And this code was created as plugin “test” and bind with “F12”.[code]
import sublime, sublime_plugin
from ctypes import *
MB_DEFBUTTON1 = 0x0
MB_DEFBUTTON2 = 0x100
MB_DEFBUTTON3 = 0x200
MB_ICONASTERISK = 0x40
MB_ICONEXCLAMATION = 0x30
MB_ICONHAND = 0x10
MB_ICONINFORMATION = MB_ICONASTERISK
MB_ICONQUESTION = 0x20
MB_ICONSTOP = MB_ICONHAND
MB_OK = 0x0
MB_OKCANCEL = 0x1
MB_YESNO = 0x4
MB_YESNOCANCEL = 0x3
MB_ABORTRETRYIGNORE = 0x2
MB_RETRYCANCEL = 0x5
class TestCommand(sublime_plugin.ApplicationCommand):
def run(self):
self.box_a(‘Test-Box’)
def box_a(self, text, title='Message Box', utype=MB_OK, hwnd=None):
mb = windll.user32.MessageBoxA
mb(hwnd, c_char_p(text), c_char_p(title), c_long(utype))
[/code]
This fails with error message:
[quote] mb(hwnd, c_char_p(text), c_char_p(title), c_long(utype))
TypeError: bytes or integer address expected instead of str instance[/quote]
What do I wrong?
Thanks in advance.