c++-cli

LNK2022: metadata operation failed : Inconsistent field declarations in duplicated types

穿精又带淫゛_ 提交于 2019-12-05 11:18:31
I have problem with compiling my C++ .NET project. I have read "LNK2022: metadata operation failed" driving me insane -- and this is not my case, because in my case i cannot compile one single project -- it fails at link time. i tried all (two) solutions from that topic and that didn't help me. This errors started to rise up just when i have changed the class to be a template class. i have Vector2Di (for int type) class and now need completely the same for float type, so i renamed it to Vector2D and changed it to use template, now i have: template <class T> public ref class Vector2D :

modopt and .NET reflection

萝らか妹 提交于 2019-12-05 10:53:10
I have a CLI/C++ interface that I want to examine via .NET Reflection. Here's the function signature in the source code: class ClassA; template<typename _Type> class ClassTempA; public interface class Test : BaseFunc { public: ClassTempA<int>& SomeFunc2(ClassA inst) = 0; }; Here's what the function looks like when examined in .NET Reflector: unsafe ClassTempA<int>* modopt(IsImplicitlyDereferenced) SomeFunc2(ClassA inst); Is there a way to get at the modopt attributes via .NET reflection, or do I have to use the Metadata Unmanaged API? You can get the modopt and modreq info from System

C++/CLI Explicitly Load Managed DLL at runtime (the equivalent of LoadLibrary for Unmanaged)

99封情书 提交于 2019-12-05 10:31:08
Problem 1: Is there a way to explicitly load a library at runtime instead of at compile time in C++/CLI. Currently I am using the .NET "Add Reference" at compile time. I would like to explicitly load a managed dll. Is there the .NET equivalent of LoadLibrary? Update: Thanks to Randolpho Assembly::LoadFrom example from MSDN Assembly^ SampleAssembly; SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" ); // Obtain a reference to a method known to exist in assembly. MethodInfo^ Method = SampleAssembly->GetTypes()[ 0 ]->GetMethod( "Method1" ); // Obtain a reference to the parameters

Abstract Sealed Classes

↘锁芯ラ 提交于 2019-12-05 09:59:31
Just a small question about c++/cli. Abstract classes have abstract methods to be implemented by derived classes, sealed classes dont allow inheritance. So why we have some classes in .NET base class library defined as abstract sealed, and you can find plenty .. ??! It is equivalent to "static class" in the C# language. The language that was used to write almost all of the BCL classes. All the methods must be static. Declaring it abstract and sealed prevents anybody from deriving from the class and creating an instance of it. The class methods are the exact equivalent of free functions in the

C++/CLI shorthand properties

你离开我真会死。 提交于 2019-12-05 09:28:09
问题 How does a developer do the equivalent of this in managed c++? : c# code public String SomeValue { get; set; } I've scoured the net and found some solutions, however it is hard to distinguish which is the correct (latest, .NET 3.5) way, given the colourful history of getters/setters and managed c++. Thanks! 回答1: Managed C++ does not support automatic properties. You should manually declare a backing field and the accessors: private: String* _internalSomeValue; public: __property String* get

Issue in compiling with marshal.h : error C2872: 'IServiceProvider' : ambiguous symbol

心不动则不痛 提交于 2019-12-05 08:51:08
问题 I am trying to use the marshalling library in my C++/CLI project. When compiled with #include <msclr/marshal.h> I get the error error C2872: 'IServiceProvider' : ambiguous symbol . Most of the resolutions seems to be suggesting moving #include <windows.h> like the one here -> Ambiguous references, but I dont have those includes. All I have is: using namespace System; using namespace System::Configuration; using namespace std; #include <msclr/marshal.h> How do I debug this issue ? 回答1: You do,

using namespace

半腔热情 提交于 2019-12-05 08:14:52
what is the difference between using System; and using namespace System; is it the same thing? thanks Yes, there's a difference. The first one doesn't compile. Maybe you meant this: #using <System.dll> using namespace System; The #using directive allows you to reference an assembly without going through the Framework and References project setting. 来源: https://stackoverflow.com/questions/4906540/using-namespace

Use of ^ operator in visual c++

心已入冬 提交于 2019-12-05 06:08:33
I am doing Visual c++ programming, I have created a CLR console application. I have noticed that String arrays should be declared like String ^, not String[]. What is the use of ^? And why is it being used instead of []? And is this substitution limited only to CLR applications? Here is a line of the code and the error: array<String[]>[] abc; the errors generated were error C2143: syntax error : missing ';' before '[' error C2146: syntax error : missing ';' before identifier 'abc' eror C2065: 'abc' : undeclared identifier Ceramic Pot The circumflex accent means that the object is a managed

Visual Studio 2017 Professional C++/CLI Missing

匆匆过客 提交于 2019-12-05 04:09:26
I can't understand why I can't find C++/CLI project type in to Visual Studio 2017 . I just updated my Visual Studio, and now I can't create any more Windows Forms applications. The answer is solved in this visual studio community forum . I copied the solution here for convenience: Please make sure you have selected the component "C++/CLI support" in your installation; Please launch the "Visual Studio Installer" Modify your installed VS; You can find the component "C++/CLI support" under thw workload "Desktop development with C++" 来源: https://stackoverflow.com/questions/43298794/visual-studio

Array of pointers in C++/CLI MSIL assembly

我只是一个虾纸丫 提交于 2019-12-05 03:43:44
I'm trying to wrap some legacy C code for use with C# running on .NET Core. I'm using the approach given here to create a C++ wrapper that compiles to pure MSIL. It's working well for simple functions, but I've found that if my code ever uses pointers-to-pointers or arrays of pointers it will crash with a memory violation. Often it crashes Visual Studio and I have to restart everything, which is tedious. For example, the following code will cause the crashes: public ref class example { public: static void test() { Console::WriteLine("\nTesting pointers."); double a[5] = {5,6,7,8,9}; //Array.