darthmaule2
Topic Author
Posts: 98
Joined: 23 Oct 2014, 19:54

Mixing C# and C++

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
 MainThread = gcnew Thread(gcnew ThreadStart(this, &CustomMTAContext::Main));  MainThread->Start();

And inside that thread:
[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
}
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?
 
User avatar
jsantos
Site Admin
Posts: 4123
Joined: 20 Jan 2012, 17:18
Contact:

Re: Mixing C# and C++

30 Mar 2015, 12:22

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.
 
darthmaule2
Topic Author
Posts: 98
Joined: 23 Oct 2014, 19:54

Re: Mixing C# and C++

01 Apr 2015, 19:11

Do you have a C# Demo app/tutorial so I could quickly see how to use NoesisGui directly from C#?
 
User avatar
jsantos
Site Admin
Posts: 4123
Joined: 20 Jan 2012, 17:18
Contact:

Re: Mixing C# and C++

03 Apr 2015, 15:05

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.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], maherne and 4 guests