c++-cli

Convert HWND to IntPtr (CLI)

隐身守侯 提交于 2019-11-30 02:10:31
问题 I have a HWND in my C++ MFC code, and I want to pass this HWND to a C# control and get it as IntPtr. What Is wrong in my code, and how can I do it correctly? (I think it's something with wrong using of the CLI pointers, because I get an error that it cannot convert from System::IntPtr^ to System::IntPtr. But I don't know how exactly to make it all to work properly...) My C++ MFC code: HWND myHandle= this->GetSafeHwnd(); m_CLIDialog->UpdateHandle(myHandle); My C# code: public void UpdateHandle

C++/CLI : Casting from unmanaged enum to managed enum

人盡茶涼 提交于 2019-11-30 01:29:58
What is the correct way of casting (in C++/CLI) from a native code enum to a managed code enum which contain the same enum values? Is there any difference with using the C# way of casting like for example (int) in C++/CLI. mcdave Assuming your native code is enum shape_type_e { stUNHANDLED = 0, //!< Unhandled shape data. stPOINT = 1 //!< Point data. ... }; and your managed code is public enum class ShapeType { Unhandled = 0, Point = 1, ... }; You can cast from the native to the managed using shape_type_e nativeST = stPOINT; ShapeType managedST = static_cast<ShapeType>(nativeST); Debug.Assert

How to use MonthCalender to insert date in text box?

我的未来我决定 提交于 2019-11-30 00:00:38
问题 I have a textBox1 in my windows form. I would like to use it to get date from the user. I want to show MonthCalender1 once the user put the cursor in the textbox1 and then set the date in the textbox1 automatically and then the calender will disappear. How can I use C# or C++/CLI to do that? 回答1: This is not the best code, but I hope you get the idea: public Form1() { InitializeComponent(); monthCalendar1.MaxSelectionCount = 1; } private void textBox1_Enter(object sender, EventArgs e) {

raise events in c++/cli dll and consume in c#

冷暖自知 提交于 2019-11-29 22:37:29
问题 In my c# app I have a progressbar. C# app is calling a c++/cli dll which processes a number of files. As each file is processed in the dll I would like to track it's progress in the c# app. For this i need to raise an event in c++/cli and consume it in C#. From MSDN I gather I need in my c++/cli class the following: delegate void Del(int); event Del^ E; void fire(int i) { E(i); } MSDN Events In MSDN the receiver of the event is in the same c++/cli project and it is shown how to raise the

Loading Mixed-Mode C++/CLI .dll (and dependencies) dynamically from unmanaged c++

江枫思渺然 提交于 2019-11-29 22:13:29
问题 I have a managed C++ assembly I'm loading dynamically in an unmanaged c++ application through a standard LoadLibrary() call. The managed C++ assembly has dependencies on several more managed (C#) assemblies. Everything worked fine until I moved all the managed assemblies to a subdirectory of the unmananged application. To illustrate: Managed C++ .dll (MyCoolDll.dll) Dependent on DotNetDll1.dll Dependent on DotNetDll2.dll Unmanaged C++ app (MyCoolApp.exe) Loads MyCoolDll.dll via LoadLibrary(

Documenting C++/CLI library code for use from c# - best tools and practices? [closed]

霸气de小男生 提交于 2019-11-29 22:05:59
I'm working on a project where a c++/cli library is being used primarily from a c# application. Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio? Assuming there isn't, what would be the best way to document the c++/cli code to enable its easier use from c# (and within c++/cli of course)? What is you opinion on XML comments vs doxygen vs other tools (which)? Zoinks I have gotten it to work as follows: Use XML style comments for your C++/CLI header entries. This means the full XML comment is required (triple-slash comments, <summary> tag at a

Can I use C++/CLI (.NET Winforms/WPF ) to provide GUI for app written in native C & C++

情到浓时终转凉″ 提交于 2019-11-29 22:02:05
问题 I've an app written C & C++. Now, I need to provide a GUI for this app. MFC is the best option for me. But I'm not familiar with MFC. So can I use .NET to build GUI for this? If so, How? Please be clear. If I can use .NET I guess I can use WPF too right? 回答1: You can technically write a GUI in C++/CLI, but I would highly discourage it. C++/CLI is good for writing .NET wrappers around native C++ and exposing it to other .NET languages, but not much else. In your case, if you're really set on

Visual C++ 2010: Changes to MSVC runtime deployment (no more SxS with manifest)

烂漫一生 提交于 2019-11-29 20:41:40
Where can I find some official note, kb article or other documentation describing changes to the Visual Studio 2010 C/C++ runtime linking and deployment policy? Under Visual Studio 2008 (with the VC90 runtime) a manifest was embedded in native images, and the runtime libraries were deployed as side-by-side assemblies (WinSxS). This caused problems when rebuilding a native exe or library using VS 2008 SP1, in that an updated version of the C++ runtime was required by the embedded manifest. For VS 2010 and the MSVCR100 runtime version, the policy seems to have changed completely. The file

Including headers from an unmanaged C++ code inside C++/CLI code

青春壹個敷衍的年華 提交于 2019-11-29 18:02:01
I'm writing a CLR wrapper for an unmanaged C++ library. There are two files I'm including from the unmanaged lib: //MyCLIWrapper.h #include "C:\PATH\TO\UNMANAGED\Header.h" #include "C:\PATH\TO\UNMANAGED\Body.cpp" Then I'm writing CLI implementations for the unmanaged library functions: //MyCLIWrapper.h // includes ... void MyCLIWrapper::ManagedFunction() { UnmanagedFunction(); // this function is called successfuly } However, if my Unmanaged function contains calls to other functions that are defined in other unmanaged header files. This causes a compiler linkage error. If I add includes to

C++/CLI-Question: Is there an equivalent to the C# “is” keyword or do I have to use reflection?

不问归期 提交于 2019-11-29 17:53:22
问题 I've read somewhere on MSDN that the equivalent to C#'s "is" keyword would be dynamic_cast, but that's not really equivalent: It doesn't work with value types or with generic parameters. For example in C# I can write: void MyGenericFunction<T>() { object x = ... if (x is T) ...; } If I try the "equivalent" C++/CLI: generic<class T> void MyGenericFunction() { object x = ... if (dynamic_cast<T>(x)) ...; } I get a compiler error "error C2682: cannot use 'dynamic_cast' to convert from 'System: