|
That cannot be all your code. What´s nSize? And pCharText wasn´t initialized -> this should be a runtime error.
Anyway, try this
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0);
char* result = new char[erg];
erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, result, erg, 0, 0);
Souldrift
|
|
|
|
|
Hi SoulDrift,
I tried your code..its still showing the same "??" marks rather japanese texts..
please tell me where am going wrong..
am giving the code once again for your perusal..
const WCHAR* = L"sss";
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed
char* charText = new char[erg];
erg = WideCharToMultiByte(CP_ACP, 0, pText, -1, charText, erg, 0, 0); // then we convert
Thanks,
Rakesh
|
|
|
|
|
Your const WCHAR* doesn`t have a label. Does your compiler not have a problem with that?
I tried your code
const WCHAR* pText = L"sss";
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0);
char* charText = new char[erg];
erg = WideCharToMultiByte(CP_ACP, 0, pText, -1, charText, erg, 0, 0);
I works very nicely.
Souldrift
|
|
|
|
|
If the wide char character cannot be represented in the choosen codepage (in you case CP_ACP , i.e. The system default Windows ANSI codepage), then it is replaced by a default one, see WideCharToMultiByte documentation [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have to agree, if your developing on an American/english installed OS then CP_ACP will be Windows 1252, you want to change that to the Japanese/country specific page.
? is I remember right is 0x20, could be wrong.
I wrote a little app to convert UNICODE to Multibyte supporting the codepages we need, and if the wrong code page was chosen the character would be displayed as ??
basically I replaced CP_ACP with either 1250 or 1251 or 1252 etc..
Seemed to do the trick.
|
|
|
|
|
Rakesh5 wrote: ...but its showing ?? marks instead of unicode characters..
What is?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
First of all, using CP_ACP means you don't really have a control of the target code page - it depends on the users's settings. Sometimes it is exactly what you want, sometimes it is not.
Anyway, if we assume that your system locale is Windows CP 1252 and you have some Greek characters in Text , your code will try to convert Greek characters to CP1252 and because there is no mapping between the two scripts, you are going to get replacement characters (?) instead.
To convert Greek text from const wchar* value to char value to char* , you'll need to use CP1253 (not sure if I spelled the constant correctly) instead of CP_AP.
I hope it make sense.
|
|
|
|
|
This question is related to my previous question. As i mentioned before, my project contains many dlls and i am facing some ambiguity due to two dlls which contains same namespace names. So, i want to change the paths of these to dlls. But i dont know how to. Is their any option in visual studio c++ so that i can easily solve my problem?
http://nnhamane.googlepages.com/
|
|
|
|
|
LoadLibrary allows you to specify the full path to the dll.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I searched on net more about loadlibrary function but i haven't got anything. can you please tell me about how to use it in windows form?
http://nnhamane.googlepages.com/
|
|
|
|
|
|
Dear All,
I am having problem in converting ANSI to UNICODE but my code is not giving the desired result. Please have a look at the below code and advice me. When I compare the both strings, the strings are not equal after conversion. Please help me. Many thanks in advance.
char szData[2] ;
szData[0] = '♠';
szData[1] = 0;
wchar_t wszData1[] = L"♠";
wchar_t wszData2[2];
MultiByteToWideChar(CP_ACP, 0, szData, -1, wszData2, sizeof(wszData2) / sizeof wchar_t));
if (wcscmp(wszData1, wszData2) == 0)
MessageBox("Strings are equal!");
else
MessageBox("Strings are not equal.");
|
|
|
|
|
bhanu_reddy09 wrote: szData[0] = '♠';
How could it work?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
szData[0] = '♠';
wchar_t wszData1[] = L"♠"; These probably aren't doing what you're expecting. You should only have ASCII characters in source code, and use hex escapes for any characters outside the ASCII range. Depending on what that character is, and what your system's code page is, it may not even be possible to store the character in a non-Unicode string.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
Many thanks for your replies and suggestions. Actually I read a data from the serial device and it is having the ASCII value 6 and the corresponding character for 6 is '♠'. I just give the previous code as an example.
szData[0] = 0x06;
Now, I want to display the corresponding character (received from serial device) for 0x06 in the CEdit. Please advice me.
|
|
|
|
|
bhanu_reddy09 wrote: szData[0] = 0x06;//from a serial device
This is a ASCII control character (ACK , see [^]), i.e. not printable.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
This line
szData[0] = '♠';
produces a compiler warning doesn´t it?
♠ is not an ANSI character, afaik.
If you use an actual ansi sign like '®' in your code, it works properly.
Souldrift
|
|
|
|
|
Yes, I got compiler warning but how to change the character 0x06 to Unicode and display properly in the CEdit.
Thanks...
|
|
|
|
|
|
Dear All,
I have tried in many possible ways but I cannot display the character ♠. The real problem is that I need to change my entire project to UNICODE but this is not possible for right now. I also tried the below and even not working.
wchar_t display[2];
display[0] = 0x2660;
display[1] = 0;
edit.SetWindowText(display);
Is there any possible way to do simply. Many thanks in advance.
|
|
|
|
|
Hi All,
I am getting exception in code:
temp=g_pNsp->GetFolderFromID(_bstr_t(szEntryID));
pitem=temp->Items;
for (int i=1;i<=pitem->Count;i++)
pMail=pitem->Item(i);
Somtimes I am getting pMail=0x000000 but there is emails inside that folder,
I think item will not be MailItem. How to type cast of check for MailItem?
|
|
|
|
|
Are you sure you want to start the loop with i=1 ???
Souldrift
|
|
|
|
|
Hi,
I am reading data from a socket (i.e Array of BYTES, lpData)... I stored the incoming data in a buffer by using memcpy( bmpBuffer,lpData, dwCount);
Now I received some more data... ( data is coming continuously)...
Now I want to augment the bmpBuffer with the incoming data (till the time I receive the last packet,) What function I can call to augment the coming data in existing buffer.
To explain more, as we can add two strings str="Hello" + "Hi", How we can add data of two buffers
|
|
|
|
|
for instance:
char buf[100];
const char * str1 = "Hello";
const char * str2 = "Hi";
char * ptr = buf;
unsigned int len;
len = strlen(str1);
memcpy(ptr, str1, len);
ptr += len;
len = strlen(str2);
memcpy(ptr, str2, len);
ptr += len;
*ptr = '\0';
ptr++;
In a real world case, you probably want to allocate dynamically the memory buffer (and increase its size whenever it is needed).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
YES. U are right ...
BYTE* bmpBuffer=NULL;
bmpBuffer=(BYTE*)GlobalAlloc(GMEM_ZEROINIT,size);
memcpy( bmpBuffer,lpData, dwCount);
How I may increase the size of bmpBuffer at run time? Should I create a BIG buffer (upto 3 Mb to accomodate the incomimg image) or I can manage to increase the size of buffer on request as well...
|
|
|
|
|