Function returning wrong value

Previous topic - Next topic

jestermon

I've almost completed my sqllite dll, but I have one very strange problem that I can't seem to solve.
The glbasic wrapper passes a parameter to the dll, and receives a string (char*) back from the dll - with no problems.

The problem I have however, is that when I return the string back from the wrapper function, all I get is the first byte (character) of the string. The function is inside a TYPE. I have no idea if that will make a difference though.
See the image for an example of the print results

The function is

Code (glbasic) Select
FUNCTION DBgetRecord$: recordNo
LOCAL record$
record$ = recordNo
INLINE
if(SqlDBgetRecord){
SqlDBgetRecord(record_Str);
}
ENDINLINE
PRINT record$ , 0,1    // <------ Prints out correct value
RETURN record$         // <------ Returns only 1st byte
ENDFUNCTION


I have included the whole project below in the zip file so that the problem can be seen in context.
Any help in getting the full string to return from the function will not only help finalize the project, but also help to add a sqlite database for windows to the glbasic library.

Edit: I wrote the dll for games, to use as few calls as possible. Sqlite itself, is embedded into the dll. The dll does most of the hard work, leaving the game developer to only worry about a few sql statements. It was specially ported to work with GLBasic. . . If I can get the wrapper working. 


[attachment deleted by admin]

Kitty Hello

when passing strings to inline as char*, you need to call getbuffer(max_bytes) and releasebuffer to find the 0 charcter and set the length of the returned string for internal use.

Code (glbasic) Select

INLINE
if(SqlDBgetRecord){
SqlDBgetRecord(record_Str.getbuffer(1024) );
record_Str.releasebuffer();
}
ENDINLINE


jestermon

Thanks Gernot. That fixed the problem.
I don't see the releasebuffer() function anywhere in the documentation - But I'll certainly remember it though.

I've uploaded the fully working sqlite dll with its wrapper and usage example to the showroom, for those that are interested in a real sql database for their games. It will only work on windows.

jestermon

This might be of interest to some advanced users.
The releasebuffer function which is not documented got me to thinking - Where can I find a reference to other undocumented functions?
I then ran a search for "releasebuffer" on all files in the glbasic directory structure. There were a lot of hits, but mostly in .a files (.a being linker files for unix based systems). I use devcpp a lot, so I am quite familiar this.
However the one file that really stood out was glb.h since this contained the function declarations. In here I found what I was looking for - Definitions of all c/c++ based functions, and found quite a few functions that are not documented, and that I had not seen before.
So if you are into INLINE coding, then glb.h is a great place to scratch around, and learn more about the insides of glbasic.

fuzzy70

Thanks for sharing that & your sqlite wrapper. I may have use for that in the not to distant future as I have been toying with writing a frontend for my emulators (& I have more than a few lol).

Using SQL would make storing the available games for each system etc far more manageable.

Time for me to refresh my SQL & table splitting/optimizing I think ::)

Cheers
Lee

Sent from my GT-I5700 using Tapatalk 2

"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)