Click here to Skip to main content
15,893,161 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Loading Variable in EditBox Pin
Archer28230-Jul-04 12:57
Archer28230-Jul-04 12:57 
GeneralRe: Loading Variable in EditBox Pin
arunforce30-Jul-04 13:13
arunforce30-Jul-04 13:13 
GeneralRe: Loading Variable in EditBox Pin
Jaime Stuardo30-Jul-04 13:52
Jaime Stuardo30-Jul-04 13:52 
GeneralRe: Loading Variable in EditBox Pin
arunforce30-Jul-04 14:25
arunforce30-Jul-04 14:25 
GeneralNotify Messages Pin
Kosk30-Jul-04 11:47
Kosk30-Jul-04 11:47 
GeneralRe: Notify Messages Pin
Renjith Ramachandran30-Jul-04 18:18
Renjith Ramachandran30-Jul-04 18:18 
GeneralUnicode and cstring Pin
pnpfriend30-Jul-04 11:05
pnpfriend30-Jul-04 11:05 
GeneralRe: Unicode and cstring Pin
Gary R. Wheeler30-Jul-04 12:19
Gary R. Wheeler30-Jul-04 12:19 
First of all, AllocSysString() returns a BSTR, which is a string type used by COM (among other things). You probably don't want this, if you're just converting string types.

If you are using MFC 7.0 or 7.1 (corresponding to VS .NET 2002 or 2003), you can do the following:
CString astring;
CStringA astring_A(astring);
const char *k = astring_A.GetBuffer();
CStringA is the char form of CString, and includes a constructor that automatically converts from the _TCHAR form (CString) if necessary. I believe that, by default, the conversion uses the CP_ACP code page.

If you are using VC6, it's a little harder:
CString astring;
int astring_A_size = (astring.GetLength() * sizeof(_TCHAR)) + 1;
char *astring_A = new char[astring_A_size];
::WideCharToMultiByte(CP_ACP,0,(LPCWSTR)astring,-1,astring_A,astring_A_size,NULL,NULL);
const char *k = astring_A;
WideCharToMultiByte is an API function that converts a wide character string to a multibyte character string according to a specified code page.

Please note that my code here is an example only. If you are using other code pages, you'll need to be more careful. Also, my allocation for astring_A in the second example is only an approximation. WideCharToMultiByte can also be used to calculate the size of the MBCS string, so that you can allocate exactly the right amount of buffer.


Software Zen: delete this;
GeneralRe: Unicode and cstring Pin
Michael Dunn30-Jul-04 14:48
sitebuilderMichael Dunn30-Jul-04 14:48 
GeneralRe: Unicode and cstring Pin
PJ Arends30-Jul-04 23:15
professionalPJ Arends30-Jul-04 23:15 
Generalchar str[256] AND char *str = new char(256) Pin
Igor Mihailov30-Jul-04 10:44
Igor Mihailov30-Jul-04 10:44 
GeneralRe: char str[256] AND char *str = new char(256) Pin
Kosk30-Jul-04 12:01
Kosk30-Jul-04 12:01 
GeneralRe: char str[256] AND char *str = new char(256) Pin
Gary R. Wheeler30-Jul-04 12:24
Gary R. Wheeler30-Jul-04 12:24 
GeneralRe: char str[256] AND char *str = new char(256) Pin
Archer28230-Jul-04 13:03
Archer28230-Jul-04 13:03 
GeneralSetting Wallpaper Pin
Archer28230-Jul-04 10:40
Archer28230-Jul-04 10:40 
GeneralSPIF_SENDCHANGE ? Pin
bikram singh31-Jul-04 16:14
bikram singh31-Jul-04 16:14 
GeneralInitialising a items in a structure Pin
Grahamfff30-Jul-04 10:35
Grahamfff30-Jul-04 10:35 
GeneralRe: Initialising a items in a structure Pin
Kosk30-Jul-04 11:54
Kosk30-Jul-04 11:54 
GeneralRe: Initialising a items in a structure Pin
Grahamfff30-Jul-04 21:07
Grahamfff30-Jul-04 21:07 
GeneralRe: Initialising a items in a structure Pin
Gary R. Wheeler30-Jul-04 12:33
Gary R. Wheeler30-Jul-04 12:33 
GeneralRe: Initialising a items in a structure Pin
Grahamfff30-Jul-04 21:32
Grahamfff30-Jul-04 21:32 
GeneralRe: Initialising a items in a structure Pin
Gary R. Wheeler31-Jul-04 1:55
Gary R. Wheeler31-Jul-04 1:55 
GeneralRe: Initialising a items in a structure Pin
Grahamfff2-Aug-04 10:50
Grahamfff2-Aug-04 10:50 
GeneralRe: Initialising a items in a structure Pin
Sheff30-Jul-04 22:01
Sheff30-Jul-04 22:01 
GeneralDisable maxmize minimize window Pin
magee8130-Jul-04 10:20
sussmagee8130-Jul-04 10:20 

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.