Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 63

Thread: DLL Injection with slots... ?!?!?

  1. #41
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Hold on, there is something wrong here. Regardless of what the connection type is (be it AutoConnection or DirectConnection or QueuedConnection), the slot eventually gets called unless the target slot is in a thread that doesn't have an event loop running. So if your slot doesn't get called if you use AutoConnection then it means it runs within a thread without an event loop which in turn implies it is not the main application thread. And accessing widgets from the non-gui thread leads to a crash. I see some contradictions here:
    1. since your test app doesn't use worker threads, auto and direct connections should be equivalent
    2. your test app doesn't crash so you are not accessing widgets from a worker thread which in turn means the slot should work in the first place
    2. if the application you are trying to break into uses threads and that's why the auto connect doesn't work (because your injection code works in the context of one of the worker threads), then accessing any component behind its back will/should likely lead to a crash.

    To sum things up - either you are wrong now about direct connections or your solution will be crashing on you like hell soon.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #42
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    ok, ok... we have something here.
    I'm comming for managed languages (Java) and I'm used to Garbdge collectors... (Be nice)

    The new problem is that the slot is being called only one time.... I'm creating an object of MyQWidget when the DLL is being called, I'm calling the function that does the slot-signal connection, and I'm not releasing the object...
    The DLL is still in the Main Application memory space, but MyQWidget is somehwere in memory!? maybe that was the reason that slot was not getting called...

    I understand that I'm suppose to have some kind of events loop, that will keep MyQWidget alive, so my slot is available for SIGNALS. How Do I do that?

    Am I right?
    I guess that now you'll send me to read something (Please do)

    Many thanks
    Gil

  3. #43
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    (Please read the previous post, first)

    I'm trying now to prevent my MyQWidget from terminating (So it can be available for signals) I've changed it to inherit from QDialog (And not just QWidget or QObject)
    When the DLL is running for the first time, I'm creating my "dialog" and calling a public function to do the signal connection, and than calling the "exec()" function of the dialog (To keep it alive)
    BUT! the main UI is freezing, until I close my Dialog...

    Do I have to create the dialog in a different thread? so the main UI will be able to actually send the signal...

    Gil.

  4. #44
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    If the application is a Qt application (and it is) then there is already an event loop running and you shouldn't need to do anything more. Especially don't try handling anything related to widgets from another thread (in doubt read my previous post again). It doesn't matter if you inherit from QWidget or QDialog, the main event loop is already handling your widget. As for the memory thing, as long as you don't delete the object yourself and as long as its parent doesn't go out of scope, you'll object will remain alive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #45
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    As far as I can see, I have two options:
    1. use exec() -> leads to the main UI waiting for the dialog to close.
    2. use show() -> The dialog opens, and closes very fast, no Idea why...

    any ideas?

  6. #46
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by gilamran View Post
    2. use show() -> The dialog opens, and closes very fast, no Idea why...
    You are probably creating it on the stack and not on heap so it gets out of scope and gets deleted by the compiler.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    gilamran (19th October 2010)

  8. #47
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    That was the problem!!
    I've created my QDialog on the heap and now I'm getting all the signals!!! yey!
    This might be obvious to some of you, but I come from Java (With garbage collector)

    Two things left:
    1. When I close the main UI, I can still see it in memory (Probably because it still have a slot in an object that wasn't release...)
    So I need a way to know when the window is trying to close, or when the data of the model is being deleted... are there any events/signals that I can listen to and delete myself?

    2. Still when I use the QDialog show(), it's openning and closing (very fast), and when I use the exec(), the main UI is stuck till I close it... any idea how to solve this?

    Thanks
    Gil

  9. #48
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Show us how you create the dialog.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #49
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    Qt Code:
    1. #include <windows.h>
    2.  
    3.  
    4. INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
    5. {
    6. MyQDialog *m_MyQDialog = new MyQDialog();
    7.  
    8. switch(Reason)
    9. {
    10. case DLL_PROCESS_ATTACH:
    11. m_MyQDialog->connectQWidget();
    12. m_MyQDialog->show();
    13. break;
    14.  
    15. case DLL_PROCESS_DETACH:
    16. break;
    17.  
    18. case DLL_THREAD_ATTACH:
    19. break;
    20.  
    21. case DLL_THREAD_DETACH:
    22. break;
    23. }
    24. return TRUE;
    25. }
    To copy to clipboard, switch view to plain text mode 

  11. #50
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    This shouldn't cause your dialog to disappear.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #51
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: DLL Injection with slots... ?!?!?

    At which point in time does DLL_PROCESS_ATTACH happen?

    If it happens when the dll gets loaded before the main event loop is running, you're too soon to create the dialog.

    Note that the main event loop is the one you want to use to create your dialog.
    Try installing a hook into the main application event function. Then, when the application started event happens, create your dialog.

  13. #52
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    I'm injecting my DLL when the application is fully running.
    I took the QApplication:instance(), than I checked the applicationFilePath and got the injected exe file path. I guess that this means that My Dialog will be part of the exe application...

    It looks like it's going to be inevitable... I will have to debug QT :-(
    What's keeping a QDialog alive?

  14. #53
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by gilamran View Post
    What's keeping a QDialog alive?
    Please define "alive".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #54
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    "alive" means that it's in an events loop.
    I did some debugging and got an ASSERT that said: "widgets must be created in the GUI thread"...
    now I know that you're going to kill me and tell me that you already told me that it's "accessing widgets from the non-gui thread leads to a crash"... ok well, I did get access to the widgets, and even got my external DLL slot to get called...
    but now the thing is that I can't create a dialog from my DLL... is there a way to work around it? (I think that can manage without the dialog)

  16. #55
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Thus far I have an impression that you are doing some random things and expect to find a combination of them that works. This is not a good approach. You should first analyze what the applicaiton you are attaching to is actually doing. Otherwise your code might be called from a completely arbitrary context and it will not be possible to control it. Use a debugger to see whether the application uses threads and find a context where it will be running the main thread and try attaching to that. Otherwise you'll end up in a situation that you are doing something from a worker thread that gets terminated at some point and you won't be able to continue. Maybe you should find a different way to achieve your goal? Is the application dynamically or statically linked?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #56
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    Ok, after some time I've got some progress...
    but now I have another question: (Should I open a new thread?)
    I investigate the main application UI structure by going to it's children and printing out the widget name, x, y, visible etc.
    BUT I have some window (A VERY important one for me) that contains a a very complex UI, but it's not a child of any of the QWidgets... A large portion of the UI is missing...
    I found a QWidget with no children... can it be that this is the complex UI that I'm missing? can it be that a complex UI is some kind of external EXE running inside the QWidget?

    any ideas?

    Thanks

  18. #57
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    It's rather a graphics view or a custom widget that paints all its contents by itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    gilamran (27th October 2010)

  20. #58
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    great! it's a graphics view... didn't know they exist...

    ok, now that I have the graphics view, how can I enum all the items that inherit from QGraphicsTextItem? and print out their text...
    yea, I know it's a dumb question, but I have no C++ background.... and I didn't find a way to do it.

    Thanks
    Gil

  21. #59
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    You ask the scene for all items and then you iterate over them checking their type and so on.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  22. #60
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    yea I know.... but my C++ background is 0.
    can't get it to work...

    Qt Code:
    1. foreach (QGraphicsItem *item, scene->items())
    2. {
    3. QGraphicsTextItem *gti = qgraphicsitem_cast<QGraphicsTextItem *>(item);
    4. if (gti)
    5. {
    6. sendmsg("QGraphicsTextItem found");
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Signals & Slots!
    By qtoptus in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2010, 02:50
  2. Can you use dependency injection with Qt?
    By photo_tom in forum Qt Programming
    Replies: 0
    Last Post: 20th February 2010, 19:34
  3. How do you add slots?
    By rakkar in forum Newbie
    Replies: 10
    Last Post: 27th August 2009, 00:11
  4. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 18:38
  5. signal and slots
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2007, 09:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.