Найти - Пользователи
Полная версия: DLL, messages, qt
Начало » GUI » DLL, messages, qt
1
Nolr
Есть dll. Есть код на delphi, работающий с ней.
var
    MainWindowHandle:cardinal;
    Data: array [0..100] of byte;
    DataMSG:byte;
private
    procedure ProcMSG(var VMsg:TMessage); message WM_USER+1;
public
    function open(MainWinHandle:cardinal;pData:Pointer;MsgP:pointer):boolean; stdcall external 'gtr.dll';
// инициализация в начале работы приложения
    initDLL(MainWinHandle, Addr(Data), Addr(DataMSG));
procedure TForm1.ProcMSG(var VMsg:TMessage);
begin
    case DataMSG of
    04: begin
    // работа массивом Data
    end;
end;


Мой код такой
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui import Ui_mainForm
from ctypes import *
class mainForm(QWidget):
    def __init__(self, parent=None):
        super(mainForm, self).__init__(parent)
        self.ui = Ui_mainForm()
        self.ui.setupUi(self)
        MainWindowHandle = windll.kernel32.GetCurrentThread()
        #MainWindowHandle = self.winId() 
        gtrDLL = windll.LoadLibrary('gtr.dll')
        gtrDLL.open.restype = c_bool
        HEAP_ZERO_MEMORY = 8L
        GetProcessHeap = windll.kernel32.GetProcessHeap
        HeapAlloc      = windll.kernel32.HeapAlloc
        HeapFree       = windll.kernel32.HeapFree
        self.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 100 * sizeof(c_byte))
        self.DataMSG = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(c_byte))
        # освобождать память буду в конце работы приложения
        gtrDLL.open(c_ulong(MainWindowHandle), self.buffer, self.DataMSG)
        
    def winEvent(self, message):
        WM_USER = 0x0400
        if message.message == WM_USER + 1: # это условие не выполняется никогда        
            #if self.DataMSG == 2:
            #if (c_byte).from_address(self.DataMSG) == c_byte(2):
            result = (c_byte * 100).from_address(buffer)
            print result
        return (False, 0) # подсмотрел в чудом коде, но не уверен, что нужно именно так делать
        #return QWidget.winEvent(False, message.message)
Nolr
Добавлю, что есть pyqt и с помощью (bool, int result) QWidget.winEvent (self, MSG message) можно добраться до нужного мне сообщения, а потом данным. Вопрос как получить result?

Идею подглядел в http://www.qtcentre.org/threads/42038-Problems-with-recieving-Windows-messages-using-winEvent
Nolr
А вот с таким кодом у кого-то есть идеи как решить эту задачу?
reclosedev
Откуда должен прийти WM_USER + 1 ?

http://www.riverbankcomputing.com/pipermail/pyqt/2006-August/013891.html
The PyQt4 variant of this function returns a tuple where the first
element is the same as the result value of the Qt function and the
second item is the long* result.
Nolr
Откуда должен прийти WM_USER + 1 ?
Это сообщение от DLL.

С моим вопросом разобрался. Проблема была не в коде.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB