c++-cli

What is the most efficient way to convert a std::vector<T> to a .NET List<U>?

我是研究僧i 提交于 2020-07-05 02:38:05
问题 What is the most efficient way to convert a std::vector to a .NET List? To give some context, I am wrapping an unmanaged C++ class with C++/CLI. The C++/CLI class holds a pointer to the C++ class and I have a wrapper for each public method. One method returns a std::vector, so in my wrapper I was going to return the .NET class List. I.e. // unmanaged class class A { public: std::vector<int> runList(); } // managed class public ref class A { public: // the below is obviously extremely

System.AccessViolationException error when stored callback is executed

孤街浪徒 提交于 2020-05-17 06:49:13
问题 I have passed as callback a C++ member function to a C# project through a C++/CLI wrapper (this works fine). The C# project is going to call this delegate when receiving data from another .exe process: an event will be raised and a method will call this callback. So, I needed to "save" this Action delegate using an static instance of a C# class already created. I got the following code: // C++ unmanaged function WRAPPER_API void dispatchEvent(std::function<void(int)> processEvent) { Iface:

System.AccessViolationException error when stored callback is executed

你说的曾经没有我的故事 提交于 2020-05-17 06:49:05
问题 I have passed as callback a C++ member function to a C# project through a C++/CLI wrapper (this works fine). The C# project is going to call this delegate when receiving data from another .exe process: an event will be raised and a method will call this callback. So, I needed to "save" this Action delegate using an static instance of a C# class already created. I got the following code: // C++ unmanaged function WRAPPER_API void dispatchEvent(std::function<void(int)> processEvent) { Iface:

How to instantiate a generic base class in derived class in C++/CLI?

╄→尐↘猪︶ㄣ 提交于 2020-05-15 08:38:31
问题 I am new to generics. My derived class need to pass the generic type to base class. My derived class itself doesn't need generic type. class A { public: }; generic < typename T> public ref class Base { public: T m_Instance; void Hello() { cout << "Base::Hello() called" << endl; } T GetInstance() { return m_Instance; } }; public ref class Derived : Base <A> { public: void Print() { cout << "Derived::Print called" << endl; Hello(); } }; As you can you can see, my derived case knows what's the

Passing unmanaged method as callback to managed C++/CLI class

岁酱吖の 提交于 2020-04-30 06:28:38
问题 I want to pass as callback a C++ member function to a C# project. I have other project in C++/CLI and I want to do it through it. So, in unmanaged C++ of my C++/CLI project I have a function object: std::function<void(int)>callback; This function is coming from my C++ project and it works fine, I save it there as example to avoid the previous step. Now, I would like to pass this callback function to my C# project. For this, I create a method in unmanaged C++, pass it to managed C++ and from

C# application log4net log file not created when used in C++/CLI

谁都会走 提交于 2020-04-13 16:55:24
问题 I've written a C# dll - foo.dll - that uses log4net for logging. The dll is then used in a C++ application via a C++\CLI wrapper. The C++ application works perfectly, however the log file is not created . When I use this dll in a testing C# application (that uses the original C# dll) the log file is create without problems. This configuration is set in foo.dll.config: <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections>

C# application log4net log file not created when used in C++/CLI

六月ゝ 毕业季﹏ 提交于 2020-04-13 16:51:50
问题 I've written a C# dll - foo.dll - that uses log4net for logging. The dll is then used in a C++ application via a C++\CLI wrapper. The C++ application works perfectly, however the log file is not created . When I use this dll in a testing C# application (that uses the original C# dll) the log file is create without problems. This configuration is set in foo.dll.config: <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections>

C++/CLI targetting .NET Core 3.1

泪湿孤枕 提交于 2020-02-27 09:56:06
问题 .NET Core 3.1 added support for C++/CLI (Announcing .NET Core 3.1). The official announcement lists two new project templates, CLR Class Library (.NET Core) and CLR Empty Project (.NET Core) , which we can indeed find and use. However, there is no additional information about supporting technologies such as WPF or Windows Forms. In a blog posts in September, Microsoft said: we are committed to supporting C++/CLI for .NET Core to enable easy interop between C++ codebases and .NET technologies

C++/CLI targetting .NET Core 3.1

橙三吉。 提交于 2020-02-27 09:56:02
问题 .NET Core 3.1 added support for C++/CLI (Announcing .NET Core 3.1). The official announcement lists two new project templates, CLR Class Library (.NET Core) and CLR Empty Project (.NET Core) , which we can indeed find and use. However, there is no additional information about supporting technologies such as WPF or Windows Forms. In a blog posts in September, Microsoft said: we are committed to supporting C++/CLI for .NET Core to enable easy interop between C++ codebases and .NET technologies

Debugger does not step into native code when debugging a static lib wrapped in a C++/CLI DLL

旧城冷巷雨未停 提交于 2020-02-25 00:51:46
问题 In a C# app, I'm referencing a native C static lib, that I wrapped in a C++/CLI DLL. I chose a static lib versus a DLL because I have other constraints related to the release process of the app to the user. Among the many topics available on this forum I found the following implementation. Main : { MyCLRDLL test = new MyCLRDLL(); if(test.go()) Console.WriteLine("Hello, wrld"); } In the DLL project, the file MyCLRDLL.hpp #include "MyNativeLib.h" #pragma comment(lib, "MyNativeLib.lib")