c++-cli

How can I create .Net extension methods by C++/CLI?

不打扰是莪最后的温柔 提交于 2019-11-29 06:38:02
问题 In C#, extension methods can be created by public static class MyExtensions { public static ReturnType MyExt(this ExtType ext) { ... } } Since all of my library are written in C++/CLI, I would like to create the .net extension methods also in C++/CLI (in order to have one DLL instead of two). I've tried the following code static public ref class MyExtensions { public: static ReturnType^ MyExt(this ExtType ^ext) { ... } }; But the compiler can not recognize keyword 'this' in the first argument

C++/CLI and CMake

时光怂恿深爱的人放手 提交于 2019-11-29 06:26:47
I am trying to set up a C++/CLI project using cmake. I have had success doing this with visual studio 2010, but I am now working with a legacy solution that requires visual studio 2008. In visual studio 2010, it is enough to set up my cmake like this: set_target_properties(${PROJECT_NAME} PROPERTIES VS_DOTNET_REFERENCES "${CMAKE_CURRENT_SOURCE_DIR}/../OrionMaster/3rdParty/GMap.NET.Core.dll;System;System.Core;System.Data;System.Drawing;System.Xml;WindowsBase") set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/clr /EHa") set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG

Is there an easy way to sign a C++ CLI assembly in VS 2010?

无人久伴 提交于 2019-11-29 05:49:06
问题 Right now I am setting the Linker/Advanced/KeyFile option. I am getting the "mt.exe : general warning 810100b3: is a strong-name signed assembly and embedding a manifest invalidates the signature. You will need to re-sign this file to make it a valid assembly." . Reading from the web, it sounds like I have to set the delay signing option, download the SDK, and run sn.exe as a post build event. Surely there must be an easier way to do this common operation in VS2010? 回答1: There's a fair amount

c++/cli DLL fails under Win 8.1

做~自己de王妃 提交于 2019-11-29 05:37:29
i have written a Win32/net DLL, it works fine under Win XP, Win7 and 8 but under Win 8.1 it fails. Dependency Walker says: API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL not found (user32.dll will call them) Google means, MS changed some System-DLLs in 8.1 (and ignored compatibility), so that many programs have the same problem. Full list with "file not found": API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL MSVCR120.DLL API-MS-WIN-CORE-SHUTDOWN-L1-1-1.DLL API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL EXT-MS-WIN-NTUSER-UICONTEXT-EXT-L1-1-0.DLL IESHIMS.DLL Does

Is there an equivalent to the C# “var” keyword in C++/CLI?

邮差的信 提交于 2019-11-29 05:27:12
In C#, I like the var keyword for situations like this: var myList = new List<MyType>(); Is there any equivalent in C++/CLI, or do I have to repeat the type name everytime just like this: List<MyType ^>^ myList = gcnew List<MyType ^>(); Could not find an explicit statement in the docs or by Google so far. I am using Visual Studio 2008. In Visual Studio 2008 there is no such equivalent. However with Visual Studio 2010 you can use the auto keyword to implement var like semantics in C++. I know this works with non-managed C++ and I'm fairly certain it works for C++/CLI as well. I know that type

How can I send a managed object to native function to use it?

早过忘川 提交于 2019-11-29 04:52:00
How can I send a managed object to native function to use it? void managed_function() { Object^ obj = gcnew Object(); void* ptr = obj ??? // How to convert Managed object to void*? unmanaged_function(ptr); } // The parameter type should be void* and I can not change the type. // This function is native but it uses managed object. Because type of ptr could not be // Object^ I called it "Unmanaged Function". void unmanaged_function(void* ptr) { Object^ obj = ptr ??? // How to convert void* to Managed object? obj->SomeManagedMethods(); } The cleaner and the better approach is to use gcroot

Conversion between Base64String and Hexadecimal

孤街浪徒 提交于 2019-11-29 04:37:49
I use in my C++/CLI project ToBase64String to give a string like /MnwRx7kRZEQBxLZEkXndA== I want to convert this string to Hexadecimal representation, How I can do that in C++/CLI or C#? bryanmac FromBase64String will take the string to byte s byte[] bytes = Convert.FromBase64String(string s); Then, BitConverter.ToString() will convert a byte array to a hex string ( byte[] to hex string ) string hex = BitConverter.ToString(bytes); Ranhiru Jude Cooray Convert the string to a byte array and then do a byte to hex conversion string stringToConvert = "/MnwRx7kRZEQBxLZEkXndA=="; byte[] convertedByte

C++ vs. C++/CLI: Const qualification of virtual function parameters

你。 提交于 2019-11-29 03:59:58
[All of the following was tested using Visual Studio 2008 SP1] In C++, const qualification of parameter types does not affect the type of a function (8.3.5/3: "Any cv-qualifier modifying a parameter type is deleted") So, for example, in the following class hierarchy, Derived::Foo overrides Base::Foo : struct Base { virtual void Foo(const int i) { } }; struct Derived : Base { virtual void Foo(int i) { } }; Consider a similar hierarchy in C++/CLI: ref class Base abstract { public: virtual void Foo(const int) = 0; }; ref class Derived : public Base { public: virtual void Foo(int i) override { } }

IntelliSense: “#using” requires C++/CLI to be enabled

喜夏-厌秋 提交于 2019-11-29 03:27:56
#using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Text; using namespace System::IO; using namespace System::Net; using namespace System::Net::Sockets; using namespace System::Collections; Errors: IntelliSense: "#using" requires C++/CLI to be enabled.... how to fix this prob!? Your project settings are wrong. Specifically Configuration Properties, General, Common Language Runtime support. Fall in the pit of success by starting your project by picking one of the project templates in the CLR node. Choose Project -> Properties from the menu bar. In the

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

人走茶凉 提交于 2019-11-29 03:19:46
问题 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 either standard C++ or C#? are mostly about managed/unmanaged interop). For example, here are a few off the top of my head: C++-style references for managed types,