Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can somebody tell that how can we convert LPVOID to UNICODE i.e. Convert LPVOID to wchar_t* / TCHAR* ? We are getting data in a void pointer but need to display as Unicode (ARABIC). We have tried following but it does not work:
wchar_t* Function(void* source, int ilen)
{
  wchar_t* l_pDestination = new wchar_t[ilen+1];
  memset(l_pDestination,0,ilen+1);
  mbstowcs(l_pDestination,source,ilen+1);
  return l_pDestination;
}

Please help.
Posted
Updated 11-Dec-09 1:47am
v4

That really depends on what is contained in the LPVOID. LPVOID is basically a pointer that points to something which is not defined. So, if the contents are a unicode string, you can simply cast your pointer:
TCHAR* unicodeString = (TCHAR*)myPointer;


But of course, this really depends no what you have put in your pointer...

EDIT: after you edited your message, I still have the same question: to what is pointing the source pointer exactly ? That's the key to give you a correct answer.
Furthermore, you say it doesn't work, can you explain what you get and what you expected ?
 
Share this answer
 
v2
If you're sure that the LPVOID is actually pointing to a Unicode string, then there's no "conversion" needed. Just a C-Style cast will do.

If you're sure that the pointer is pointing to ANSI style string, then you could convert it to Unicode using one of the many conversion mechanisms (ATL macros come to mind instantly)

If you are unsure of what the pointer is pointing to, you're not going to convert anything.
 
Share this answer
 
Thanks for quick reply.
We are developing an application in VC++ 8.0 for PDA (Windows Mobile 5). It has SYBASE as backend on PDA. If data stored in database is in ENGLISH language then it is fetching data in proper format but if data stored in database is in ARABIC language then it is fetching data in JUNK characters.

struct sqlvar
{
short int sqltype;
short int sqllen;
void *sqldata;
short int *sqlind;
struct sqlname sqlname;
};

SYBASE is filling the fetched data in sqldata memeber of above pre-defined stucture of SYBASE.
If data is in ARABIC in database then we are sure that we need to convert it into UNICODE before display.
 
Share this answer
 
Thanks for quick reply.
We are developing an application in VC++ 8.0 for PDA (Windows Mobile 5). It has SYBASE as backend on PDA. If data stored in database is in ENGLISH language then it is fetching data in proper format but if data stored in database is in ARABIC language then it is fetching data in JUNK characters.

struct sqlvar
{
short int sqltype;
short int sqllen;
void *sqldata;
short int *sqlind;
struct sqlname sqlname;
};

SYBASE is filling the fetched data in sqldata memeber of above pre-defined stucture of SYBASE.
If data is in ARABIC in database then we are sure that we need to convert it into UNICODE before display.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900