c++-cli

Array initialization in Managed C++

巧了我就是萌 提交于 2019-12-01 01:45:49
问题 I wish to declare and initialize a 1D managed array of items. If it was C# code, I would write it like this: VdbMethodInfo[] methods = new VdbMethodInfo[] { new VdbMethodInfo("Method1"), new VdbMethodInfo("Method2") }; I am trying to write (well, actually, I'm writing a program generate) the same thing in managed C++... So far I have: typedef array<VdbMethodInfo^, 1> MethodArray; // How do I avoid pre-declaring the size of the array up front? MethodArray^ methods = gcnew MethodArray(2);

What is CLI/C++ exactly? How does it differ from 'normal' c++?

醉酒当歌 提交于 2019-12-01 00:14:16
问题 Let me clarify what I mean by 'normal' C++ first- I'm currently reading Walter Savitch's "Problem Solving in C++". As far as I am aware this is not written specifically for Microsoft or Unix. So my question is, how does what I am learning in this book (which I am using for my universal knowledge-gaining of c++) differ from what I keep reading about CLI C++? Is CLI C++ just what I would encounter if I used Visual C++? I'm totally confused. 回答1: C++/CLI, (Also sometimes C++/CLR) refers to a

Target .NET 3.5 C++/CLI in Visual Studio 2010 Beta 2

こ雲淡風輕ζ 提交于 2019-11-30 23:33:00
Has anyone had any success converting a VS 2008 C++/CLI (vcproj) project to a VS 2010 project (vcxproj), whilst maintaining .NET 3.5 as the target framework? I haven't been able to do this and get the project to build successfully. The project compiles fine in VS2008 as .NET 3.5, and fine in VS2010 as .NET 4.0, but I am unable to target .NET 3.5 in 2010. The IDE doesn't seem to provide an option for it, and modifying the vcxproj file by adding <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> causes compilation to fail with the folling error: Error 1 error C1001: An internal error has

Cannot use managed event/objects in unmanaged code error c3265, c2811

蹲街弑〆低调 提交于 2019-11-30 23:05:47
Native C++ library that I am using in C++/CLI project raises events giving me results, If I try to handle the event by extending the unmanaged event, it says the ref class can only extend ref class. I then tried to create a native event but have manged object inside it to collect the results, but I get the error cannot declare managed object in unmanaged class. Is there anyway to get it done in one of the ways I am trying, or should I declare unmanaged result objects fill them in unmanaged event and then Marshall it ? Edit: class MyNativeListener: public NativeEventListener { private:

C# to C++/CLI to C DLL System.IO.FileNotFoundException

十年热恋 提交于 2019-11-30 20:06:45
I'm getting System.IO.FileNotFoundException: The specified module could not be found when running C# code that calls a C++/CLI assembly which in turn calls a pure C DLL. It happens as soon as an object is instantiated that calls the pure C DLL functions. BackingStore is pure C. CPPDemoViewModel is C++/CLI calling BackingStore it has a reference to BackingStore. I tried the simplest possible case - add a new C# unit test project that just tries to create an object defined in CPPDemoViewModel . I added a reference from the C# project to CPPDemoViewModel . A C++/CLI test project works fine with

Linker error when using unique_ptr in C++/CLI

纵饮孤独 提交于 2019-11-30 19:30:30
I'm currently converting my instances of auto_ptr to unique_ptr , but I'm hitting an issue. It works great in the C++ part of the code, but when doing it in my managed C++/CLI layer (the software uses both C# and C++) I get link errors. It compiles fine, but it breaks at link time. There were never any issues with auto_ptr . I'm currently using Visual Studio 2010. Does anybody know of any issues with using unique_ptr in C++/CLI? I've tried to sum up my issue in a piece of code below, but please be aware that the code below actually compiles and works (I checked that the ownership of the

How do I call C++/CLI (.NET) DLLs from standard, unmanaged non-.NET applications?

蹲街弑〆低调 提交于 2019-11-30 19:19:15
In the unmanaged world, I was able to write a __declspec(dllexport) or, alternatively, use a .DEF file to expose a function to be able to call a DLL. (Because of name mangling in C++ for the __stdcall, I put aliases into the .DEF file so certain applications could re-use certain exported DLL functions.) Now, I am interested in being able to expose a single entry-point function from a .NET assembly, in unmanaged-fashion, but have it enter into .NET-style functions within the DLL. Is this possible, in a simple and straight-forward fashion? What I have is a third-party program that I have

C++/CLI : Advantages over C#

微笑、不失礼 提交于 2019-11-30 19:05:19
Is there any major advantage of managed C++/CLI over C#. Definitely not the syntax I suppose as the following code in C++/CLI is real ugly, C++/CLI code: [Out]List<SomeObject^>^% someVariable Compare above with C# Code: out List<SomeObject> someVariable Just out of curiosity, is there an even uglier syntax in C++/CLI as compared to the above. It's almost exclusively an interopability language - both for allowing .Net code to access legacy C++ libraries, or for extended existing (native) C++ code bases with access to .Net libraries (and some variations on these themes). While it is possible to

When should delete be called on a gcnew allocated object?

心已入冬 提交于 2019-11-30 18:54:48
I was reading the following MSKB example and they perform a delete on a managed object. I was under the impression you should never delete a garbaged collected object rather you must leave that to garbage collector. What have I missed? Method 4 //#include <msclr/marshal.h> //using namespace msclr::interop; marshal_context ^ context = gcnew marshal_context(); const char* str4 = context->marshal_as<const char*>(str); puts(str4); delete context; delete in C++/CLI merely calls the Dispose method on a managed object, if it implements the System::IDisposable interface – if it doesn't, it's

Why is Intellisense “Unavailable for C++/CLI”? [duplicate]

99封情书 提交于 2019-11-30 18:14:33
Possible Duplicate: No IntelliSense for c++/cli in visual studio 2010? As the title already states, nothing gets popped up or syntax checked. In the status bar, the following message is displayed. Intellisense 'Unavailable for C++/CLI' Usually I am using native C++ in Visual C++ 2010 Express. In Visual C++ 2008, Intellisense was working correctly for C++/CLI, so I guess it should be working in this version too. The IntelliSense parser in the C++ IDE was due for an overhaul, it had chronic problems that didn't get better with each release. Random corruption of the .ncb file, the IS database was