c++-cli

why doesn't this compile when using std::max and c++/CLI?

我们两清 提交于 2019-12-22 10:54:04
问题 Can anyone please explain why the following will compile int a = aAssignments[i]->Count; int b = fInstanceData->NumRequiredEmpsPerJob[i]; fInstanceData->NumSlotsPerJob[i] = max(a,b); but fInstanceData->NumSlotsPerJob[i] = max((int)(aAssignments[i]->Count), (int)(fInstanceData->NumRequiredEmpsPerJob[i])); //why on earth does this not work? wont? The error it gives is error C2665: 'std::max' : none of the 7 overloads could convert all the argument types The variable aAssigmments is of type

Can C++/CLI .NET use resource .resx files for localization?

眉间皱痕 提交于 2019-12-22 10:37:26
问题 I am trying to localize a managed C++ .NET DLL for multiple languages. The forms are easy enough because they operate just like the other languages and create multiple .resx files. I cannot find any examples of localizing embedded strings in managed C++, other than to use .RC string tables in the traditional C++ way. Is there any way to use .resx resource files to facilitate use with resource editors like Zeta, etc? 回答1: Create a separate resources file in managed C++ containing all the error

How do I convert a cli::array to a native array from native code?

喜欢而已 提交于 2019-12-22 08:57:56
问题 I'm writing a native wrapper around a managed component written in C++\CLI. I have the following function in managed code: array<Byte>^ Class::Function(); I want to expose this function from a native C++ class with the following signature: shared_array<unsigned char> Class::Function(); I've gotten as far as calling the managed function from native code, but I'm not sure how to safely copy the managed array into an unmanaged one. gcroot<cli::array<System::Byte>^> managedArray = _managedObject-

C++/CLI use of Action<…,…> and Func<…> unsupported?

蹲街弑〆低调 提交于 2019-12-22 08:46:08
问题 it does not look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as: System::Action<int, int>^ action = nullptr; System::Func<int, int>^ func = nullptr; Both result in errors such as: error C2977: 'System::Action' : too many generic arguments error C2955: 'System::Action' : use of class generic requires generic argument list Only single argument Action works: System::Action<int>^ action = nullptr;

Is there a C#'s unsafe equivalent in C++/CLI?

痞子三分冷 提交于 2019-12-22 08:23:37
问题 I am trying to port C++/CLI code into Verifiable Type-Safe C++/CLI code (Use clr:safe flag) so I can get a AnyCPU assembly. The main compilation problem I find is that, I get a lot of C4956 errors and I think, that might be solved by explicitly tell the compiler I expect this to be unsafe. Suggestions? 回答1: This has been covered here Basically, this is what /clr:pure was supposed to provide, because it also generates a pure MSIL assembly. Unfortunately it still causes a dependency on a

modopt and .NET reflection

拜拜、爱过 提交于 2019-12-22 07:28:08
问题 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

Initialize List<T> with array in CLR C++?

倖福魔咒の 提交于 2019-12-22 06:40:10
问题 I was wondering why this code does not work in C++/CLI but damn easy in C#? List<Process^>^ processList = gcnew List<Process^>( Process::GetProcessesByName(this->processName));); error C2664: 'System::Collections::Generic::List::List(System::Collections::Generic::IEnumerable ^)' : cannot convert parameter 1 from 'cli::array ^' to 'System::Collections::Generic::IEnumerable ^' Here is what I come up with. Did perfectly well. :) List<Process^>^ processList = gcnew List<Process^>( safe_cast

C++/CLI: CA2123: Requires SecurityCriticalAttribute?

风格不统一 提交于 2019-12-22 05:29:21
问题 I am a little lost on erros like that: Warning 7 CA2123 : Microsoft.Security : Add the following security attribute to 'RithmicConnector::Connect(String^)' in order to match a LinkDemand on base method 'IConnector::Connect(String^)': 'SecurityCriticalAttribute'. c:\work\nettecture\tradex\source\tradex.connectivity.rithmic\rithmicconnector.cpp 52 Tradex.Connectivity.Rithmic Where do I add the SecurityCriticalAttribute? I tried on the header file - but the error does not disappear. I have one

RAII in C++/CLI

我怕爱的太早我们不能终老 提交于 2019-12-22 04:37:26
问题 I'm used to the C++ RAII facilities, and I want to use RAII the right way with managed code in C++/CLI. Herb Sutter and Microsoft both tell me this is the best practice. I have something like this: ref struct Managed { // No default constructor Managed( /*...*/ ) { /*...*/ } ~Managed() { /* Important non-managed resource release here */ } // ... }; ref struct UsesManaged { Managed^ m_; array<Managed^>^ a_; UsesManaged( Managed^ m, array<Managed^>^ a ) : m_(m), a_(a) {} // ... }; ref struct

what is intptr?

一世执手 提交于 2019-12-22 04:19:06
问题 I didn't understand what is IntPtr, could someone explain this? thanks 回答1: It is the managed counterpart of void* . You can cast to and from void* for usage in managed code without having to resort to unsafe code in managed layers, eg C#. 回答2: It is an integer that is the same size as a pointer. 32 bits wide in 32 bit images, 64 wide in 64 bit images. 回答3: It's a .NET platform-specific type that is used to represent a pointer or a handle. The IntPtr type is designed to be an integer whose