c++-cli

How to port C++ code to C++/CLI in Visual Studio?

▼魔方 西西 提交于 2019-11-30 08:36:11
问题 I have an application written in native C++ which I'd like to get running on the .NET virtual machine. I was thinking of recompiling the C++ code as C++/CLI, using the Visual Studio 2008 compiler. Regrettably, I don't find any documentation on how to do this, so hence my questions: Does this actually make sense? Am I trying the impossible? Where can information on the topic be found? 回答1: A lot of native C++ code will actually just compile and run on C++/CLI. This is really a kind of hybrid

Proper way of raising events from C++/CLI?

北慕城南 提交于 2019-11-30 08:28:53
I was wondering what's the proper way of raising events from C++/CLI. In C# one s hould first make a copy of the handler, check if it's not null, and then call it . Is there a similar practice for C++/CLI? C++/CLI allows you to override raise in custom event handlers so you don't have to test for null or copy when raising the event. Of course, inside your custom raise you still have to do this. Example, adapted from the MSDN for correctness: public delegate void f(int); public ref struct E { f ^ _E; public: void handler(int i) { System::Console::WriteLine(i); } E() { _E = nullptr; } event f^

C++/CLI and CMake

北城以北 提交于 2019-11-30 08:16:26
问题 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

Destruction of Native Objects with Static Storage Duration

徘徊边缘 提交于 2019-11-30 08:03:35
2012-12-09 Summary: In a normal mixed-mode application global native C++ destructors run as finalizers. It's not possible to change that behavior or the associated timeout. A mixed-mode assembly DLL runs C++ constructors/destructors during DLL load/unload - exactly as a native DLL. Hosting the CLR in a native executable using the COM interface allows both the deconstructors to behave as in a native DLL (the behavior I desire) and setting the timeout for finalizers (an added bonus). As far as I can tell the above applies to at least Visual Studio 2008, 2010 and 2012. (Only tested with .NET 4)

System.AccessViolationException from unmanaged code?

夙愿已清 提交于 2019-11-30 07:46:26
I'm writing this library that implements some basic audio player features in C++/CLI via the Media Foundation framework that will be consumed by managed code. I can play audio, stop, pause, etc just fine. For anyone who is not familiar with Media Foundation, the media session posts events that you can handle for notifications. This is done by calling BeginGetEvent on the session object with an IMFAsyncCallback object. The IMFAsyncCallback defines the method Invoke(IMFAsyncResult) that you should implement to handle the events. When an event occurs, the invoke method is called by the session

How do I export class functions, but not the entire class in a DLL

前提是你 提交于 2019-11-30 07:37:24
I have developed a Win32 DLL, providing the details below, and want to create a CLI/C++ wrapper for the functions Connnect and LogOut. I know that entire classes and functions can be exported from a DLL. class CClientLib { public: CClientLib (void); // TODO: add your methods here. __declspec(dllexport) bool Connect(char* strAccountUID,char* strAccountPWD); __declspec(dllexport) void LogOut(); private : Account::Ref UserAccount ; void set_ActiveAccount(Account::Ref act) { // Set the active account } Account::Ref get_ActiveAccount() { return UserAccount; } }; I want to have the class as the

CLR/CLI linker fails with error LNK2022 - Custom attributes are not consistent

拟墨画扇 提交于 2019-11-30 07:09:04
问题 Environment: Visual Studio 10, CLR/CLI Class Library project, built with Platform Toolset v100 , targeting framework version v3.5 . I am aware that this question was already asked here, but I did not find an answer that solved the problem for my case, so bringing this up again. While building a CLR/CLI Class Library (DLL) project the linker is failing with the following errors: MSVCMRT.lib(managdeh.obj) : error LNK2022: metadata operation failed (80131195) : Custom attributes are not

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

梦想的初衷 提交于 2019-11-30 06:41:30
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. error C2059: syntax error: 'this' Is there some way to create the extension method in C++/CLI ? You

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

↘锁芯ラ 提交于 2019-11-30 06:06:49
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? There's a fair amount of lameness here, this just never worked before. It got "fixed" in VS2010, mt.exe now generates a warning

What is the difference between Managed C++ and C++/CLI?

允我心安 提交于 2019-11-30 05:43:01
What is exactly the difference between the "old" Managed C++ and the "new" C++/CLI? Managed C++ is the version in VS2002 and VS2003. It had race conditions and other serious bugs, as well as being confusing. It's no longer supported. In VS2005, Microsoft introduced C++/CLI, which has also been accepted as an ISO standard. It's also supported in VS2008 and the upcoming VS2010. Both of them had the same goal, which is to create .NET assemblies using the C++ language. The syntax is different (C++/CLI managed code is a lot easier to differentiate from standard C++ at a glance) and C++/CLI also has