473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converting from System::String to std::string while keeping nulls.

Hi,
I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper
around some C++ LIBS. I've created some classes that contains a pointer to
the LIB classes and everthing seems to compile well.
The problem is getting a std::string from System::String and still
preserving the nulls. System::String is a base64 encoded string of a series
of bytes. When I convert it back to a string from base64 representation, the
NULLs inside the decoded string makes it smaller. Suppose the decoded string
is $BFGDHF\0GDFS, I get $BFGDHF and the NULL char is interpretted as
termination char. But I need to get a string with all the nulls and data.

thanks

Jul 24 '07 #1
2 3069
"Abhimanyu Sirohi" <Ab*************@discussions.microsoft.comwrote in
message news:9C**********************************@microsof t.com...
Hi,
I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper
around some C++ LIBS. I've created some classes that contains a pointer to
the LIB classes and everthing seems to compile well.
The problem is getting a std::string from System::String and still
preserving the nulls. System::String is a base64 encoded string of a
series
of bytes. When I convert it back to a string from base64 representation,
the
NULLs inside the decoded string makes it smaller. Suppose the decoded
string
is $BFGDHF\0GDFS, I get $BFGDHF and the NULL char is interpretted as
termination char. But I need to get a string with all the nulls and data.
Use the std::string constructor that takes a pair of iterators rather than
the one that takes a (w)char*. You can supply pointers to the begining and
one-past-the-end of the buffer containing the decoded bytes as the
"iterators" for the constructor.

-cd
Jul 24 '07 #2
use bytes[] instead of strings.

--
Sheng Jiang
Microsoft MVP in VC++
"Abhimanyu Sirohi" <Ab*************@discussions.microsoft.comwrote in
message news:9C**********************************@microsof t.com...
Hi,
I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper
around some C++ LIBS. I've created some classes that contains a pointer to
the LIB classes and everthing seems to compile well.
The problem is getting a std::string from System::String and still
preserving the nulls. System::String is a base64 encoded string of a
series
of bytes. When I convert it back to a string from base64 representation,
the
NULLs inside the decoded string makes it smaller. Suppose the decoded
string
is $BFGDHF\0GDFS, I get $BFGDHF and the NULL char is interpretted as
termination char. But I need to get a string with all the nulls and data.

thanks

Jul 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jim Langston | last post by:
#include <string> int main () { std::string MyString = "Testing"; MyString = " " + MyString; } This works in Microsoft Visual C++ .net 2003
0
by: Vasco Lohrenscheit | last post by:
Hello, i can convert between the different string types (String constructor and Marshal::StringToHGlobalAnsi), but have problems with endline '\n'. It seems that System::String needs "\r\n"...
1
by: Maxwell | last post by:
Hello, I having having oodles of trouble using the std lib in my MC++ (VS.NET 2003) Class library. I figured out a simple sample to reproduce the errors I am having. Create a MC++ (VS.NET 2003)...
2
by: John Swan | last post by:
Hello. I cannot seem to find any documentation upon the STL string. I am simply trying to transfer the contents of a std::string to a System::String where I am coming into difficulties. Any...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
5
by: Rob Dob | last post by:
I am trying to set the NullValue within the Column properties of my Dataset in VS2005. The DataType is a System.DateTime. and when I try and change it from "(Throw Exception)" I get the following...
6
by: DaTurk | last post by:
Hi, I have several interfaces in CLI that I access via c#. My problem is, is that down in the unmanaged c++, which the CLI lies on top of, I have a lot of c_str() happening. But all of my...
14
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have seen the following function to convert from a System::String^ to a const wchar_t*. I would like to get a LPCTSTR and AFAIK LPCTSTR is equal to const wchar_t*. Then it should all work right?...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.