Click here to Skip to main content
15,440,926 members
Home / Discussions / Managed C++/CLI

Managed C++/CLI

PinnedThe C++ / CLI is for managed and mixed-mode C++ programming only Pin
Chris Maunder9-Jan-06 9:36
cofounderChris Maunder9-Jan-06 9:36 
QuestionHow does the compiler achieve the CRT remapping? Pin
John Schroedl22-Aug-22 10:50
professionalJohn Schroedl22-Aug-22 10:50 
Question[Solved] I hope there is a Managed C++/CLR person left to help me with Parallel::For Pin
madusmacus27-Jul-22 4:25
Membermadusmacus27-Jul-22 4:25 
AnswerRe: I hope there is a Managed C++/CLR person left to help me with Parallel::For Pin
Richard Deeming27-Jul-22 22:13
mveRichard Deeming27-Jul-22 22:13 
General[Final Code Here] Re: I hope there is a Managed C++/CLR person left to help me with Parallel::For Pin
madusmacus27-Jul-22 22:35
Membermadusmacus27-Jul-22 22:35 
Thank you very much Richard
If MS docs had C++ version of this i would have not neded to bother you
I was very confused as i dont do delegates if i can avoid it

Very happy some C++/CLR people still exist

ill mark as solved

Here is the Final working MainForm() showing cross thread update of textBox, Random, and usage of other Member funtions
This is here to help anyone that is as bad at this overcomplicated Parallel coding in C++/CLR (my opinion should be easier)

"Parallel::For" - intellisense still moans about 2 or more overloads of it but who cares anyway, no one :¬)

namespace CppTutorial {

	using namespace System;
    using namespace System::Threading::Tasks;
	using namespace System::Windows::Forms;

	/// <summary>
	/// Summary for MainForm
	/// </summary>
	public ref class MainForm : public System::Windows::Forms::Form
			//TODO: Add the constructor code here

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
			if (components)
				delete components;

	private: System::Windows::Forms::TextBox ^textBox1;


		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
			this->textBox1=(gcnew System::Windows::Forms::TextBox());
			// textBox1
			// MainForm
			this->Shown+=gcnew System::EventHandler(this,&MainForm::MainForm_Shown);

#pragma endregion


  static MainForm ^staticmain;
  Random ^rand1;
  static void Body(int index)
	// Randomly slow down thread
	int r=staticmain->rand1->Next(1000000);
	for(int i=0;i<r;i++){}
	// Append index and rnd text
	staticmain->textBox1->AppendText("i: "+Convert::ToString(index)+"  -   r: "+Convert::ToString(r)+"\r\n");
	// Call another MainForm member from inside Body

  System::Void MainForm_Shown(System::Object^ sender,System::EventArgs^ e) 
	// Save main as static for use in Body()
	// Allocate Random object for use in Body()
    rand1=gcnew Random();
	// Stop cross thrad exeptions
    System::Action <int> ^body = gcnew System::Action <int> (MainForm::Body);
    ParallelLoopResult ^result = Parallel::For(0, 20, body);

	void AnotherMethod()
		int test=1;


modified 29-Jul-22 3:41am.

Questionc++ forms 2022 code Pin
Member 884846417-Jun-22 1:37
MemberMember 884846417-Jun-22 1:37 
AnswerRe: c++ forms 2022 code Pin
Richard MacCutchan17-Jun-22 3:56
mveRichard MacCutchan17-Jun-22 3:56 
QuestionI want to write a C++/CLI wrapper class library which can be utilized in both C++ and C# applications. Pin
Member 121624009-Jun-22 21:45
MemberMember 121624009-Jun-22 21:45 
Questionsimplifying code Pin
hshan_15-Mar-22 6:30
Memberhshan_15-Mar-22 6:30 
AnswerRe: simplifying code Pin
Victor Nijegorodov15-Mar-22 9:22
MemberVictor Nijegorodov15-Mar-22 9:22 
GeneralRe: simplifying code Pin
Ghazi Warrior22-Mar-22 19:46
MemberGhazi Warrior22-Mar-22 19:46 
GeneralRe: simplifying code Pin
hshan_19-Apr-22 3:35
Memberhshan_19-Apr-22 3:35 
AnswerRe: simplifying code Pin
Craig Robbins15-Mar-22 9:25
MemberCraig Robbins15-Mar-22 9:25 
QuestionConvert From C# To Visual C++ 2015 Pin
Paramu197313-Dec-21 20:21
MemberParamu197313-Dec-21 20:21 
Rant[REPOST] Convert From C# To Visual C++ 2015 Pin
Richard Deeming13-Dec-21 21:56
mveRichard Deeming13-Dec-21 21:56 
GeneralRe: [REPOST] Convert From C# To Visual C++ 2015 Pin
Paramu197316-Dec-21 21:14
MemberParamu197316-Dec-21 21:14 
AnswerRe: Convert From C# To Visual C++ 2015 Pin
Richard MacCutchan13-Dec-21 21:58
mveRichard MacCutchan13-Dec-21 21:58 
GeneralRe: Convert From C# To Visual C++ 2015 Pin
Paramu197316-Dec-21 21:35
MemberParamu197316-Dec-21 21:35 
AnswerRe: Convert From C# To Visual C++ 2015 Pin
Dave Kreskowiak14-Dec-21 5:05
mveDave Kreskowiak14-Dec-21 5:05 
QuestionopenFileDialog - AccessViolationException was unhandled Pin
Paramu19734-Oct-21 12:28
MemberParamu19734-Oct-21 12:28 
AnswerRe: openFileDialog - AccessViolationException was unhandled Pin
Victor Nijegorodov5-Oct-21 21:26
MemberVictor Nijegorodov5-Oct-21 21:26 
GeneralRe: openFileDialog - AccessViolationException was unhandled Pin
Paramu19736-Oct-21 3:17
MemberParamu19736-Oct-21 3:17 
QuestionConvert/cast System::Array class to List Pin
yehiga146710-Jun-21 17:51
Memberyehiga146710-Jun-21 17:51 
AnswerRe: Convert/cast System::Array class to List Pin
Victor Nijegorodov10-Jun-21 20:27
MemberVictor Nijegorodov10-Jun-21 20:27 
AnswerRe: Convert/cast System::Array class to List Pin
Richard Andrew x6427-Jun-21 6:52
professionalRichard Andrew x6427-Jun-21 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.