-
1. Re: How to read and write strings?
dheeraj_c May 20, 2011 4:27 AM (in response to dheeraj_c)Hi All,
I used putStringProc() to write the string in WriteScriptParameters() and GetStringLength() and GetString() functions to retrieve the string. The issue I'm facing is that the string is truncated when I read back the string. For Example, if I saved "abcd", then I get back "bcd". If the string is big then the string gets truncated from both ends. I used following code to read & write :
Read:
(sPSActionDescriptor->GetStringLength(actionDescriptor,
keyText,
&stringLength));
std::vector<char> vc(stringLength+1);
(sPSActionDescriptor->GetString(actionDescriptor, keyText, &vc[0], (uint32)vc.size()));Write:
writeProcs->putStringProc(token, keyText, (const unsigned char*)"abcd");
What might be the problem? Am I doing it the wrong way?
Thanks,
Dheeraj
-
2. Re: How to read and write strings?
Tom Ruark May 20, 2011 1:37 PM (in response to dheeraj_c)Use a pascal string, first byte is the length, or use the new suite based action procs for char *'s. Not obvious but the 255 usuall gives it away. You cannot use strings larger than 255 characters with this routine.
/**
* Stores an ID and corresponding string (\c typeChar) into a descriptor structure.
* @param PIWriteDescriptor The descriptor to write into
* @param DescriptorKeyID The key to write.
* @param ConstStr255Param The string to write.
* @returns Non-zero error if failure.
*/
typedef
MACPASCAL OSErr (*PutStringProc)(PIWriteDescriptor, DescriptorKeyID, ConstStr255Param);
-
3. Re: How to read and write strings?
dheeraj_c May 20, 2011 9:06 PM (in response to Tom Ruark)Thanks for the info Tom Ruark. Can you please tell me wich routine to use if I want to save more than 255 characters?
-
4. Re: How to read and write strings?
Tom Ruark May 24, 2011 10:34 AM (in response to dheeraj_c)See PIActions.h
You will need to acquire this suite
PSActionDescriptorProcs
and use these routines
/**
char* cstrValue);
/**
* Gets a string (\c typeChar) from a descriptor for a given key.
* @param descriptor The descriptor from which to read.
* @param key The key to read.
* @param cstrValue [OUT] The string returned.
* @param maxLength The maximum number of characters to return.
* @returns Non-zero error if failure
*/
SPAPI OSErr (*GetString)(PIActionDescriptor descriptor, DescriptorKeyID key,
char* cstrValue, uint32 maxLength);
If you are in a filter you will need to convert from the handle descriptor to the PIActionDescriptor. See the Hidden.cpp source file on how to do that.
AsHandle
HandleToDescriptor
P.S. Is it just me or is this a horrible editor for posting messages!!!
* Puts a string value (\c typeChar) into a descriptor for a given key.
* @param descriptor The descriptor in which to write.
* @param key The key to write.
* @param value The string to write.
* @returns Non-zero error if failure
*/
SPAPI OSErr (*PutString)(PIActionDescriptor descriptor, DescriptorKeyID key,
-
5. Re: How to read and write strings?
Tom Ruark May 24, 2011 10:35 AM (in response to Tom Ruark)I apologize for the reply above. Is this a horrible editor or what!!!



