10.205 new?

Previous topic - Next topic


What does this mean?

   //    New libs included. Can use WebOS 3.x features now. Please check for
   //    PDL_GetPDKVersion() > 100 if you want features unavailable on 1.4.5

Kitty Hello

You can use the Touchpad-PDK library now. If you want to be compatible with 1.4.5 devices, check for PDL_GetPDK_Version() > 100 to see that you're on 2.x at least.
You can use these function with:
IMPORT "C" int PDL_GetPDKVersion()
for example.



Can you write a little example?

For example with

PDL_GetDataFilePath    Gets a location for saving app data.

I'm soooo lost with C...

Kitty Hello

PDL_Err PDL_GetDataFilePath(const char *dataFileName, char *buffer, int bufferLen);
PDL_Err is int (had to look that up).

Code (glbasic) Select

// make sure there's no space between char and * ("char*" and "const char*" is recognized as DGStr string argument)
IMPORT "C" int PDL_GetDataFilePath(const char*dataFileName, char* buffer, int bufferLen);

LOCAL short$, long$
LOCAL ierr%
ierr% = PDL_GetDataFilePath(short$, long$, 1024)

IF ierr% = 0 // PDL_NOERROR
  // This is a problem now. If you want to get a string - see below

    STDOUT "Save to: >>"+long$+"<<\n"

not tested, but that might be it.

OK, when you have a const char*, DGStr strings work properly. It's just passing a pointer to the first character and the function can not change the contents of the string.
But! When you pass a "char*", the function is allowed to change the contents of the string buffer pointed to. This is a problem, because GLBasic DGStr strings internally have a "length" variable (which saves you from buffer overflows, speeds up many operations and allows you to have \0 characters in the string).
So, passing a DGStr to a char* will allocate 1024 bytes for the string, and pass that pointer. HOWEVER! If the length of the string was changed (which usually is always the case with char* arguments), you must tell GLBasic the new string length.
The DGStr::releasebuffer() function does this. It parses for the first \0 character in the string (which is an indicator for the end of a C-string) and sets this length internally.
If you use INLINE code and want a string buffer, you can call:
char* pString = mystring_Str.getbuffer( length_of_buffer );