PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Convert char * to unsigned short *

Ok, here is my problem.  It's not a very big problem, but it would my my port look nicer if it displayed words instead of hyrogliphics when an error came up.  It gets annoying having to look in the log file all of the time.  But anyways.  Let say you have...

Code:

char *PtrToString
unsigned short *NeedsToBePtrToString


How would I get NeedsToBePtrToString
to have the pointer to the string that PtrToString is currently the pointer to.  One thought that I had was TEXT(), but that seems to only work with thinks like

Code:
TEXT("This is a string, and not a variable containing a string")


I tried putting everything from char, char *, &char (I was really desrite with that one), and I can't get it to work.  So, I think that there must be another way.  Any thoughts?
Sorry, I accidently posted it twice.  Notice the -1 posts in the one above this.  I deleted my post, but it didn't delete the thread.
Setting another variable to the same value works like so:
char * pchFoo;
unsigned short * pusBar;

pusBar = (unsigned short *)pchFoo;

Note the use of a cast so that the compiler won't complain about the type difference between the two variables.  The above line of code has done nothing more than store the address pointed to by pchFoo into pusBar.  Nothing has happened to the data that pchFoo points to.

However this is probably not what you're actually trying to do.  What you want to do (and I'm mind reading here) is since your app contains character strings that are 8-bit characters, you would like to display them using some API that expects 16-bit (WCHAR) wide characters.  The cast used above isn't going to do this since the underlying data that pusBar points to hasn't changed - you're still going to get the hiroglyphics that you hate so much.

So what you want to do is convert an 8-bit character string to a 16-bit character string.  Use MultiByteToWideChar.

If this isn't what you wanted to do, then clarify your question a bit and we'll help you out.
Thanks, I'll give that second one a try.  I knew about casting, but your right, that won't help me at all.  I think your mind ready skills may be on to something.  I'll give that MultiByteToWideChar thing a try as soon as I get a chance.
Just in case you guys were wondering, the function to use is mbstowcs().  This allows you to quickly convert multibyte strings (used by win 9x) into unicode format wich is the format used by WinCE.