Results 1 to 7 of 7

Thread: What other changes should I make?

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Question What other changes should I make?

    I am trying to retrieve data from a dll and show it on a console window.

    I first tried it out with VC++ and this was the main code

    #include <iostream>
    #include<windows.h>

    using namespace std;


    HMODULE hDll = LoadLibrary(L"dllprog.dll");
    FARPROC fpTestDll = GetProcAddress(hDll, "TestDll");
    typedef char* (__stdcall *fpTestDllT)();
    fpTestDllT TestDll = (fpTestDllT)fpTestDll;

    int main()
    {
    char* a;
    a = TestDll();
    cout <<endl << a;
    Sleep(3000);
    }
    this is working perfectly fine.

    Now i am trying to write the same thing with Qt using QtCreator to make it platform independent

    this is my code

    #include <QtCore/QCoreApplication>
    #include <QLibrary>
    #include <iostream>
    #include <windows.h>


    QLibrary myLib("dllprog");
    typedef void (*MyPrototype)();
    MyPrototype myFunction =
    (MyPrototype) QLibrary::resolve("dllprog", "TestDll");

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    char b;
    b = TestDll();
    cout <<endl << b;

    return a.exec();
    }
    but the compiler shows some errors. what changes should I make to get the app working??

    One more question, i tried a helloworld dialog app. It was working fine when i used the creator to build and run, but when i went to the .exe file and double clicked it, it says mingwm10.dll is missing. I have given the path os MINGW in the environmental variables. what should I do to avoid that?

    Will the created app be able to run in systems that dont have MINGW?
    Last edited by srohit24; 4th March 2009 at 07:21.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What other changes should I make?

    please show the errors it gave

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: What other changes should I make?

    here are the errors. 3 of them

    /main.cpp:21: error: `TestDll' was not declared in this scope
    main.cpp:22: error: `cout' was not declared in this scope
    /main.cpp:22: error: `endl' was not declared in this scope
    and 3 warning for unused cout, endl and TestDll.

    hopefully you can help
    Last edited by srohit24; 4th March 2009 at 07:23.

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: What other changes should I make?

    for the cerr error
    Qt Code:
    1. using namespace std;
    To copy to clipboard, switch view to plain text mode 

    for the TestDll() error, probably:
    you defined a function (varible) myFunction, call that instead?
    and you should probably also declare it to return a char* instead of void?

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QLibrary>
    3. #include <iostream>
    4. using namespace std;
    5.  
    6. QLibrary myLib("dllprog");
    7. typedef char* (*MyPrototype)();
    8. MyPrototype myFunction =
    9. (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QCoreApplication a(argc, argv);
    14.  
    15. char *b = TestDll();
    16. cout << endl << b;
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    (all untested, of course...)

    HTH

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: What other changes should I make?

    thanks for replying mate.

    I just corrected cout and endl using namespace std (silly error )

    thanks mate, it worked

    Can you explain your reasoning?

    Now I need to create a GUI appliaction. I want to use a pushbutton to paste the contents in variable b into a text box, how can that be done? whats the code for it? I am new to GUI based coding.

    this is the working code

    #include <QtCore/QCoreApplication>
    #include <QLibrary>
    #include <iostream>
    #include <windows.h>

    using namespace std;
    /*HMODULE hDll = LoadLibrary(L"dllprog.dll");
    FARPROC fpTestDll = GetProcAddress(hDll, "TestDll");
    typedef char* (__stdcall *fpTestDllT)();
    fpTestDllT TestDll = (fpTestDllT)fpTestDll; */

    QLibrary myLib("dllprog");
    typedef char* (*MyPrototype)();
    MyPrototype myFunction =
    (MyPrototype) QLibrary::resolve("dllprog", "TestDll");

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    char *b = myFunction();
    cout <<endl << b;
    //Sleep(3000);
    return a.exec();
    }
    Last edited by srohit24; 4th March 2009 at 08:09.

  6. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: What other changes should I make?

    reasoning? what reasoning?
    well, if you have a function that should return "text" its return type probably is not void
    (and the return type in the windows example was char*, so I figured "same dll, same type").

    GUI:
    you need to create a little dialog (by code or with designer).
    put a QPushButton inside, and some text widget (e.g. QTextEdit).
    Connect a slot to the QPushButton's clicked() signal. In the slot call your dll stuff.
    With the result, call QTextEdit::setText()
    See the Qt docs for examples on how to do that: tutorials
    HTH

  7. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: What other changes should I make?

    how can i call my dll function in the slot?

    When i add a slot i dont get my dll function in the textedit window in slots.

    what should i do?

Similar Threads

  1. Error running 'make'
    By borker in forum Installation and Deployment
    Replies: 1
    Last Post: 1st May 2008, 14:54
  2. QT4 for kde 4 beta 2 configure problem: make not found
    By marcomangiante in forum Installation and Deployment
    Replies: 1
    Last Post: 5th September 2007, 20:35
  3. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  4. Replies: 3
    Last Post: 19th October 2006, 22:13
  5. Qt4.1.4 make errors.
    By impeteperry in forum Installation and Deployment
    Replies: 11
    Last Post: 1st July 2006, 17:27

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
  •  
Qt is a trademark of The Qt Company.