c++-cli

Does C++/CLI event have any listeners?

你。 提交于 2019-12-04 08:01:00
In C# I can check if an event has any listeners: C# Example: public static event EventHandler OnClick; if (OnClick != null) OnClick(null, new EventArgs() ); In C++/CLI checking if the event is null is not necessary. C++/CLI Example: delegate void ClickDelegate( Object^ sender, MyEventArgs^ e ); event ClickDelegate^ OnClick; OnClick (sender, args); BUT, in the project I am working on, I don’t want to construct the MyEventArgs object if there are no listeners. How do I find out if OnClick has any listeners in C++? It seems you can't check that with "trivial events", like you used, because you

LPOVERLAPPED_COMPLETION_ROUTINE is incompatible with function

旧城冷巷雨未停 提交于 2019-12-04 06:27:53
问题 I want to asynchronously write data to file using WriteFileEx from winapi , but I have a problem with callback. I'm getting follow error: an argument of type "void (*) (DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped)" is incompatible with parameter of type "LPOVERLAPPED_COMPLETION_ROUTINE" What am I doing wrong? Here is code: // Callback void onWriteComplete( DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) { return; } BOOL

Wrapping an Unmanaged C++ Class Library with C++/CLI - Question 2 - Collections

拜拜、爱过 提交于 2019-12-04 06:03:08
Note: This post represents Question #2 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 wrap the common library with C++/CLI wrapper classes. The classes contained in the common library can be

C++/CLI DLL namespace not found in MSVS C# Project (successfully reproducible)

ε祈祈猫儿з 提交于 2019-12-04 04:48:02
问题 I have a similar problem to C++/CLI DLL namespace not found in MSVS. I am using VS2010. I have a C++/CLI Assembly (DLL) that contains managed wrapper (public ref classes) code about unmanaged C++ code. When I reference this project from a C# project (in my actual project, its a C# class library, but I can duplicate this behaviour with a C# winforms application), no types are accessible (verified in the Object browser). I get, for example, " error CS0246: The type or namespace name 'CLILib2'

Adding Existing Form to C++/CLI WinForms Project

拥有回忆 提交于 2019-12-04 04:39:12
I have two C++/CLI projects A and B in separate solutions. I use A for experiments/testing and move the tested code to B once I am finished testing. However, I find that on adding a windows forms class (header, cpp and resx) to project B, I am no longer able to use the visual forms designer of the IDE. How do I enable that? Got it! Open the Solution Explorer pane and the Properties pane side-by-side. Select the header file for the form class in the Solution Explorer pane. In the properties pane, select "C++ Form" under the "File Type" property. The header file will now display a form icon next

What is “verifiable managed assembly”

依然范特西╮ 提交于 2019-12-04 04:31:12
问题 While checking the possibility of developing for Windows Phone 7 using C++, I came across this thread, which states: "...any language that can compile to a verifiable managed assembly (the verifiability requirement applies to all dependencies, too!) is good" (for WP7 development) What is "verifiable managed assembly" and where can I learn more about this? 回答1: Verifiable code is code that gets compiled to IL and can be proven to not produce any IL that can execute unsafe code, bypass code

Can I implement .ToString() on C++ structs for debugging purposes?

扶醉桌前 提交于 2019-12-04 04:26:37
In C#, if I define a struct, I can also override ToString(). Then when I'm debugging and I add a watch or hover my mouse over an instance of the struct, the tooltip will be the computed ToString() rather than the type name of the struct. Can I do that in C++ and/or C++/CLI somehow? That is, can I define a method as part of the struct (or do anything else) that will cause the watch-value/tooltip to display a string of my choosing? The default string rendering in Visual Studio for C/C++ is a list of all the struct's field values (or as many as can be jammed into the little box). My types all C

Error Compiling C++/CLI Delegate call using Predicate with Array::FindAll()

孤街浪徒 提交于 2019-12-04 04:20:23
The following code results in C3867 (...function call missing argument list...) and C3350 (...a delegate constructor expects 2 argument(s)...). What am I doing wrong? public ref class Form1 : public System::Windows::Forms::Form { public: bool IsEven(int i){ return (i % 2) == 0; } Form1(void) { numbers = gcnew array<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; array<int> ^even = Array::FindAll( numbers, gcnew Predicate<int>(IsEven)); } }; In C++/CLI you have to pass the actual instance of the type containing the function: array<int> ^even = Array::FindAll( numbers, gcnew Predicate<int>(this, &Test:

Use C++ CLI template class in C#

天涯浪子 提交于 2019-12-04 04:13:25
I have the following class in C++/CLI and an explicit template instantiation for the int primitive.. template<typename T> public ref class Number { T _value; public: static property T MinValue { T get() { return T::MinValue; } } static property T MaxValue { T get() { return T::MaxValue; } } property T Value { T get() { return _value; } void set(T value) { if( value<MinValue || value > MaxValue) throw gcnew System::ArgumentException("Value out of range"); _value = value; } } }; template ref class Number<int>; On compiling this and inspecting the generated assembly using reflector I am able to

Initialize static Dictionary while creating in C++/CLI

老子叫甜甜 提交于 2019-12-04 02:40:10
Today I saw C# code that creates static dictionary and initializes it: public static readonly Dictionary<string, string> dict = new Dictionary<string, string>() { {"br","value1"}, {"cn","value2"}, {"de","value3"}, }; but when I decided to write same code for C++/CLI, an error occurred. Here is my attempt: static System::Collections::Generic::Dictionary<System::String^, System::String^>^ dict = gcnew System::Collections::Generic::Dictionary<System::String^, System::String^>( ) { {"br","value1"}, {"cn","value2"}, {"de","value3"}, }; Can I do this and if so, how? KeithS C# 3.0 and later allows