PDA

View Full Version : How to get an array of bytes from a DLL?



srohit24
22nd April 2009, 06:02
Hi

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



void Dialog::myFunction1()
{
QLibrary *loadLibrary = new QLibrary("sample_for_rohit");

loadLibrary->load();
if (loadLibrary->isLoaded() == false)
qDebug()<<"error not loaded";
else
qDebug()<<"loaded";

typedef char* (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) QLibrary::resolve("sample_for_rohit", "TestDll");
char *b = myFunction();

ui->dispEdit->setText(b);
}

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

faldzip
22nd April 2009, 07:28
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.

srohit24
22nd April 2009, 10:25
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.


QLibrary *loadLibrary = new QLibrary("sample_for_rohit");

loadLibrary->load();
if (loadLibrary->isLoaded() == false)
qDebug()<<"error not loaded";
else
qDebug()<<"loaded";


typedef QByteArray (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) QLibrary::resolve("sample", "TestDll");

QByteArray ba = myFunction();

char *b = ba.data();

ui->dispEdit->setText(b);

faldzip
22nd April 2009, 11:09
and what that function in DLL is returning exactly?

srohit24
22nd April 2009, 15:14
It returns a array of bytes. (not a string)

faldzip
22nd April 2009, 16:11
I don't know C++ type named "array of bytes"...