Mixing C# and C++
Posted: 26 Mar 2015, 18:37
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
}