Click here to Skip to main content
15,899,314 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Including winsock2.h problem Pin
Budric B.19-Jul-07 10:59
Budric B.19-Jul-07 10:59 
QuestionOptimizing hard drive write performance Pin
TragicComic19-Jul-07 8:02
TragicComic19-Jul-07 8:02 
AnswerRe: Optimizing hard drive write performance Pin
James R. Twine19-Jul-07 8:12
James R. Twine19-Jul-07 8:12 
GeneralRe: Optimizing hard drive write performance Pin
Perspx19-Jul-07 10:38
Perspx19-Jul-07 10:38 
GeneralRe: Optimizing hard drive write performance Pin
TragicComic19-Jul-07 11:38
TragicComic19-Jul-07 11:38 
AnswerRe: Optimizing hard drive write performance Pin
Paresh Chitte19-Jul-07 19:05
Paresh Chitte19-Jul-07 19:05 
GeneralRe: Optimizing hard drive write performance Pin
TragicComic20-Jul-07 7:37
TragicComic20-Jul-07 7:37 
QuestionConverting strings using WideCharToMultiByte Pin
mhand7519-Jul-07 7:42
mhand7519-Jul-07 7:42 
I am having trouble converting from a unicode string to a single-byte string. Our application is a C++ COM server that is called from a .NET client. The COM object needs to be able to convert the strings it receives from Unicode to single-byte. To do this, I wrote this function:

CString ConvertBSTRToString(BSTR bstrSrc)
{
CString strDest = "";
char* szDest = NULL;
int nSrcLen = 0;
int nDestLen = 0;

nSrcLen = lstrlenW(bstrSrc);
if (nSrcLen > 0)
{
int nCodePage = GetACP();
nDestLen = WideCharToMultiByte(nCodePage, 0, bstrSrc, nSrcLen, NULL, 0, NULL, NULL);
if (nDestLen > 0)
{
szDest = (char*)HeapAlloc(GetProcessHeap(), 0, nDestLen + 1);
WideCharToMultiByte(nCodePage, 0, bstrSrc, nSrcLen, szDest, nDestLen, NULL, NULL);
szDest[nDestLen] = '\0';
strDest = szDest;
HeapFree(GetProcessHeap(), 0, szDest);
}
}

return strDest;
}

I initially tested this function on my system, which is setup with the Latin 1 code page (1252). I also setup my machine to allow for Russian input (1251). To test, I changed the above function to hard-code the code page to 1251 (instead of the GetACP() call). When I pass a string from the .NET client to the COM object, it performs the conversion to single-byte correctly. Of course the converted string does not look like the original Russian string since the code page running on my machine is 1252, but comparing the 1251 and 1252 code page shows that the characters in the string have the correct value.

The problem comes in when I try to test the COM object on a Russian OS. When I do this the call to WideCharToMultiByte simply returns "?????". I assume the "?" is the default character the routine uses when it cannot perform the conversion correctly. I don't understand why this conversion fails? I verified that the code page being returned by GetACP() on the Russian system is 1251.

I also did another test where I hard-coded the code page used in the conversion to be ISO 8859-5 (28595) on the Russian system. The conversion here was successful. I don't understand why the conversion would work for this Cyrillic code page, but not the Cyrillic code page that is the active code page on the system.

Thanks for any advice. I know there is something I'm just not understanding about how this works.


AnswerRe: Converting strings using WideCharToMultiByte Pin
DevMentor.org22-Jul-07 19:38
DevMentor.org22-Jul-07 19:38 
Questionhow can I launch another application( like notepad.exe ) in my VC Pin
LeeeNN19-Jul-07 7:22
LeeeNN19-Jul-07 7:22 
AnswerRe: how can I launch another application( like notepad.exe ) in my VC Pin
Mark Salsbery19-Jul-07 7:27
Mark Salsbery19-Jul-07 7:27 
GeneralRe: how can I launch another application( like notepad.exe ) in my VC Pin
mid=574119-Jul-07 7:28
mid=574119-Jul-07 7:28 
GeneralRe: how can I launch another application( like notepad.exe ) in my VC Pin
Mark Salsbery19-Jul-07 7:34
Mark Salsbery19-Jul-07 7:34 
AnswerRe: how can I launch another application( like notepad.exe ) in my VC Pin
Michael Dunn19-Jul-07 7:40
sitebuilderMichael Dunn19-Jul-07 7:40 
GeneralRe: how can I launch another application( like notepad.exe ) in my VC Pin
LeeeNN19-Jul-07 7:58
LeeeNN19-Jul-07 7:58 
GeneralRe: how can I launch another application( like notepad.exe ) in my VC Pin
Hamid_RT31-Jul-07 9:21
Hamid_RT31-Jul-07 9:21 
QuestionNibbles, Bits, bytes and somehow a number! Pin
Steven Wybraniec19-Jul-07 6:15
Steven Wybraniec19-Jul-07 6:15 
AnswerRe: Nibbles, Bits, bytes and somehow a number! Pin
led mike19-Jul-07 6:24
led mike19-Jul-07 6:24 
AnswerRe: Nibbles, Bits, bytes and somehow a number! Pin
mid=574119-Jul-07 6:35
mid=574119-Jul-07 6:35 
QuestionDesktop Window Manager (DWM) problem.. Pin
Perspx19-Jul-07 5:38
Perspx19-Jul-07 5:38 
QuestionRegular DLL with Doc/View architecture Pin
Andy H19-Jul-07 5:22
Andy H19-Jul-07 5:22 
AnswerRe: Regular DLL with Doc/View architecture Pin
led mike19-Jul-07 6:31
led mike19-Jul-07 6:31 
AnswerRe: Regular DLL with Doc/View architecture Pin
Mark Salsbery19-Jul-07 7:09
Mark Salsbery19-Jul-07 7:09 
GeneralRe: Regular DLL with Doc/View architecture Pin
led mike19-Jul-07 8:25
led mike19-Jul-07 8:25 
GeneralRe: Regular DLL with Doc/View architecture Pin
Mark Salsbery19-Jul-07 10:34
Mark Salsbery19-Jul-07 10:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.