c++-cli

Sharing an enum from C#, C++/CLI, and C++

不羁岁月 提交于 2019-11-27 01:32:51
问题 I have a library that consists of three parts. First is native C++, which provides the actual functionality. Second is a C++/CLI wrapper/adaptor for the C++ library, to simplify the C# to C++ transition. Finally I have a C# library, which invokes the C++ library through the C++/CLI adaptor. Right now there I have two sets of parallel enum definitions, one stored in a .cs file and the other in a .h file. This poses a double problem: I have dual maintenance. I must always synchronize changes of

How to access class in C++/CLI from C#?

雨燕双飞 提交于 2019-11-27 01:24:10
问题 I am writing a GUI tool in C# to parse and display the data output of another program written in C. In order to parse the data I need to know the data structures which are specified in a number of C header files. Thus I need to incorporate those C header files into my C# project. My questions are: 1) After some research I came to conclude that the best way is to create a new C++/CLI project in my solution, import the C header files into this new project, write some C++/CLI classes that act as

What is gcnew?

烈酒焚心 提交于 2019-11-27 01:13:03
问题 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.) 回答1: gcnew is for .NET reference objects; objects created with gcnew are automatically garbage-collected; it is important to use gcnew with CLR types 回答2: gcnew

Creating a pure MSIL assembly from a C++/CLI project?

匆匆过客 提交于 2019-11-27 01:11:49
问题 I am trying to create a pure MSIL assembly from a C++/CLI project using /clr:pure and /clrimagetype:pure flags, however, the output assembly specifically targets x86. Am I missing anything that might be preventing my project to be compiled as MSIL only? 回答1: You can create an AnyCPU dll with C++/CLI , but in the simplest case, you will not be able to use MFC, ATL or the CRT. However, if you just want to write pure managed .NET code in C++/CLI, including managed pointers (which /clr:safe does

Calling C# from C++, Reverse P/Invoke, Mixed Mode DLLs and C++/CLI

喜夏-厌秋 提交于 2019-11-27 01:02:29
问题 As I understand it I can use reverse P/Invoke to call C# from C++. Reverse P/Invoke is simply a case of: Create you managed (c#) class. Create a c++/cli (formerly managed c++) class library project. Use this to call the managed c# class (presumably via a reference). Call the c++/cli code from native c++. Questions: Is this correct? Is the DLL created at step 2 known as a mixed mode DLL? Has C++/CLI completely superseded Managed C++ as far as MS are concerned? Is COM completely avoided using

Can C++/CLI be used to call .NET code from native C++ applications? [closed]

拜拜、爱过 提交于 2019-11-27 00:58:38
问题 I've done the other way around (calling pure C++ code from .NET) with C++/CLI, and it worked (for the most part). How is the native-to-C++/CLI direction done? I really don't want to use COM interop... 回答1: You can always host the CLR in your native app. 回答2: If you have an existing native C++ app and want to avoid "polluting" it with too much CLR stuff, you can switch on the /clr flag for just one specific file and use a standard C++ header to provide an interface to it. I've done this in an

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

感情迁移 提交于 2019-11-27 00:41:34
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's from 2004. I have also seen Marshal::StringToHGlobalAnsi(). Is there a method that is considered "best practice"? There's a good overview here (this marshaling support added for VS2008): http://www.codeproject.com/KB/mcpp/OrcasMarshalAs.aspx Ben Straub

Is there any advantage to using C++/CLI over either standard C++ or C#?

两盒软妹~` 提交于 2019-11-26 23:30:55
问题 I'm not seeing any real advantages, other than the fact that you have a C++ syntax, and with it, things like pointers and destructors. 回答1: If you're talking about why you would use C++/CLI over C#, I think the main reasons are that: it might be more natural for C++ developers (though I think this is probably not true) C++/CLI has very nice capabilities for bridging the native and managed environments (using the 'IJW' - It Just Works - technology) I think that Herb Sutter probably gives the

C++/CLI: Public ref struct generates C2011: 'class' type redefinition

落爺英雄遲暮 提交于 2019-11-26 23:26:59
问题 I have a header file in a managed DLL project like so: Enums.h: #pragma once ... public ref struct ManagedStruct { Bitmap^ image; } ... This header is referenced both from another class in the DLL and from a separate executable. The managed struct alone is generating: error C2011: 'ManagedStruct' : 'class' type redefinition. If I move the struct to the main header file in the DLL it works fine, and is publicly accessible, so that's what I'm doing, but I would very much like to learn why this

how to convert System::String to const char*?

旧街凉风 提交于 2019-11-26 23:12:11
how to convert 'String^' to 'const char*'? String^ cr = ("netsh wlan set hostednetwork mode=allow ssid=" + this->txtSSID->Text + " key=" + this->txtPASS->Text); system(cr); Error : 1 IntelliSense: argument of type "System::String ^" is incompatible with parameter of type "const char *" You can do this using the msclr::interop::marshal_context class: #include <msclr/marshal.h> Then: String^ something = "something"; msclr::interop::marshal_context ctx; const char* converted = ctx.marshal_as<const char*>(something); system(converted); The buffer for converted will be freed when ctx goes out of