Hi there!
I've been having a lot of difficult trying to figure out a way to convert
a terminated char array to a system::string for use in Visual C++ .NET
2003.
This is necessary because I have some legcay C code that needs to process
a string taken from a textbox, then I need to re-display the string as the
textbox->Text. I easily found how to convert from system::string to char[]
but I can't figure out how to go the other way!!
Can someone point me in the right direction? I'm pretty new to VC++
managed programming and the whole GUI thing! :S 27 51722
"Trep" <da**********@g mail.com> writes: Hi there!
I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003.
C++ doesn't have system::string, but on the analogu of std::string
system::string s = the_char_array;
is worth trying.
Okaaay... first off, let me just apologize for the atrocious spelling in my
initial post. It's still pretty early here and my brain is a little zapped!
I should have taken the time to run a spell-check.
Sorry :(
Trep wrote: Hi there!
I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003.
This is necessary because I have some legcay C code that needs to process a string taken from a textbox, then I need to re-display the string as the textbox->Text. I easily found how to convert from system::string to char[] but I can't figure out how to go the other way!!
Can someone point me in the right direction? I'm pretty new to VC++ managed programming and the whole GUI thing! :S
..NET is entirely off topic here, however in the future C++/CLI will be
on topic (but not any system specific libraries of course, like ADO .NET
or whatever).
In any case, if you want to convert an std::string to "char[]" a call to
c.str() member function will suffice.
Example in C++/CLI:
std::string s="Test";
String ^someString= gcnew String(s.c_str( ));
String otherString(s.c _str());
[
Off topic:
In current "managed extensions":
std::string s="Test";
String *someString= __gc new String(s.c_str( ));
]
--
Ioannis Vranos http://www23.brinkster.com/noicys
But... I was under the impression that VC++ .NET used managed strings,
which evolved from CStrings???
My reason for saying this is that I keep getting tips from the compiler
saying the following when, for example, I try to directly set a .NET
textbox contents to equal the contents of a string:
Cannot convert parameter 1 from 'unsigned char *' to 'System::String __gc
*'
So I searched the web and found how to make a System::String __gc * into a
char * but I can't find how to go the other way!
Maybe I'm missing your point??
Trep posted: Hi there!
I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003.
This is necessary because I have some legcay C code that needs to process a string taken from a textbox, then I need to re-display the string as the textbox->Text. I easily found how to convert from system::string to char[] but I can't figure out how to go the other way!!
Can someone point me in the right direction? I'm pretty new to VC++ managed programming and the whole GUI thing! :S
I haven't a clue about .NET, nor have I had a peek at the definition of
"system::string ", but... were I to guess:
system::string ConvertStringTo SysString(char const blah[])
{
return system::string( blah);
}
-JKop
Trep posted: But... I was under the impression that VC++ .NET used managed strings, which evolved from CStrings???
My reason for saying this is that I keep getting tips from the compiler saying the following when, for example, I try to directly set a .NET textbox contents to equal the contents of a string:
Cannot convert parameter 1 from 'unsigned char *' to 'System::String __gc *'
So I searched the web and found how to make a System::String __gc * into a char * but I can't find how to go the other way!
Maybe I'm missing your point??
It wants a *pointer* to a System::String object.
(BTW, C++ is case sensitive, so be careful, is it "system::string " or
"System::String "?)
-JKop
Ioannis Vranos wrote: Trep wrote:
Hi there!
I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003.
This is necessary because I have some legcay C code that needs to process a string taken from a textbox, then I need to re-display the string as the textbox->Text. I easily found how to convert from system::string to char[] but I can't figure out how to go the other way!!
Can someone point me in the right direction? I'm pretty new to VC++ managed programming and the whole GUI thing! :S
.NET is entirely off topic here, however in the future C++/CLI will be on topic (but not any system specific libraries of course, like ADO .NET or whatever).
In any case, if you want to convert an std::string to "char[]" a call to c.str() member function will suffice.
And now I realise you meant a null terminated char array to System::String.
String ^text= gcnew String(array);
[
Off topic:
"Managed extensions":
String *text= __gc new String(array);
]
--
Ioannis Vranos http://www23.brinkster.com/noicys
Thanks for the quick replies. I'm sorry, I didn't realize that this wasn't
an appropriate group for .NET questions. I appreciate your suggestions and
I'll keep trying. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kueishiong Tu |
last post by:
How do I convert a Byte array (unsigned char managed) to a
char array(unmanaged) with wide character taken into
account?
|
by: Mark Ingram |
last post by:
Hi,
how can i return an array of strings from an unmanaged c++ dll into a c#
application?
cheers
Mark
|
by: Bob Rock |
last post by:
Hello,
converting from the managed to the unmanaged world (and viceversa strings)
and byte arrays is something I do often and I'd like to identify the most
correct and efficient way to do it.
Also, I was wondering could there be issues in not making copies when
converting??? I was thinking, when "pointing" to the same data with both
managed and unmanaged strings/arrays couldn't there be issues such as the
garbage collector trying to...
|
by: joye |
last post by:
Hello,
How to convert an unmanaged string with char array type to a managed string
with char array type?
Thanks.
Regards,
Tsung-Yu
|
by: joye |
last post by:
Dear All,
Many old C standard library is useful for string operation such as strcpy.
But I meet some problem, a managed char array which declared in a structure
and this structure has a instance declared in a__gc class.
Sample code as following,
namespace Configure
{
using namespace System ;
| |
by: Serge BRIC |
last post by:
My application, written in .NET VB, tries to get a communication port handle
from a TAPI object with this code:
Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem")
The vFileHandle is supposed to be a file handle (an IntPtr, I suppose). How
can I convert this Byte() in this IntPtr ?
|
by: Madhu_TN |
last post by:
Hi All,
I am new to this board. I am trying to create a Crystal Report viewer into a
VS C++ Dot NET 2003 app ( This uses both managed and unmanaged code).
I get the following compilation error:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\
cstringt.h(875): error C2664: 'PtrToStringChars' : cannot convert parameter 1
from 'unsigned char *' to 'const System::String __gc *'
The code segemnt is:
|
by: Peter |
last post by:
Does anyone know how to convert the following VB6 code to C# code?
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As
Any, Source As Any, ByVal bytes As Long)
Dim sngArray(0) As Single
strString = Chr$(107) & Chr$(62) & Chr(139) & Chr$(65)
CopyMemory sngArray(0), ByVal strString, Len(strString)
After running the code sngArray(0) = 17.40548
|
by: Peter |
last post by:
Trying to convert string to byte array.
the following code returns byte array of {107, 62, 194, 139, 64}
how can I convert this string to a byte array of {107, 62, 139, 65}
System.Text.UTF8Encoding str = new System.Text.UTF8Encoding();
string s = new string((char)107, 1);
s += new string((char)62, 1);
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |