views:

179

answers:

1

I am attempting to construct a very simple proof of concept that I can write a web service and actually call the service from a symbian environment. The service is a simple Hello service which takes a name in the form of a const char* and returns back a greeting of the form "hello " + name in the form of a char*. My question is, how do I convert a char* to a TPtrC16 so that I can use the console->Write function to print out the response to screen? I know I could search through the API and figure this out, but for a basic conceptual demo I'd rather not spend the time (not sure that Symbian is something I will ever work with again).

Thanks!

+1  A: 

If the const char* string is in US-ASCII, you can use TDes::Copy to copy it wrapped in a TPtrC8 to a 16-bit descriptor:

const char *who = "world";
TBuf<128> buf;
buf.Copy(TPtrC8((TText8*)who));
console->Printf(_L("hello %S\n"), &buf);

If it is in some other encoding, have a look at the charconv API in the SDK help.

laalto
There were a few things I had to fiddle with in order to get this to work. In the end the code looks like this: char *who = "world"; TUint8 *i((unsigned char*)who); TBuf<128> buf; buf.Copy(TPtrC8(i)); console->Printf(_L("hello %S\n"), I can probably refactor some of this to make it prettier, but it works for now. Thanks for the help!
Adam E