c++-cli

Implementing IEnumerable<T> in C++/CLI

I'm having problems implementing IEnumerable<T> in my custom collection class in C++/CLI. Here is the relevant part of the code: using namespace System::Collections::Generic; ref class MyCollection : IEnumerable<MyClass^> { public: MyCollection() { } virtual IEnumerator<MyClass^>^ GetEnumerator() { return...

C++/CLI : Interop window is not properly configured

Hi, I'm trying to load a WPF control in a C++/CLI application, using the HwndSource class. Here is my code : UBOOL MyWindowWrapper::Init(const HWND InParentWindowHandle) { Interop::HwndSourceParameters sourceParams( "WindowName" ); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.ParentWindow = (Int...

Lambdas don't appear to work within ref classes in VS2010

One of the cool new C++ features in Visual Studio 2010 are lambda expressions. However, I can't get them to work within a managed class. class UnmanagedClass { void Foo() { // Creating empty lambda within unmanaged class. // This compiles fine. auto lambda = [](){ ; }; } }; ref class ManagedClass { v...

How do I specify a fixed-size buffer in C++/CLI?

In C#, I can specify a fixed sized buffer using the fixed keyword, like so: public unsafe struct StructWithFixedBuffer { public fixed char FixedBuffer[128]; } how would I express the same thing in C++/CLI? ...

How do I fix fatal error C1113: #using failed on 'Mylib.lib'

I have a project which uses C++/CLI to implement a GUI and some background processing to talk to a sensor. I've got that all working and a lot of the comms stuff which we use to communicate the the sensor sits in a .dll. The problem is that I'd like to combine the library into the main executable to avoid having to worry about distributi...

C++ CLI Missing ';' before '}'

I am learning C++/CLI and attempting to build an Interop component for my C# project. I'm not sure what this error means or how to resolve it? Any ideas? #pragma once using namespace System; namespace Firewall { public ref class Firewall { void StartFirewall(){}; } } ...

Whats the difference between C++ and C++ CLI

I'm learning C++ (CLI apparently), and every time I post a question saying that I am using C++, someone jumps down my throat saying that I'm not using C++, but C++/CLI. I'm not really sure of a difference, as I am extreamely new to this, but it seems to make everyone upset. Can anyone shine some light on the differences? As a second n...

(C#/C++ CLI) Is it possible to protect my C++ CLI assemblies from being used in other .NET projects?

I have created a C++ CLI wrapper for native C++ code, which in turn I reference in my C# application. Is it possible to somehow protect this assembly so that it may only be used in my application without the possibility of someone else using it? I'm a Microsoft technology developer, I'm all about selfishness :) ...

C++/CLI/C# BadImageFormat Exception when loading form

I created a C++/CLI assembly that creates a wrapper around native C++ code. The resource compiles and the assembly loads fine into my C# project when I add it as a resource. I can access my objects and intellisense from within my application, but when attempting to build, it crashes with the exception: BadImageFormat Could not loa...

C#/C++/CLI Exposing a method with a return type of list in my C++/CLI assembly to my C# project (Beginner Question)

I'm a begineer to C++/CLI, so bare with me. I have a C++/CLI project that wraps a native C++ application, which I use in my C# project. I added a few void methods in my C++/CLI class which expose correctly to my C# project. The intellisense shows fine in C# and I can interact with the methods. However, when I put a return type of a s...

C++/CLI Convert unmanaged native C++ list into a managed C++/CLI List

I have a C++ list which contains a struct. My C++/CLI project consumes the native C++. I would like to return a managed list to my C# project. How can I convert my C++ list into a managed list? ...

Need to convert String^ to char *

I am using the .NET DateTime to get the current date and time. I am converting it to a string to use as part of a file name. The problem is the OpenCV command to save an image requires a char * not a string type, and DateTime will only output a String^ type. How do I make this work? Heres the code not completed String^ nowString = DateT...

C++/CLI I can't add a class to my collection.

I am attempting to simply add a FilterInfo class to my FilterInfo collection. I'm having a terrible time trying to understand why the following code keeps throwing the error: System::Collections::Generic::List::Add' : cannot convert parameter 1 from 'Ziz::FilterInfo *' to 'Ziz::FilterInfo' I'm only learning C++/CLI, as I'm a...

How can I get close to non-nullable types in C# today?

I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack. However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo&). The compiler makes this work by adding...

Is this really returning a local addess?

I have some code which creates a synchronised queue which I use in a data gathering class to report it's data. The method which creates queues is kicking up a warning: Queue^% DataGatherer::AddOutputQueue() { Queue^ outputQueue = Queue::Synchronized(gcnew Queue); AddOutputQueue(outputQueue); return outputQueue; } 1>.\Da...

Assigning pointer to a CLR type to void* using unsafe?

Is there any way to assign a pointer to a CLR type to a void* in a C# unsafe block? var bar = 1; var foo = new Foo(); unsafe { void* p1 = &bar; void* p2 = &foo; // fails at compile time } Or this only possible using C++/CLI: System::Text::StringBuilder^ sb = gcnew System::Text::StringBuilder(); void* p1 = &sb; Can't find ...

What are the advantages of doing 100% managed development using C++/CLI?

What are the advantages (the list of possible disadvantages is lenghtly) of doing 100% managed development using C++/CLI (that is, compile with /clr:safe which "generates ... assemblies, like those written in ... C#")? Especially when compard to C# (note C++/CLI : Advantages over C# and Is there any advantage to using C++/CLI over eithe...

C++ Change image based on a click (Visual Studio C++)

In visual studio, when making a C++ windows application form. I want a picture to change when I click on it. So when I double click the picture and it brings up the click action script, what script do I use..... Similiar to int temp = System::Int32::Parse(label1->Text); temp++; label1->Text = temp.ToString(); Which just increme...

How do I display an MFC control in a windows forms application?

I'd like to create a windows forms control which shows an MFC control such as CIPAddressCtrl, with a working Text property and TextChanged event. How do I display an MFC control in a windows forms application? I'm happy to use C++/CLI if necessary. NOTE: I'm not asking how to create a brand new windows forms control; I want to host a ...

C++/CLI use of Action<...,...> and Func<...> unsupported?

Hi, it does look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as: System::Action<int, int>^ action = nullptr; System::Func<int, int>^ func = nullptr; Both result in errors such as: error C2977: 'System::Action' : too many generic arguments...