Search for a third-party QWidget with the entered code and QWidget :: find (hwnd)

I have a Qt Dll that I inject into a third-party application using the window crawl library:

if(!DetourCreateProcessWithDll( Path, NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED, NULL, NULL, &si, &pi, "C:\\Program Files\\Microsoft Research\\Detours Express 2.1\\bin\\detoured.dll", "C:\\Users\\Dave\\Documents\\Visual Studio 2008\\Projects\\XOR\\Debug\\XOR.dll", NULL)) 

and then I set a system-wide hook to intercept window creation:

 HHOOK h_hook = ::SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, Status::getInstance()->getXORInstance(), 0); 

Where XOR is my program name, and Status :: getInstance () is Singleton, where I save global variables.

In my CBTProc callback, I want to intercept all windows that are QWidgets:

 HWND hwnd= FindWindow(L"QWidget", NULL); 

which works well, since I get the corresponding HWND (I checked with Spy ++) Then I want to get a pointer to QWidget, so I can use its functions:

 QWidget* q = QWidget::find(hwnd); 

but here is the problem, the returned pointer is always 0. Have I entered the code incorrectly in this process? Or am I not using QWidget :: find () as it should?

Thanks,

Dave

EDIT: If I changed the QWidget :: find () function to an exported function of my DLL, after setting the hooks (so that I could set and catch a breakpoint), QWidgetPrivate :: mapper is NULL.

+7
qt dll code-injection hook qwidget
source share
2 answers

Answer:

Stupid error, I compiled into Debug, so QtGui4d.dll and QtCore4d.dll loaded, not QtCore4.dll and QtGui.dll

+2
source share

Compare the `QWidgetPrivate :: mapper addresses in the DLL and in your code. Especially if one of them is connected statically, there may be two instances, each of which has its own, disjoint set of widgets.

0
source share

All Articles