Results 1 to 6 of 6

Thread: How to get an array of bytes from a DLL?

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

    Default How to get an array of bytes from a DLL?

    Hi

    I have a working code that can get a string from a DLL built in VS.

    Qt Code:
    1. void Dialog::myFunction1()
    2. {
    3. QLibrary *loadLibrary = new QLibrary("sample_for_rohit");
    4.  
    5. loadLibrary->load();
    6. if (loadLibrary->isLoaded() == false)
    7. qDebug()<<"error not loaded";
    8. else
    9. qDebug()<<"loaded";
    10.  
    11. typedef char* (*MyPrototype)();
    12. MyPrototype myFunction = (MyPrototype) QLibrary::resolve("sample_for_rohit", "TestDll");
    13. char *b = myFunction();
    14.  
    15. ui->dispEdit->setText(b);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Dataopen is a function inside the dll and hardware_comm is the name of the dll.

    Now i need to access the array of bytes from another DLL. But if I use the same code as in the returning the string, I get a error.
    The error is the just-in-time compiler error.

    I know that the DLL is loaded as i get the loaded msg from qDebug.

    Somehow DLL permits strings but not pointer to arrays(I know its strange because internally it’s the same thing but that’s the way it is!).

    Can anyone help me out in this?

    Thanks
    Last edited by srohit24; 22nd April 2009 at 06:07.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get an array of bytes from a DLL?

    it would be better to see the code from application where your problem appears, and you are showing code from some application not connected with problem... and I think it's rather just-in-time debugger or something like that which is caused by some error in your application - "segmentation fault" would be my guess, probably you're returning pointer to no more existing data or something like that. Can you show us the code? And try to use debbuger to see where the error occurs - much faster then asking us to resolve problem which is exactly that what debbuger should find in a blink of an eye.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    Default Re: How to get an array of bytes from a DLL?

    I am using QtCreator to build the application

    The DLL is built using VS and it is working as it has to. There are no problems with the dll

    My task is to, use the DLL, get the array of bytes from it, and display it.

    I had tried the same thing, but instead of array of bytes, i had to get a string from a different DLL.

    the code for that is shown in my earlier post.

    I tried using QByteArray but i am getting only 1 character return. I dont know if its working or some sort of bug in the code.

    Qt Code:
    1. QLibrary *loadLibrary = new QLibrary("sample_for_rohit");
    2.  
    3. loadLibrary->load();
    4. if (loadLibrary->isLoaded() == false)
    5. qDebug()<<"error not loaded";
    6. else
    7. qDebug()<<"loaded";
    8.  
    9.  
    10. typedef QByteArray (*MyPrototype)();
    11. MyPrototype myFunction = (MyPrototype) QLibrary::resolve("sample", "TestDll");
    12.  
    13. QByteArray ba = myFunction();
    14.  
    15. char *b = ba.data();
    16.  
    17. ui->dispEdit->setText(b);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get an array of bytes from a DLL?

    and what that function in DLL is returning exactly?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    Default Re: How to get an array of bytes from a DLL?

    It returns a array of bytes. (not a string)

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get an array of bytes from a DLL?

    I don't know C++ type named "array of bytes"...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Phonon issues with DirectSound9
    By Zoltán in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2009, 02:48
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. How many bytes did i send?
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2008, 10:12
  4. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  5. How to construct Image from Bytes
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 29th January 2007, 05:41

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.