473,406 Members | 2,371 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,406 software developers and data experts.

wrapping unmanaged class convert MFC CString

I have dealt with converting managed C++ String* to PCSTR using the Marshal
class, but now I need to get managed C++ String* converted to MFC CString.
I can't seem to figure out how this is performed?

Is it possible? Any help would be greatly appreciated, thank you.
Nov 17 '05 #1
4 2127
sklett wrote:
I have dealt with converting managed C++ String* to PCSTR using the
Marshal class, but now I need to get managed C++ String* converted to
MFC CString. I can't seem to figure out how this is performed?


See: Convert from System::String* to TCHAR/CStringT
http://blog.kalmbachnet.de/?postid=18

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Hmm, so that is what I ended up doing but was sure there was a prettier way
;) Thanks!

char buffer[512];

char* pCheckoutby = (char*)(void*)Marshal::StringToHGlobalAnsi(checkou tby);

strcpy(buffer, pCheckoutby);

CString str(buffer);



"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@207.46.24 8.16...
sklett wrote:
I have dealt with converting managed C++ String* to PCSTR using the
Marshal class, but now I need to get managed C++ String* converted to
MFC CString. I can't seem to figure out how this is performed?


See: Convert from System::String* to TCHAR/CStringT
http://blog.kalmbachnet.de/?postid=18

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #3
"sklett" <as***@asdfasdfsd.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
Hmm, so that is what I ended up doing but was sure there was a prettier
way
;) Thanks!

char buffer[512];

char* pCheckoutby =
(char*)(void*)Marshal::StringToHGlobalAnsi(checkou tby);

strcpy(buffer, pCheckoutby);

CString str(buffer);


What's wrong with

char* psz = ((char*)Marshal::StringToHGlobalAnsi(checkoutby);
CString str(psz);
Marshal::FreeCoTaskMem(psz); // don't leak!

?

-cd
Nov 17 '05 #4
Nothing, I was over complicating the whole thing, it's actually pretty clean
I guess.
I'm flip-floppin'
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
"sklett" <as***@asdfasdfsd.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
Hmm, so that is what I ended up doing but was sure there was a prettier
way
;) Thanks!

char buffer[512];

char* pCheckoutby =
(char*)(void*)Marshal::StringToHGlobalAnsi(checkou tby);

strcpy(buffer, pCheckoutby);

CString str(buffer);


What's wrong with

char* psz = ((char*)Marshal::StringToHGlobalAnsi(checkoutby);
CString str(psz);
Marshal::FreeCoTaskMem(psz); // don't leak!

?

-cd

Nov 17 '05 #5

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

Similar topics

0
by: sklett | last post by:
I'm having a really hard time with wrapping an unmanaged class with a managed class, then calling that managed class from my C# code. I will show you the three pieces, then explain: --------...
2
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
7
by: Klaus Bonadt | last post by:
I have an existing VC6 application using the MFC. I am able to pass CString and other parameters from such a VC6 dll to an unmanaged MFC dll (compiled in Visual Studio .NET). Now I want to use...
0
by: BobTheHacker | last post by:
I am a little lost which is not out of place for me. Anyway here is the story. I wrote a C# class library (managed code) and have a VC++ project that is not managed and am having a few issues. ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: Achim Domma (Procoders) | last post by:
Hi, I still try to implement a .Net wrapper to handel AVI Files. I'm unsing managed C++ with VStudio 2003. The structure of my classes looks like this: class AudioStream { ... } class...
4
by: RedJoy | last post by:
I am switching from VS2003 .NET to VS2005 and I receive the following errorwhen compiling my project: error C3821: 'File': managed type or function cannot be used in an unmanaged function...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.