c++-cli

Using C++ Class DLL in C# Application

这一生的挚爱 提交于 2019-11-26 05:51:37
问题 I have an unmanaged C++ DLL which merely exports a single class (not COM...it\'s just a simple C++ class) as its interface. I want to use this class in C# but am told that it cannot merely be imported into C#. What is the right way to use this class in my C# application? 回答1: Simple way assuming class Foo: Create a C++/CLI project, call this FooWrapper. Make FooWrapper depend on the unmanaged dll (however you normally would). Create a managed class ManagedFoo which contains a single private

How to call a C# library from Native C++ (using C++\CLI and IJW)

偶尔善良 提交于 2019-11-26 03:09:14
问题 Background: As part of a larger assignment I need to make a C# library accessible to unmanaged C++ and C code. In an attempt to answer this question myself I have been learning C++/CLI the past few days/ weeks. There seems to be a number of different ways to achieve using a C# dll from unmanaged C++ and C. Some of the answers in brief appear to be: using Interlope services, Using .com. and regasm, Using PInvoke (which appears to go from C# to C++ only), and using IJW in the C++/CLR (which

c++/cli pass (managed) delegate to unmanaged code

故事扮演 提交于 2019-11-26 02:55:16
问题 How do I pass a function pointer from managed C++ (C++/CLI) to an unmanaged method? I read a few articles, like this one from MSDN, but it describes two different assemblies, while I want only one. Here is my code: 1) Header (MyInterop.ManagedCppLib.h): #pragma once using namespace System; namespace MyInterop { namespace ManagedCppLib { public ref class MyManagedClass { public: void DoSomething(); }; }} 2) CPP Code (MyInterop.ManagedCppLib.cpp) #include \"stdafx.h\" #include \"MyInterop

Calling C# code from C++

我的未来我决定 提交于 2019-11-26 01:59:09
问题 I need to be able to invoke arbitrary C# functions from C++. http://www.infoq.com/articles/in-process-java-net-integration suggests using ICLRRuntimeHost::ExecuteInDefaultAppDomain() but this only allows me to invoke methods having this format: int method(string arg) What is the best way to invoke arbitrary C# functions? 回答1: Compile your C++ code with the /clr flag. With that, you can call into any .NET code with relative ease. For example: #include <tchar.h> #include <stdio.h> int _tmain

How do I create a C++/CLI Winforms app in VS2012?

岁酱吖の 提交于 2019-11-26 00:26:06
问题 I just installed Visual Studio 2012 express for Desktop. I can\'t see any place to create a GUI application with C++ ! Where is this \"Windows Form Application\" used to exists in Visual C++ 2010 ? Where are these drag and drop controls? I installed this because I got details telling this supports GUI intellisense (Visual C++: Unable to invoke method from another class) Please help! 回答1: It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is

C++/CLI Mixed Mode DLL Creation

删除回忆录丶 提交于 2019-11-26 00:24:43
问题 I\'ve got a native C++ DLL that I would like to have a C++/CLI wrapper layer for. From what I understood, if you simple added a C++/CLI class to the project, VS would compile as mixed mode, but I was apparently wrong as VS doesn\'t seem to be even touching the managed code. So, given a pre-existing native code-base what exactly , step-by-step, do you need to do to create a mixed mode DLL, so that I can can link into that code from any .NET language? *I need to do this because my native code

What does the caret (‘^’) mean in C++/CLI?

﹥>﹥吖頭↗ 提交于 2019-11-25 21:57:31
问题 I just came across this code and a few Google searches turn up no explanation of this mysterious (to me) syntax. Hashtable^ tempHash = gcnew Hashtable(iterators_); IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator(); What the heck does the caret mean? (The gcnew is also new to me, and I asked about that here.) 回答1: This is C++/CLI and the caret is the managed equivalent of a * (pointer) which in C++/CLI terminology is called a 'handle' to a 'reference type' (since you can still have