Hi there, this is my first post on this forum I've been following for quite some time. Recently I got an idea to improve my decisions while playing poker. I've come a long way, but still I'm figuring out some issues. Currently I'm figuring out how to call back into the Qt framework from an Easyhook hooked Qt function, but can't resolve this for some reason. Can you help me out? I tried searching for it, but either I'm not using the right keywords or there's nothing to be found about this subject (highly unlikely).
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);
}
}