I'm hooking into QLabel::paintEvent and in the hook I want to call (for example) the QLabel::text function of the passed in QLabel. Please check the code below.
The hook works, but the moment I call QLabel::text I'm getting an AccessViolationException.
Thanks a million!
PS: I saw codingthewheel.com is down. Such a shame! Is there a mirror of the site?
Currently I have this (c#)
Code:
[DllImport("Qt5Widgets.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.ThisCall, EntryPoint = "?text@QLabel@@QBE?AVQString@@XZ")]
protected static extern IntPtr QLabel_text(IntPtr obj);
[DllImport("Qt5Widgets.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.ThisCall, EntryPoint = "?paintEvent@QLabel@@MAEXPAVQPaintEvent@@@Z")]
protected static extern void QLabel_paintEvent(IntPtr obj, IntPtr p1);
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Unicode, SetLastError = true)]
delegate void TQLabel_paintEvent(IntPtr obj, IntPtr p1);
static unsafe void QLabel_paintEvent_Hooked(IntPtr obj, IntPtr p1)
{
try
{
var ptr = QLabel_text(obj); // <-- I'm getting an AccessViolationException here. Why? And how can I resolve this?
var str = (QString)Marshal.PtrToStructure(ptr, typeof(QString));
((Main)HookRuntimeInfo.Callback).Interface.GotQLabel_paintEvent(str.ToString());
QLabel_paintEvent(obj, p1);
}
catch (Exception ex)
{
((Main)HookRuntimeInfo.Callback).Interface.ErrorHandler(ex);
}
}
Statistics: Posted by stat80 — Thu Feb 18, 2016 8:41 pm
]]>