January 20, 2012

Adi Adi
Lab Rat
206 posts

[split] dll issues

 

Hi

I have created a dll in win32 in which i have also linked Qt libraries so that I can use both QT & win32 datatypes in this dll.
I have created one more QT Application in which I am loading this dll dynamically using QLibrary::load().
After loading I am calling one function in for loop form this dll which takes QStirng as parameter for 1st 10 times the QString value which I am sending from QT app to that dll is recieved correctly in that dll function but exactly from 11th time the QString value sent from QT appp to dll function is showing garbage value?

How to resolve this?

12 replies

January 20, 2012

Adi Adi
Lab Rat
206 posts

Hi

The error message which i recieve says something like this

A buffer overrun has occurred in TEMP.exe which has corrupted the program’s internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic ‘How to debug Buffer Overrun Issues’.

January 20, 2012

Adi Adi
Lab Rat
206 posts

Hi Lukas

I am facing one more problem can you help me to resolve this

Step 1: I have created a win32 dll with name Temp.dll in which i have linked QT libraries & also added required include files so that i can also use QT datatypes in that dll.
In Temp.dll has one function with following prototype & definition

  1. QString Data(QString data)
  2. {
  3.         return data;
  4. }

Step 2: Now I have created one Sample QT Appplication code for same is given below but when I am trying to call the above function in this application in for loop after 2-3 iterations of for loop it is crashing & giving following error message

A buffer overrun has occurred in LoadLibrary.exe which has corrupted the program’s internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic ‘How to debug Buffer Overrun Issues’.

  1. Sample App Code:
  2.  
  3. #include <QLibrary>
  4. #include <QString>
  5. #include <qdebug.h>
  6.  
  7. //Function Pointers
  8. typedef QString (*Data)(QString);
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.         QCoreApplication a(argc, argv);
  13.         bool bLoaded = false;
  14.         //Load win32 Export Library
  15.         QLibrary lib("Temp.dll");
  16.         bLoaded = lib.load();
  17.         Data  data= (Data) lib.resolve("Data");
  18.         if(bLoaded)
  19.         {
  20.                 for(int i = 0;i<100; i++)
  21.                 {
  22.                         QString strName = "Test";
  23.                         if(lib.isLoaded())
  24.                                 QString strTagInfo = data(strName);
  25.                 }
  26.         }
  27.         else
  28.         {
  29.                 QString str = "Failed to load Temp library";
  30.         }
  31.         bool bUnLoad = lib.unload();
  32.        
  33.         return a.exec();
  34. }

January 20, 2012

Tobias Hunger Tobias Hunger
Area 51 Engineer
3383 posts

I just split this out of another thread to make the issue more visible. Hope this helps getting it resolved fast.

January 20, 2012

Tobias Hunger Tobias Hunger
Area 51 Engineer
3383 posts

I would guess that your buffer overrun corrupts the string you pass. Fix the overrun and your problem should go away.

January 20, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

… and merge with http://developer.qt.nokia.com/forums/viewthread/13631/ please ;-)

January 20, 2012

Adi Adi
Lab Rat
206 posts

How to fix over run.

January 20, 2012

Tobias Hunger Tobias Hunger
Area 51 Engineer
3383 posts

Check http://en.wikipedia.org/wiki/Buffer_overflow for more information on what is going wrong.

January 20, 2012

Gerolf Gerolf
Robot Herder
3235 posts

If I read the code, it is buggy:

  1.     Sample App Code:
  2.      
  3.     #include <QLibrary>
  4.     #include <QString>
  5.     #include <qdebug.h>
  6.      
  7.     //Function Pointers
  8.     typedef QString (*Data)(QString);
  9.      
  10.     int main(int argc, char *argv[])
  11.     {
  12.             // ...
  13.             Data  data= (Data) lib.resolve("Data");
  14.             if(bLoaded)
  15.             {
  16.                 // ....
  17.                   QString strTagInfo = Data(strName);
  18.                   // here you use the type, not the pointer?
  19.             }
  20.             // ...
  21.             return a.exec();
  22.     }

I would recommend to rename the pointer data to something like dataFkt or similar, so such things are seen earlier…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

January 23, 2012

Adi Adi
Lab Rat
206 posts

Hi Gerolf

I didnt exactly get what you want me to do can you please explain clearly.

January 23, 2012

Adi Adi
Lab Rat
206 posts

Hi Gerolf

That was the typing mistake in actual I was using data() only. But still same problem.

January 23, 2012

Adi Adi
Lab Rat
206 posts

Can anyone please help me to resolve this.

January 23, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Well, you might provide a small, compilable example that reproduces your problem, which can be downloaded somewhere.

 
  ‹‹ Problem with sockets      QHostInfo ››

You must log in to post a reply. Not a member yet? Register here!