c++-cli

c++/cli Best practice for free GCHandle in the finalizer

喜你入骨 提交于 2019-12-07 07:05:28
问题 I have some functions in c and I would use this in a .net application. For this I wrote an Wrapper class with C++/cli. In the c interface is a callback function and wrapped this in a .net delegate. But how should I release the unmanaged ressources for the callback gcHandle? Is it allowd to call IsAllocated and Free from a GCHandle in the finalizer? Because it is an managed ressource and is it possibile that the gc already release it? Here is the code for the c interface: // C functions #ifdef

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

只谈情不闲聊 提交于 2019-12-07 05:28:33
问题 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

Free-running application under test exits shortly after I attach with VS2010 SP1 in x86

一曲冷凌霜 提交于 2019-12-07 05:21:11
问题 On Windows 7 x64, when I attach in x86 mode to a fairly complex free-running app, it runs for a while, then reproducibly exits. MyApp.exe Managed (v4.0.30319)' has exited with code -1073740791 (0xc0000409). followed immediately by MyApp.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0). Sometimes if it runs OK, it would hit my breakpoint, I'll inspect the state, but when I hit F5 to keep going, the app exits in the same fashion. Quick search for the error code tells me that it's

using namespace

霸气de小男生 提交于 2019-12-07 04:18:27
问题 what is the difference between using System; and using namespace System; is it the same thing? thanks 回答1: 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

Abstract Sealed Classes

痞子三分冷 提交于 2019-12-07 04:15:39
问题 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 .. ??! 回答1: 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

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

此生再无相见时 提交于 2019-12-07 04:15:34
问题 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

How do I make a vector/array of System::Windows::Forms::Checkbox^

孤者浪人 提交于 2019-12-07 03:03:27
Couldn't find any answer to this problem, or not even any questions asked. So what I'm trying to do, is a std::vector, maybe just a normal array, of Checkboxes. std::vector< System::Windows::Forms::CheckBox^ >m_items; m_items.push_back( myCheckbox ); That's what I currently have, and it clearly ain't working. So does anyone have any ideas, on how to get it working, cause I've tried everything I can, but vectors don't seem to support Checkboxes. Incase you need the error code: c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(200): error C3699: '&&' : cannot use this

Accessing embedded resources in C++/CLI

妖精的绣舞 提交于 2019-12-07 00:25:30
I've been working with C# for a while, and I'm trying to write a .NET app in C++ this time. In C# I was able to access the managed resources from the code quite easily, the name of the resource file worked sort of like a class, so if I had a string called "abc" in a resource file called cba.resx, simply writing cba.abc returned with the string from the resource file. Even intellisense works with it. Same thing works with icons, etc. Is it possible to do the same in C++, and if so, how? Or if not, what is the easiest way to access strings/icons in resource files? In Visual Studio, C# projects

Wrapping an Unmanaged C++ Class Library with C++/CLI - Question 1 - Project/Code Organization

最后都变了- 提交于 2019-12-06 20:54:07
问题 Note: This post represents Question #1 of my inquiry. The introduction block (all text until the numbers are reached) is repeated in both questions as it is background information that may be needed to answer the question. Introduction to Question I have an unmanaged C++ library that contains classes and functions that are common to and shared among several "higher level" libraries. I now have need to provide access to the common library to C#/.Net applications. To do this, I will have to

How to use c/c++ struct in C# code?

旧时模样 提交于 2019-12-06 19:33:26
I'm using some service that send me byte array using UDP. This service application was developed in C - and this this byte array is a C struct. I know that i can redefine this struct on C# and using the StructLayout attribute to have the same alignment of a member ( am i right ? ) But is it possible to define the same struct using managed C++/CLI and import this managed C++ code to my C# project and on this way to do the serialization ? If this is possible - so how to do it ? I can't find any example when i google it. Hans Passant No, this will not help you. C++/CLI also distinguishes between