Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Does anybody know how to convert an unsigned short* to a char* in BREW?

Converting the pointer is not the issue, that can be accomplished with a simple cast. I'm guessing your problem is with converting the data that the pointers point to.
If you are trying to convert from an AECHAR-based string to a char-based string, try using WSTRTOSTR().

Converting the pointer is not the issue, that can be accomplished with a simple cast. I'm guessing your problem is with converting the data that the pointers point to.
If you are trying to convert from an AECHAR-based string to a char-based string, try using WSTRTOSTR().

Really my problem is related to my previous post.
I read the line of a text file. But I coudn't save it in char or AECHAR variable. In this code I try to save the read line in a AECHAR variable called output.
The compiler returns:
c(436): warning C4133: 'function' : incompatible types - from 'unsigned short *' to 'const char *'
c(436): warning C4133: 'function' : incompatible types - from 'char *' to 'unsigned short *'
IFile * pIFile;
ISourceUtil * pMesu;
ISource * pISource;
IGetLine * pIGetLine;
GetLine *gl;
int rv;
AECHAR *output;
if ((output = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
return;
if ((gl = (GetLine *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
return;
//Create a ISourceUtil
if (ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pMesu))
return;
//Create an IFileMgr
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr))
return;
//Open the associated file
if ((pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, "xfile1.txt", _OFM_READ)) == NULL)
{
IFILEMGR_Release(pMe->m_pIFileMgr);
pMe->m_pIFileMgr = NULL;
return;

//Get a Source from a Stream, which was cast from a File
if (ISOURCEUTIL_SourceFromAStream(pMesu,(IAStream*)pIFile,&pISource))
return;
//Get a GetLine from a Source
if (ISOURCEUTIL_GetLineFromSource(pMesu, pISource, 5000, &pIGetLine))
return;
//Get a line of text
rv = IGETLINE_GetLine(pIGetLine, gl, IGETLINE_LF);
DBGPRINTF(gl->psz);// the read line is saved in gl->psz and I want convert it to AECHAR
STR_TO_WSTR(output, gl->psz, TEXT_BUFFER_SIZE);//line 436
DBGPRINTF("output (%s\n)", output);
FREE(output);
FREE(gl);

Really my problem is related to my previous post.
I read the line of a text file. But I coudn't save it in char or AECHAR variable. In this code I try to save the read line in a AECHAR variable called output.
The compiler returns:
c(436): warning C4133: 'function' : incompatible types - from 'unsigned short *' to 'const char *'
c(436): warning C4133: 'function' : incompatible types - from 'char *' to 'unsigned short *'
IFile * pIFile;
ISourceUtil * pMesu;
ISource * pISource;
IGetLine * pIGetLine;
GetLine *gl;
int rv;
AECHAR *output;
if ((output = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
return;
if ((gl = (GetLine *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
return;
//Create a ISourceUtil
if (ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pMesu))
return;
//Create an IFileMgr
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr))
return;
//Open the associated file
if ((pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, "xfile1.txt", _OFM_READ)) == NULL)
{
IFILEMGR_Release(pMe->m_pIFileMgr);
pMe->m_pIFileMgr = NULL;
return;

//Get a Source from a Stream, which was cast from a File
if (ISOURCEUTIL_SourceFromAStream(pMesu,(IAStream*)pIFile,&pISource))
return;
//Get a GetLine from a Source
if (ISOURCEUTIL_GetLineFromSource(pMesu, pISource, 5000, &pIGetLine))
return;
//Get a line of text
rv = IGETLINE_GetLine(pIGetLine, gl, IGETLINE_LF);
DBGPRINTF(gl->psz);// the read line is saved in gl->psz and I want convert it to AECHAR
STR_TO_WSTR(output, gl->psz, TEXT_BUFFER_SIZE);//line 436
DBGPRINTF("output (%s\n)", output);
FREE(output);
FREE(gl);

A quick look at the API documentation would tell you that the STRTOWSTR() function takes the char* as the first parameter and the AECHAR* as the second.
You have put them in the wrong order.

A quick look at the API documentation would tell you that the STRTOWSTR() function takes the char* as the first parameter and the AECHAR* as the second.
You have put them in the wrong order.

Thanks nparrish, I corrected the order of the parameters in the STR_TO_WSTR()
now I have:
STR_TO_WSTR(gl->psz,output, TEXT_BUFFER_SIZE)
and compiles without problems

Thanks nparrish, I corrected the order of the parameters in the STR_TO_WSTR()
now I have:
STR_TO_WSTR(gl->psz,output, TEXT_BUFFER_SIZE)
and compiles without problems