Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

What's the correct .NET type...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 20 Oct 2004 19:22 GMT
when a function wants an MFC CString?  TIA.
Jochen Kalmbach - 20 Oct 2004 19:30 GMT
> when a function wants an MFC CString?  TIA.

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

//#include <vcclr.h>

 System::String *mstr = S"Hello world";
 CString dest;
 #ifdef _UNICODE
 const __wchar_t __pin * umstring = PtrToStringChars(mstr);
 #else
 const char* umstring = (const char*)Marshal::StringToHGlobalAnsi
(mstr).ToPointer();
 #endif
 dest = umstring;
 #ifndef _UNICODE
 Marshal::FreeHGlobal(IntPtr((void*)umstring));
 #endif

Signature

Greetings
 Jochen

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

James - 20 Oct 2004 20:30 GMT
Thanks for responding!!  Does anyone have additional input
on how to do this from C#?  I guess I'll have to write a
C++ wrapper..

>-----Original Message-----
>
[quoted text clipped - 17 lines]
>  Marshal::FreeHGlobal(IntPtr((void*)umstring));
>  #endif
Jochen Kalmbach - 20 Oct 2004 20:38 GMT
> Thanks for responding!!  Does anyone have additional input
> on how to do this from C#?  I guess I'll have to write a
> C++ wrapper..

You cannot pass a CString to an function from C#. You only can pass an
char*/wchar_t*.

Signature

Greetings
 Jochen

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.