views:

752

answers:

3

Hey, I have a Qt Dll wich I inject into a third-party Application using windows detours 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 programs name, and Status::getInstance() is a Singleton where I keep globals.

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 a corresponding HWND (I checked with Spy++) Then, I want to get a pointer to the QWidget, so I can use its functions:

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

but here's the problem, the returned pointer is always 0. Am I not injecting my code into the process properly? Or am I not using QWidget::find() as I should?

Thanks,

Dave

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

A: 

Compare the addresses of `QWidgetPrivate::mapper in the DLL and in your code. Esp. if one is linked statically, there might be two instance of it, each with it's own, disjoint, set of widgets.

what do you mean in the DLL and in my code? the DLL is my code
David Menard
+1  A: 

Answered:

Stupid mistake, I was compiling in Debug, so it was QtGui4d.dll and QtCore4d.dll that where loading, not QtCore4.dll and QtGui.dll

David Menard
A: 

how can i find out which dll is loaded? i have the same problem as David Menard

I'm running debug build, succesfully(??) hook dll, attach with debuger to injected application exe, but no success using QWidget::find. HWND is correct.