Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Fri, 15 Aug 2008 20:20:03 -0700,    group: microsoft.public.win32.programmer.ui        back       


Single byte to double byte   
Greetings,

1) I want to do a file read in which I read single byte but store in a 
double byte buffer.  Is there a way to do a direct read that will fill a 
double-byte buffer with the results of my single byte read?

2) Similarly, I have a very long single byte string in a buffer in memory.  
What is the fastest way to get that into a double-byte-defined buffer?

Thanks in advance,
Tony Duff
date: Fri, 15 Aug 2008 20:20:03 -0700   author:   Tony Duff

Re: Single byte to double byte   
> 1) I want to do a file read in which I read single byte but store in a 
> double byte buffer.  Is there a way to do a direct read that will fill a 
> double-byte buffer with the results of my single byte read?
> 
> 2) Similarly, I have a very long single byte string in a buffer in memory.  
> What is the fastest way to get that into a double-byte-defined buffer?


What do you mean by "double byte buffer"?

UTF-16? that would be "Unicode UTF-16 buffer" or "wide character buffer"
or something like that. In this case you will have to know the code page
of the "single byte string" and convert using MultiByteToWideChar.

"Double byte" has a very clear meaning (refers to a certain types of 
encodings, used for Chinese, Japanese, Korean), and it is confusing
if used otherwise.

Sorry, just guessing, but asking the question helps a lot.


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Fri, 15 Aug 2008 21:05:56 -0700   author:   Mihai N.

Re: Single byte to double byte   
Greetings,

1) I want to do a file read in which I read single byte but store in a 
wchar_t buffer.  Is there a way to do a direct read that will fill a 
wchar_t buffer with the results of my single byte read?  I do not need to do 
any code page conversion (for my purposes, the value of the single byte read 
can be used as is in the wchar_t buffer.)

2) Similarly, I have a very long single byte string in a buffer in memory.  
What is the fastest way to get that into a wchar_t-defined buffer?

Thanks in advance,
Tony Duff


"Mihai N." wrote:

> > 1) I want to do a file read in which I read single byte but store in a 
> > double byte buffer.  Is there a way to do a direct read that will fill a 
> > double-byte buffer with the results of my single byte read?
> > 
> > 2) Similarly, I have a very long single byte string in a buffer in memory.  
> > What is the fastest way to get that into a double-byte-defined buffer?
> 
> 
> What do you mean by "double byte buffer"?
> 
> UTF-16? that would be "Unicode UTF-16 buffer" or "wide character buffer"
> or something like that. In this case you will have to know the code page
> of the "single byte string" and convert using MultiByteToWideChar.
> 
> "Double byte" has a very clear meaning (refers to a certain types of 
> encodings, used for Chinese, Japanese, Korean), and it is confusing
> if used otherwise.
> 
> Sorry, just guessing, but asking the question helps a lot.
> 
> 
> -- 
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
date: Sat, 16 Aug 2008 07:03:01 -0700   author:   Tony Duff

Re: Single byte to double byte   
> 1) I want to do a file read in which I read single byte but store in a 
> wchar_t buffer.  Is there a way to do a direct read that will fill a 
> wchar_t buffer with the results of my single byte read?  I do not need to
> do any code page conversion (for my purposes, the value of the single byte
> read can be used as is in the wchar_t buffer.)

That only works without conversion only if all characters in the input buffer
are plain ASCII (below 128). So no accented characters, smart quotes,
copyright or registration marks, etc.
And you are sure that software will never have to deal with that kind of data 
:-)

If that is the case, I don't know of any way to achieve that, except the dumb
copy char by char with cast to wchar_t.

If you read from a file, you might avoid reading it in memory by
memory-mapping it. But you have to measure the performance to see it it
is better.


> 2) Similarly, I have a very long single byte string in a buffer in memory.  
> What is the fastest way to get that into a wchar_t-defined buffer?
With the same warnings as as above about ASCII,
char by char copy with cast to wchar_t.
I can't think of any other way.

You might also try WideChartoMultiByte with code page 20127 (ASCII), see if
the OS can do something better (although I doubt) it can beat just a copy.


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Sat, 16 Aug 2008 22:48:51 -0700   author:   Mihai N.

Re: Single byte to double byte   
ASCII codepage translation is cool! It even converts Cyrillic letters!

"Mihai N."  сообщил/сообщила в новостях следующее: news:Xns9AFCE813CA136MihaiN@207.46.248.16...
> 
> You might also try WideChartoMultiByte with code page 20127 (ASCII), see if
> the OS can do something better (although I doubt) it can beat just a copy.
date: Sun, 31 Aug 2008 09:52:22 +0700   author:   st ldomain

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us