c++-cli

Pass an argument by reference in C++/CLI so re-assignment affects the caller

故事扮演 提交于 2019-11-30 17:54:14
Probably this is not a difficult question, but I am always a little bit confused on how to treat String type as an argument in Visual C++. I have the following to functions: void function_1(String ^str_1) { str_1 = gcnew String("Test"); } void function_2() { String ^str_2 = nullptr; function_1(str_2); } After calling function_1 , str_2 is still equal to null , but what I want to achieve is that str_2 is equal to Test . So, how can I achieve that the content of str_1 is passed to function_2 ? Thanks for any advice. Use a tracking reference : void function_1(String ^%str_1) { str_1 = gcnew

Cannot use managed event/objects in unmanaged code error c3265, c2811

戏子无情 提交于 2019-11-30 17:31:06
问题 Native C++ library that I am using in C++/CLI project raises events giving me results, If I try to handle the event by extending the unmanaged event, it says the ref class can only extend ref class. I then tried to create a native event but have manged object inside it to collect the results, but I get the error cannot declare managed object in unmanaged class. Is there anyway to get it done in one of the ways I am trying, or should I declare unmanaged result objects fill them in unmanaged

How can I mix the Concurrency Runtime with .NET code?

假如想象 提交于 2019-11-30 17:21:50
问题 I've been using the Concurrency Runtime in a C++ static library, and recently wanted to use this library in a C++/CLI project, to take advantage of the Windows Form designer and avoid MFC. Unfortunately, the Concurrency Runtime is not compatible with the /clr switch required in C++/CLI. I tried surrounding the included header files that use the Concurrency Runtime in the "#pragma unmanaged ... #pragma managed" directives, but while that's worked for me with other code in the past, it doesn't

How to use MonthCalender to insert date in text box?

落爺英雄遲暮 提交于 2019-11-30 16:40: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? 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) { monthCalendar1.Visible = true; } private void textBox1_Leave(object sender, EventArgs e) { if (!monthCalendar1

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

强颜欢笑 提交于 2019-11-30 15:03:26
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("MyCoolDll.dll") This worked fine, until I moved MyCoolDll.dll, DotNetDll1.dll & DotNetDll2.dll to

How to use managed code from unmanaged code?

╄→гoц情女王★ 提交于 2019-11-30 14:51:47
How do I call a .NET code from native C++ (unmanaged code)? I want to expose .NET code to my unmanaged (C++) application and then use them. More specifically, I want to call C# from native C++ :). I know there are many ways but can you tell me the pros and cons of each? By the way, I don't want to use COM so what are the options now? Is it possible that I wrap the C# code in C++/CLI and then call it from C++? If so, how do I do that? How do I wrap the C# in C++/CLI and then call it from C++? Robert Giesecke I've written about it just recently. It was about Delphi, but that doesn't mean it won

Please, describe you experience of using Microsoft C++/CLI [closed]

余生颓废 提交于 2019-11-30 14:04:29
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . C++/CLI is very powerful language. It's the only CLR language where you can seamlessly combine managed and unmanaged code. How many

Workaround for not having lambdas that can capture managed variables

三世轮回 提交于 2019-11-30 14:00:13
问题 In C++/CLI, you cannot create managed lambdas (like you can in C#), and thus you can't capture managed variables. You can create regular methods (rather than lambdas), but you are still left without being able to capture managed variables. Is there a standard workaround to employ in C++/CLI code? In other words I'm looking for a standard pattern I could use in C++/CLI to do the following from C#: class A { } class B { void Foo() { A a = new A(); Func<A> aFunc = () => a; // Captures a } } I

Destruction of Native Objects with Static Storage Duration

给你一囗甜甜゛ 提交于 2019-11-30 13:39:53
问题 2012-12-09 Summary: In a normal mixed-mode application global native C++ destructors run as finalizers. It's not possible to change that behavior or the associated timeout. A mixed-mode assembly DLL runs C++ constructors/destructors during DLL load/unload - exactly as a native DLL. Hosting the CLR in a native executable using the COM interface allows both the deconstructors to behave as in a native DLL (the behavior I desire) and setting the timeout for finalizers (an added bonus). As far as

Why is /clr incompatible with /mt and /mtd in Visual Studio?

别说谁变了你拦得住时间么 提交于 2019-11-30 13:11:46
问题 can anybody please explain for me how and why /clr is incompatible with /mtd ? What is the alternative for this? What happens internally if I use /md or /mdd ? As far as I know we don't combinedly use /clr and /mtd. Can someone explain if there is a way to do this? And please explain me how and why /clr is incompatible with /mt and /mtd in Visual Studio? 回答1: I expect the clue is given here: If you are using the /clr compiler switch, your code will be linked with an import library, msvcmrt