1 registered members (AndrewAMD),
1,014
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
DLL return values, MANY CRASH error! - SOLVED
#425465
07/05/13 17:25
07/05/13 17:25
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
Hello friends!. I created a dll made ​​in C + + to return values ​​that were surveyed in a database SQLITE3! At first everything works correctly, BUT , when the database starts to earn enough database tables start getting bigger is that my real problem starts! The operation is totally unstable! Suddenly I get an crash error. These errors happen when I need to receive the data. But not always. Sometimes it works fine and others it can generate a crash error, which I can not identify. But I managed to identify these occasional errors always happen when I use search functions of data. When I need to get a large number data is then subject to severe receiving a crash error. could you give me tips so I can STABILISE my function? Sample my DLL and LiteC Script: C++
//Receive data from rows and columns of the DataBase
...
DLLFUNC char* sqlite__select(int r, int c)
{
//return char value on rows [r] and Column [c]
return ((char*)result[r][c].c_str());
}
...
LiteC, Receive Many data.
void test_select()
{
int rows = sqlite_rows(); //Total de rows (sample 100 rows)
for(ping = 0; ping < rows; ping ++)
{
//ID
printf("%s",sqlite_select(ping,0)); //return 0..1..2..3..4..n
//test0
printf("%s",sqlite_select(ping,1)); //return 0..1..2..3..4..n
//test1
printf("%s",sqlite_select(ping,3)); //return 0..1..2..3..4..n
.... test100
}
Can happen or not returning a crash error. (T.T)
Last edited by NeoNeper; 07/05/13 18:45.
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: DLL return values, MANY CRASH error!
[Re: NeoNeper]
#425466
07/05/13 17:55
07/05/13 17:55
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
I could imagine that returning the c_str() is not a good idea. Maybe you pass a char* buffer instead, in which you write the result?
DLLFUNC char* sqlite__select(char* buffer, int r, int c)
{
if (buffer != NULL)
strcpy(buffer, result[r][c].c_str());
return buffer;
}
void test_select ()
{
int rows = sqlite_rows();
char buffer [256];
int ping;
for (ping = 0; ping < rows; ping++)
{
printf("%s", sqlite_select(buffer, ping, 0));
printf("%s", sqlite_select(buffer, ping, 1));
printf("%s", sqlite_select(buffer, ping, 3));
}
}
|
|
|
Re: DLL return values, MANY CRASH error!
[Re: HeelX]
#425467
07/05/13 18:19
07/05/13 18:19
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
ooh THAT AND A really good idea. Testing will!
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: DLL return values, MANY CRASH error!
[Re: NeoNeper]
#425468
07/05/13 18:59
07/05/13 18:59
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
seem to work! tested many again my game, and I had no more problems! (^.^) Tankx HeelX.
If you have a few more important tips for working with DLL, please teach for me. (^.~)
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: DLL return values, MANY CRASH error!
[Re: NeoNeper]
#425470
07/05/13 20:31
07/05/13 20:31
|
Joined: May 2013
Posts: 23 Somewhere
Wiseguy
Newbie
|
Newbie
Joined: May 2013
Posts: 23
Somewhere
|
If you have a few more important tips for working with DLL, please teach for me. (^.~) I have told you about the problem with auto variables multiple times before in this thread, but you chose to ignore it. And I don't doubt that you will do the same mistake again in the near future. Important tip: PLEASE get familiar with C++ before doing anything else. That your program crashed was very fortunate, because it's an easy way to track down undefined behaviour, but you are not guaranteed to be that lucky every time. Also, in a similar vein, DON'T use old C-Style casts! They are too broad and you lose an awful lot of control when using them. And don't cast away constness if you don't need to, and if you absolutely need to, use const_cast<>().
His words are wise, his face is beard.
|
|
|
Re: DLL return values, MANY CRASH error!
[Re: Wiseguy]
#425580
07/08/13 17:57
07/08/13 17:57
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
tanks Wiseguy. Some times I have difficulty understanding, for not mastering the English language fluently.
I have trouble with C + +, but I'm slowly learning, with your help and support materials. I am so grateful to this community.
I have done great things using LITEC along with C + +! The LITEC became a door for me to enter this world of programming games and consequently for me to learn new programming languages!.
Last edited by NeoNeper; 07/08/13 18:00.
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
|