Click here to Skip to main content
16,007,932 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralOpen File -- Very Hard Problem Pin
duvaft19-Dec-02 3:20
duvaft19-Dec-02 3:20 
GeneralRe: Open File -- Very Hard Problem Pin
stanley guan2-Jan-03 17:54
stanley guan2-Jan-03 17:54 
Generalhelp Pin
imran_rafique16-Dec-02 6:54
imran_rafique16-Dec-02 6:54 
GeneralRe: help Pin
Anders Molin20-Dec-02 12:06
professionalAnders Molin20-Dec-02 12:06 
GeneralConvertiong Managed Strings to Unmanaged Chars Pin
KBL14-Dec-02 18:37
KBL14-Dec-02 18:37 
GeneralRe: Convertiong Managed Strings to Unmanaged Chars Pin
Nish Nishant17-Dec-02 14:48
sitebuilderNish Nishant17-Dec-02 14:48 
GeneralConverting and Concatenating Strings Pin
KBL13-Dec-02 22:01
KBL13-Dec-02 22:01 
GeneralRe: Converting and Concatenating Strings Pin
Jeff J14-Dec-02 7:12
Jeff J14-Dec-02 7:12 
There are no overloaded + or += operators for Strings in MC++, so one must use the plain member functions:

String *String1 = S"C:\\files";<br />
String *String2 = S"data.txt";<br />
<br />
String1 = String::Concat(String1, S"\\", String2);<br />
<br />
//or much less efficiently...<br />
//String1 = String1->Insert(String1->Length, S"\\");<br />
//String1 = String1->Insert(String1->Length, String2);<br />
<br />
char achCStr[20];<br />
<br />
wchar_t *pGuts = PtrToStringArray(String1);<br />
int iChrs = ::WideCharToMultiByte(CP_ACP, 0, pGuts, String1->Length, achCStr, 20, NULL, NULL);<br />
achCStr[iChrs] = '\0';


PtrToStringArray() was posted earlier at http://www.codeproject.com/script/comments/forums.asp?forumid=3785&select=364715#xx364715xx[^] , and explained 2 posts earlier in that thread.

String::Concat() returns a concatenated copy of between 2 and 4 strings, and since the lengths of all the Strings are calculated prior to assembling them into the returned String, should avoid multiple temporary copies usually associated with concatenation (nice!). Insert() works like strcat() when the start position is the same as the original String's length, but as you can see it requires an extra temporary String copy Frown | :(

It's undocumented, but when I do something like the above, I pass 'String1->Length+1' in WideCharToMultiByte(), which avoids having to add the terminating null character afterwards. Like CString and std::string, CLR Strings seem to always have a terminating null appended to them, and I have never seen a case where they haven't.

Cheers
GeneralWindows Forms Open File Dialog Pin
KBL13-Dec-02 6:46
KBL13-Dec-02 6:46 
GeneralRe: Windows Forms Open File Dialog Pin
Nish Nishant17-Dec-02 14:50
sitebuilderNish Nishant17-Dec-02 14:50 
GeneralLooping sending me loopy! Pin
dyerstein13-Dec-02 3:04
dyerstein13-Dec-02 3:04 
GeneralRe: Looping sending me loopy! Pin
monrobot1313-Dec-02 4:09
monrobot1313-Dec-02 4:09 
GeneralRe: Looping sending me loopy! Pin
Jeff J13-Dec-02 10:07
Jeff J13-Dec-02 10:07 
GeneralMemory leak in managed class!!! Pin
Ahmet Orkun GEDiK12-Dec-02 23:24
sussAhmet Orkun GEDiK12-Dec-02 23:24 
GeneralRe: Memory leak in managed class!!! Pin
monrobot1313-Dec-02 4:12
monrobot1313-Dec-02 4:12 
GeneralRe: Memory leak in managed class!!! Pin
Jeff J13-Dec-02 9:49
Jeff J13-Dec-02 9:49 
GeneralConversion problem Pin
Anthony_Yio12-Dec-02 15:12
Anthony_Yio12-Dec-02 15:12 
GeneralRe: Conversion problem Pin
Jeff J12-Dec-02 22:12
Jeff J12-Dec-02 22:12 
GeneralRe: Conversion problem Pin
Anthony_Yio12-Dec-02 22:28
Anthony_Yio12-Dec-02 22:28 
GeneralRe: Conversion problem Pin
Jeff J13-Dec-02 8:57
Jeff J13-Dec-02 8:57 
GeneralHelp!!!!! Pin
dyerstein11-Dec-02 9:20
dyerstein11-Dec-02 9:20 
GeneralObject * to (void *,size_t) and back Pin
Anonymous11-Dec-02 4:55
Anonymous11-Dec-02 4:55 
GeneralRe: Object * to (void *,size_t) and back Pin
Anonymous15-Dec-02 22:50
Anonymous15-Dec-02 22:50 
GeneralMFC app - porting Pin
MattG10-Dec-02 8:35
MattG10-Dec-02 8:35 
GeneralRe: MFC app - porting Pin
Maximilien10-Dec-02 8:50
Maximilien10-Dec-02 8:50 

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.