c++-cli

shared_ptr not defined when including from managed code

99封情书 提交于 2019-12-12 11:32:16
问题 I'm trying to write a managed wrapper (C++/CLI) around an unmanaged C++ static library and am having two problems: The unmanaged library uses std::shared_ptr in its headers. <memory> is included, and the header compiles as part of an unmanaged project. When I include this header in the managed project, however, I receive this error: error C2039: 'shared_ptr' : is not a member of 'std' How do I access the Values collection of a SortedDictionary<K, V> from C++/CLI? I cannot seem to find any

Firing events in C++ and handling them in C#

拟墨画扇 提交于 2019-12-12 11:29:21
问题 I have an industrial computer with some Digital I/O pins. The manufacturer provides some C++ libraries and examples to handle pin status change. I need to integrate this events onto a C# application. AFAIK the most simple way to perform this is: Make a managed C++/CLI wrapper for the manufacturer libraries that fires events when interruptions are issued from the DIO pins. Reference that wrapper and handle the events in the C# part as it they were normal C# events. I have tried to make this

C++ MultiThreading with visual studio express 2010 Forms Application

南楼画角 提交于 2019-12-12 10:48:22
问题 I am developing a Windows forms application which connects to a piece of hardware, acquires a lot of data (~1 GSample/sec), processes it, and spits it out to the screen upon a button click. I am now trying to automate the process in a loop that can be started/stopped at any time so I can monitor it whilst tweaking the input to the acquisition hardware. I thinks it's clear that I need to do this on a separate thread, but I'm having a heck of a time trying to do this in c++/cli - I have found a

C++/CLI, static constructor outside class declaration

▼魔方 西西 提交于 2019-12-12 10:33:02
问题 How do I put body of static constructor of a managed class outside class declaration? This syntax seems to be compilable, but does it really mean static constructor, or just a static (=not visible outside translation unit) function? ref class Foo { static Foo(); } static Foo::Foo() {} 回答1: Yes, that is the correct syntax to create a C++/CLI static constructor. You can know its not creating a static function since that is not a valid function declaration syntax. Functions must have the return

Translate C++/CLI to C#

杀马特。学长 韩版系。学妹 提交于 2019-12-12 09:49:48
问题 I have a small to medium project that is in C++/CLI. I really hate the syntax extensions of C++/CLI and I would prefer to work in C#. Is there a tool that does a decent job of translating one to the other? EDIT: When I said Managed c++ before I apparently meant c++/CLI 回答1: You can only translate Managed C++ code (and C++/CLI code) to C# if the C++ code is pure managed. If it is not -- i.e. if there is native code included in the sources -- tools like .NET Reflector won't be able to translate

Mixed management in C++

风流意气都作罢 提交于 2019-12-12 09:43:26
问题 I have added a class to my program and tested it. I was really surprised that there was any real errors. Here is the code: #pragma once #include "Iingredient.h" #include <string> #include <vector> using namespace std; ref class Recipe{ private: string partsName; vector<Iingredient> ing; public: Recipe(){} }; And here are the errors: Error 23 error C4368: cannot define 'partsName' as a member of managed 'Recipe': mixed types are not supported c:\users\user\documents\visual studio 2010\projects

Visual Studio 2017 Professional C++/CLI Missing

安稳与你 提交于 2019-12-12 09:37:25
问题 I can't understand why I can't find C++/CLI project type in to Visual Studio 2017 . I just updated my Visual Studio, and now I can't create any more Windows Forms applications. 回答1: The answer is solved in this visual studio community forum. I copied the solution here for convenience: Please make sure you have selected the component "C++/CLI support" in your installation; Please launch the "Visual Studio Installer" Modify your installed VS; You can find the component "C++/CLI support" under

Lambdas in C++/CLI

你。 提交于 2019-12-12 08:54:02
问题 How to use lambda expressions in C++/CLI? 回答1: In C#, lambdas are really just syntactic sugar for creating delegates. C++/CLI supports delegates, so you can still do all of the same stuff in C++/CLI that you can do in C#, you just don't get to use the nifty syntax. 回答2: I've found this response from a Microsoft employee on the vc blog to a question regarding C++ 0x lambda and managed code interoperability: You can only pass a variable with a managed type as an argument to a lambda - you can't

How can I pass a binary blob from C++ to C#?

旧时模样 提交于 2019-12-12 08:18:09
问题 I'm primarily a C# dev (not much C++ since college), but working on integrating a large collection of existing C++ code into an application. I have a C++/CLI assembly that is buffering the two worlds and have communication from C# through to C++ working fine. The question I have, is that the C++ class has a method call that generates a binary blob (think array of byte s in C# world) that I need to get in C# and process (pass around like a solid bag). What I'm looking for is advice on how to

How to add shared C# NuGet dependencies to a C++/Cli project?

泪湿孤枕 提交于 2019-12-12 07:25:09
问题 Context: A Visual Studio solution with 2 assemblies, Cs and Cpp. Cs is a C# / .net45 dll Cpp is a C++/Cli dll, a C++ dll compiled with /clr. I have some dependencies that are pure C# projects from nuget.org. I use the original packages provided by the authors. Adding them to the Cs project works fine, but not to Cpp. How can I add the C# package to the C++ project? Since it's C++/Cli, I can easily use .net objects, and I use e.g. in the C++ library stuff from the C# library. But somehow nuget