mypcia's ramblings

from geek's perspective

Subscribe to RSS feed

Posts tagged with "visual c++"

Visual C++

, , , ...

While C++ is really funny and engaging language when it comes to mixing C++ and dotnet it's a completely different story. They just don't mix well together. First off Visual Studio especially is not really designed to be centred around C++. In C# or VB.NET you delete object and the events associated are deleted as well, it might not sound it but it's actually pretty annoying when you have an object with large number of event handlers and want to get rid of all. But that's cosmetics I would say. What is really annoying is having to constantly convert strings between system and standard strings, because Microsoft dear couldn't somehow implement standard string to use with dotnet. What's even funnier is that there exists a function which converts standard string to system string but not the other way around... knockout so after a bit of pain and going around how to I finally thought of using Marshal class off namespace Runtime.InteropServices, StringToHGlobalAnsi function, which basically converts system string to ansi and copies the system string into unmanaged memory so later we can point to that memory and pull out the contents using a pointer address. It's not that hard once you know it cannot be done any other way (or can it (?)), but why this sort of thing isn't standard as converting standard string to system string is beyond me.

void SystemToStdString ( String ^ input, string& output ) 
{ // by KKN
using namespace Runtime::InteropServices; 
const char* charString = ( const char* )( Marshal::StringToHGlobalAnsi( input ) ).ToPointer (); 
output = charString; 
Marshal::FreeHGlobal ( IntPtr ( ( void* ) charString ) );
}


I am too used to coding in C++ for Linux, coding for Windows now feels strange to say at least. It's just not the same C++.
June 2013
M T W T F S S
May 2013July 2013
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30