- darthmaule2
- Posts: 98
- Joined:
Mixing C# and C++
I'm wondering if it would be reasonable to attempt the following.
From a C# application, use a C++/CLI library to interface with a native C++ library that creates a window and shows video using DX11 and user controls via NoesisGui C# code behind.
More specifically,
1) Given that
From a C# STA Thread, you start a managed dispatcher thread from the threadpool using C++/CLI
And inside that thread:
2) Can Noesis C# classes run in the MTA thread above of MainDispatcher, with it’s Update(), WaitForUpdate() and Render() methods pinned (GCHandle::Alloc() + Marshal::GetFunctionPointerForDelegate() pattern) so they can be called from other native threads running in parallel with the managed dispatcher safely?
From a C# application, use a C++/CLI library to interface with a native C++ library that creates a window and shows video using DX11 and user controls via NoesisGui C# code behind.
More specifically,
1) Given that
From a C# STA Thread, you start a managed dispatcher thread from the threadpool using C++/CLI
Code: Select all
MainThread = gcnew Thread(gcnew ThreadStart(this, &CustomMTAContext::Main)); MainThread->Start();
And inside that thread:
Code: Select all
[System::MTAThreadAttribute]
void CustomMTAContext::Main()
{
MainDispatcher = Dispatcher::CurrentDispatcher;
m_customObj = new CustomNativeClass();
// this object currently holds Noesis C++ objects and
// hooks WndProc of the dispatcher for mouse/keyboard/touch
// intercept and interaction with a dedicated native render thread
MainDispatcher->Run(); //MTA message pump that can run managed delegates & native object/class methods
}
Re: Mixing C# and C++
Hi,
We never tried this scenario (mixing C# and C++ that way) so I am not sure it it will work. Anyways if you are using the C++ noesisGUI SDK you cannot have (easily) C# code behind. I think it would be easier using the C# SDK directly, wouldn't it?
Regarding 2) Yes, provided that all the calls are serialized and invoked from a single thread. And this is exactly the purpose of the Dispatcher.
We never tried this scenario (mixing C# and C++ that way) so I am not sure it it will work. Anyways if you are using the C++ noesisGUI SDK you cannot have (easily) C# code behind. I think it would be easier using the C# SDK directly, wouldn't it?
Regarding 2) Yes, provided that all the calls are serialized and invoked from a single thread. And this is exactly the purpose of the Dispatcher.
- darthmaule2
- Posts: 98
- Joined:
Re: Mixing C# and C++
Do you have a C# Demo app/tutorial so I could quickly see how to use NoesisGui directly from C#?
Re: Mixing C# and C++
Sorry for the delay but we wanted to update our C# SDK to be in sync with the last released version (v1.2.2). Also we have included a link in the download thread.
You can download it here.
Anyway, this version of noesisGUI is still in beta. There are still a few things to finish. For example, there is no BuildTool yet in C#. You can use the C++ version, although it won't work if you use x:Class.
You can download it here.
Anyway, this version of noesisGUI is still in beta. There are still a few things to finish. For example, there is no BuildTool yet in C#. You can use the C++ version, although it won't work if you use x:Class.