Copy a CString to a Stream*
-
Hi! I am using an application that is using both managed to unmanaged code. I want to copy data from a CString to a Stream* (it may be MemoryStream or BufferedStream - whichever is faster). Can anyone help? Thanks Best regards, Alexandru Savescu
-
Hi! I am using an application that is using both managed to unmanaged code. I want to copy data from a CString to a Stream* (it may be MemoryStream or BufferedStream - whichever is faster). Can anyone help? Thanks Best regards, Alexandru Savescu
Convert the CString to a String* and then pass the String* to the Stream* Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
Convert the CString to a String* and then pass the String* to the Stream* Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
Sorry Nish, it does not work. Here is what I did:
CString str = "aaaa": String\* str1 = new String (str); MemoryStream\* mem1 = new MemoryStream (str1, false);
and the result is:
c:\Work\Test.cpp(332): error C2664: 'System::IO::MemoryStream::MemoryStream(unsigned char __gc[],bool)' : cannot convert parameter 1 from 'System::String __gc *' to 'unsigned char __gc[]'
I found an work arround that compiles and works but I hate it:
MemoryStream* mem = new MemoryStream (n) ;// specify the size
for (int i = 0; i < n; i++)
mem->WriteByte (str[i]);Do you have another solution? Thanks! Best regards, Alexandru Savescu
-
Sorry Nish, it does not work. Here is what I did:
CString str = "aaaa": String\* str1 = new String (str); MemoryStream\* mem1 = new MemoryStream (str1, false);
and the result is:
c:\Work\Test.cpp(332): error C2664: 'System::IO::MemoryStream::MemoryStream(unsigned char __gc[],bool)' : cannot convert parameter 1 from 'System::String __gc *' to 'unsigned char __gc[]'
I found an work arround that compiles and works but I hate it:
MemoryStream* mem = new MemoryStream (n) ;// specify the size
for (int i = 0; i < n; i++)
mem->WriteByte (str[i]);Do you have another solution? Thanks! Best regards, Alexandru Savescu
Try this:
CString str = "aaaa";
String* strText = new String (str);
Byte message[] = System::Text::Encoding::ASCII->GetBytes( strText );
MemoryStream* sStream = new MemoryStream( message );If you want to use diffrent encoding replace the bold text with the appropriate encoding like: Unicode, UTF7 or UTF8. I should work :)
43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c
-
Try this:
CString str = "aaaa";
String* strText = new String (str);
Byte message[] = System::Text::Encoding::ASCII->GetBytes( strText );
MemoryStream* sStream = new MemoryStream( message );If you want to use diffrent encoding replace the bold text with the appropriate encoding like: Unicode, UTF7 or UTF8. I should work :)
43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c
Thanks. This really looks like a solution. Best regards, Alexandru Savescu