473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multibyte Character to WideChar

1,059 Top Contributor
Hello Everybody,

I am having a problem with converting value from multibyte to widechar

input variable is data
output variable is data_m
Expand|Select|Wrap|Line Numbers
  1. #define CP_SHIFT_JIS 932
  2.  
  3.  
  4. wchar_t *data_m;
  5.     data_m=(wchar_t*)malloc(sizeof(wchar_t)*1024);
  6.     memset(data_m, 0, sizeof(wchar_t)*1024);
  7.     MultiByteToWideChar(CP_SHIFT_JIS,0,data,-1,data_m,0);
  8.  
Sample Input:
Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2. Date: Wed, 13 Jan 2010 07:34:33 GMT
  3. Server: Apache/2.2.3 (Win32) PHP/5.2.0
  4. X-Powered-By: PHP/5.2.0
  5. Content-Length: 10
  6. Connection: close
  7. Content-Type: text/html
  8.  
  9. Ž„<br>“c’¬
  10.  
i was expecting output from the above code and value is

Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2. Date: Wed, 13 Jan 2010 07:34:33 GMT
  3. Server: Apache/2.2.3 (Win32) PHP/5.2.0
  4. X-Powered-By: PHP/5.2.0
  5. Content-Length: 10
  6. Connection: close
  7. Content-Type: text/html
  8.  
  9. 私<br>田町
  10.  
Let me know what am I missing....

Help is always appreciated.

regards,
Johny
Jan 12 '10 #1
1 4147
johny10151981
1,059 Top Contributor
Hello,
I solved the problem reading from a Japanese site. The code should be something like that
Expand|Select|Wrap|Line Numbers
  1.     wchar_t *data_m;
  2.  
  3.     int unilen = MultiByteToWideChar(CP_SHIFT_JIS, 0, data, -1, NULL, 0);
  4.   if (unilen <= 0) {
  5.     MessageBox(ghwnd,L"Error: charconv_win32: conversion error?\n",L"Error",MB_OK);
  6.  
  7.   }
  8.   if (unilen > UNICODE_BUFFER_SIZE) {
  9.     MessageBox(ghwnd,L"Error: charconv_win32: unicode buffer size Exited",L"Error",MB_OK);
  10.   }
  11.   /* convert source string to unicode */
  12.     data_m=(wchar_t*)malloc(unilen);
  13.     MultiByteToWideChar(CP_SHIFT_JIS, 0, data, -1, data_m, unilen);
  14.  
regard,
johny
Jan 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3080
by: lian | last post by:
Hi all, I want to write some UTF-8 Chinese characters to file with following php codes: <code> ....... $fp = fopen($filepath,'wb'); fwrite($fp,$utf8string,strlen($utf8string)); fclose($fp); ........
5
3102
by: Ma Siva Kumar | last post by:
Running postgresql-7.3.2-3 which came with Red Hat 9.0. Created a database with unicode encoding (in psql) as below: create database leatherlink with encoding='unicode' template=leatherlinkdb; leatherlinkdb is an existing database with the default encoding SQL_ASCII. When I insert Chinsese strings into the database, it is taken in and displayed back properly. But there is an issue:
18
5617
by: Zygmunt Krynicki | last post by:
Hello I've browsed the FAQ but apparently it lacks any questions concenring wide character strings. I'd like to calculate the length of a multibyte string without converting the whole string. Zygmunt PS: The whole multibyte string vs wide character string concept is broken IMHO since it allows wchar_t not to be large enough to contain a full character (rendering both types virtually the same). What's the point of
3
6858
by: yazan jab | last post by:
Is it true that Multibyte characters are : char arrays (witch represent a string from the basic characters set). In this case Wide characters are the way for encoding characters from the extended characters set. or Multibyte characters are: characters from the extended character set which need more than one byte to encode. And in this case wide
3
4236
by: Weiping | last post by:
Hi, while upgrade to 8.0 (beta3) we got some problem: we have a database which encoding is UNICODE, when we do queries like: select upper('ÖÐÎÄ'); --select some multibyte character, then postgresql response: ERROR: invalid multibyte character for locale
5
4853
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** GlobalInterfacePtr->GetName(bstr, bstrTNamePtr, &retVal);
1
6047
by: Marcel Ruff | last post by:
Hi, i have the question on how to determine the string length of a wide string and a multibyte string: 1. Number of letters (one letter may use three bytes) 2. Number of bytes In the code snippet *p points to one chinese word which i copy/pasted from my browser from some chinese homepage,
13
3542
by: TK | last post by:
Hi, how can I handle multibyte characters like ä, ü (german vowel mutation)? This does't work: switch(c) case 'ä': ... some action
2
1498
by: George2 | last post by:
Hello everyone, I need to know the wide character (unicode) and multibyte (UTF-8) values of a character string of czech. I personally know nothing about czech. Is the following approach correct? 1. I use L on the character string and watch memory to get the wide character representation of the character string in little endian form; 2. I change the computer region/language to czech, and use function WideCharToMultiByte, and use CP_ACP...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.