c++-cli

What libraries do I need to link my mixed-mode application to?

I'm integrating .NET support into our C++ application. It's an old-school MFC application, with 1 extra file compiled with the "/clr" option that references a CWinFormsControl. I'm not allowed to remove the linker flag "/NODEFAULTLIB". (We have our own build management system, not Visual Studio's.) This means I have to specify all neces...

What is the best way to convert between char* and System::String in C++/CLI

What is the approved way to convert from char* to System::string and back in C++/CLI? I found a few references to marshal_to<> templated functions on Google, but it appears that this feature never made the cut for Visual Studio 2005 (and isn't in Visual Studio 2008 either, AFAIK). I have also seen some code on Stan Lippman's blog, but it...

How to enforce all children to override the parent's Clone() method?

How to make sure that all derived C++/CLI classes will override the ICloneable::Clone() method of the base class? Do you think I should worry about this? Or this is not a responsibility of the base class' writer? Amendment: Sorry, I forgot to mention that the base class is a non-abstract class. ...

Converting std::vector<>::iterator to .NET interface in C++/CLI

I am wrapping a native C++ class, which has the following methods: class Native { public: class Local { std::string m_Str; int m_Int; }; typedef std::vector<Local> LocalVec; typedef LocalVec::iterator LocalIter; LocalIter BeginLocals(); LocalIter EndLocals(); private: LocalV...

Avoiding double-thunking with C++/CLI properties

I've read (in Nish Sivakumar's book C++/CLI In Action among other places) that you should use the __clrcall decorator on function calls to avoid double-thunking, in cases where you know that the method will never be called from unmanaged code. Nish also says that if the method signature contains any CLR types, then the JIT compiler will ...

Managed C++ Method naming

I'm using managed c++ to implement a method that returns a string. I declare the method in my header file using the following signature: String^ GetWindowText() However, when I'm using this method from C#, the signature is: string GetWindowTextW(); How do I get rid of the extra "W" at the end of the method's name? ...

Problem with converting enumerations in C++\CLI

I have an assembly, written in C++\CLI, which uses some of enumerations, provided by .Net. It has such kind of properties: property System::ServiceProcess::ServiceControllerStatus ^ Status { ServiceControllerStatus ^ get() { return (ServiceControllerStatus)_status->dwCurrentState; } } it works fine,...

Best practice for translating exceptions in C++/CLI wrapper class

I am writing a .NET wrapper class for an existing native class which throws exceptions. What are the best practices for translating between native C++ exceptions and Managed exceptions? Catch and re-throw on a one-to-one basis (e.g. std::invalid_argument -> System.System.ArgumentException)? Is there a mapping already drawn up somewhere? ...

How to get the executable path from a Managed DLL

I have a managed DLL (written in C++/CLI) that contains a class used by a C# executable. In the constructor of the class, I need to get access to the full path of the executable referencing the DLL. In the actual app I know I can use the Application object to do this, but how can I do it from a managed DLL? ...

How to get the application executable name in Windows (C++ Win32 or C++/CLI)?

I need to change the functionality of an application based on the executable name. Nothing huge, just changing strings that are displayed and some internal identifiers. The application is written in a mixture of native and .Net C++ code. Two ways that I have looked at are to parse the GetCommandLine() function in Win32 and stuffing aro...

Passing a ref or pointer to a managed type as an argument in C++.net

I'm really baffled by this - I know how to do this in VB, unmanaged C++ and C# but for some reason I can't accept a ref variable of a managed type in C++. I'm sure there's a simple answer, really - but here's the C# equivalent: myClass.myFunction(ref variableChangedByfunction); I've tried C++ pointers - no dice. I've tried ref keywords...

Windows Forms UserControl overrides not being called

I am creating a Windows Forms control derived from UserControl to be embedded in a WPF app. I have generally followed the procedures given in this link. public ref class CTiledImgViewControl : public UserControl { ... virtual void OnPaint( PaintEventArgs^ e ) override; ... }; And in my CPP file: void CTiledImgViewControl::OnPaint( ...

Are there any tools for converting Managed C++ to C++/CLI?

We have an old project written using Managed C++ syntax. I would like to propose to the team a reasonably pain-free (I don't mind some level of human interaction, I think I'm realistic in my expectations that we'll still have to do some work by hand) method of updating the existing code to C++/CLI syntax so that we can also add XML docum...

Do you recommend Native C++ to C++\CLI shift?

I have been working as a native C++ programmer for last few years. Now we are starting a new project from the scratch. So what is your thoughts on shifting to C++\CLI at the cost of loosing platform independent code. Are there are any special advantages that one can gain by shifting to C++\CLI? ...

How to use boost::bind in C++/CLI to bind a member of a managed class

I am using boost::signal in a native C++ class, and I now I am writing a .NET wrapper in C++/CLI, so that I can expose the native C++ callbacks as .NET events. When I try to use boost::bind to take the address of a member function of my managed class, I get compiler error 3374, saying I cannot take the address of a member function unless...

auto_ptr or shared_ptr equivalent in managed C++/CLI classes

In C++/CLI , you can use native types in a managed class by it is not allowed to hold a member of a native class in a managed class : you need to use pointers in that case. Here is an example : class NativeClass { .... }; public ref class ManagedClass { private: NativeClass mNativeClass; // Not allowed ! NativeClass * mNativeCla...

Is C++ CLI a superset of C++?

Would a C++ CLI compiler be able to compile some large sets of C++ classes without modifications? Is C++ CLI a superset of C++? ...

Would you use C++/CLI if supported like C# & VB.NET?

I've always had a thing for C++/CLI. Maybe because not many developers use it... or just because it's different. Suppose Microsoft fully supported C++/CLI as they do VB.NET and C# (ie. LINQ, WPF, etc.). Would you use it? If not, why? ...

Does Mono .NET support and compile C++ / CLI?

Does Mono .NET support and compile C++ / CLI? If not, do you know if they have any plans of supporting it? ...

What is gcnew?

I stumbled across this code and am too proud to go and ask the author what it means. Hashtable^ tempHash = gcnew Hashtable(iterators_); IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator(); What is gcnew and how important is it to use that instead of simply new? (I'm also stumped by the caret; I asked about that over here.) ...