Re: Changing the Text In a Text Box
- From: Steve Behman <SteveBehman@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 2 Aug 2008 08:28:00 -0700
David, thanks once again.
To be honest I had absolutely no idea that I was dealing with .NET and
perhaps, had I known, I would not have undertaken working with it.
I especially appreciated the pointer to the full discussion of these issues.
There are many topics contained therein that will help me develop my
programs without having to run to this forum for answers. I also appreciate
your patience in providing me with this help.
Below is an excerpt from a previous post of mine in this forum. I believe
it will explain where I'm coming from vis-à-vis learning new tools, reading
books and learning new languages.
=================================================
I appreciate your suggestion. I have been programming for 55 years in
about as many languages as years, I'm afraid that one more language would be
the straw that breaks this old camel's back.
If it was not for programs called ZoomText and Dragon NaturallySpeaking I
couldn't read or write anything at all -- but they do not work with paper.
Most of my own C++ programming was for OS/2 for which I developed the
equivalent of the MFC (with an interface to DB/2 using the IBM equivalent of
the SDK.
As a consequence of the above I will do piecewise development of my
application with the Visual Studio tool and then port them to the MFC for
integration into a whole application (that is if I live that long :-).
============================================
That having been said, below is my (perhaps naïve) resolution for getting
back and forth between std:string and System:: String. It puts me in a place
I understand and salvages a whole bunch of my old code.
using namespace Runtime::InteropServices;
#define toStr(a) (gcnew String((a).c_str()))
string tostr( String ^ s)
{
int i=0;
string out="";
wstring os;
const wchar_t* chars = (const
wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
os = chars; Marshal::FreeHGlobal(IntPtr((void*)chars));
while( i<s->Length ) out += s[ i++ ];
return out;
}
"David Wilkinson" wrote:
Steve Behman wrote:.
David,
Thank you so much it really did the trick!
In order to make it more useful (to me) I created a preprocessor macro:
#define str_to_Str (s) (gcnew String((s).c_str()) )
There remain two questions:
1) Is there some sort of destructor needed in association with gcnew?
2) What code is needed to transform a String to an STL string?
Steve:
1. Managed objects created with gcnew do not need deleting. The memory is
reclaimed by the garbage collector (gc) when it is no longer being used.
2. Information on Inter-op between managed and unmanaged C++ may be found here
http://msdn.microsoft.com/en-us/library/2x8kf7zx%28VS.80%29.aspx
However, before you go on, you should be sure that learning C++/CLI is the way
you want to go. Microsoft is no longer promoting C++/CLI for writing .NET GUI
applications. For most people (including even experienced C++ developers), C# is
the way yo go if you want to target the .NET framework.
--
David Wilkinson
Visual C++ MVP
- Follow-Ups:
- Re: Changing the Text In a Text Box
- From: David Wilkinson
- Re: Changing the Text In a Text Box
- References:
- Re: Changing the Text In a Text Box
- From: David Wilkinson
- Re: Changing the Text In a Text Box
- Prev by Date: Re: Timer and GDI+ Window Update
- Next by Date: Re: Timer and GDI+ Window Update
- Previous by thread: Re: Changing the Text In a Text Box
- Next by thread: Re: Changing the Text In a Text Box
- Index(es):
Relevant Pages
|