how to call code in C++ library that needs to keep a running thread from my WPF app
Posted on 2010-09-05
I have an unmanaged legacy C++ app.
I gave up on trying to load a stylized WPF window from a newly-managed C++/CLR build of the app,
and instead I tried creating a new C# app using the stylized WPF windows (by stylized I mean I'm using a 3rd party dll that contains xaml/wpf window styles).
in other words, I'm trying to recreated the UI part in a new C# app using WPF, but don't want to migrate all my legacy non-UI code.
The problem is I want to load my old C++ code from this new C# app in such a way that the C++ code can kick off a thread and keep it running in order to do all sorts of fancy stuff.
if I just call my main exported function, then it won't return control to my C# app until the thread exits.
Do I need to do a LoadLibrary() to make sure the dll stays in memory?
I want the C++ dll to kick off a thread and stay in memory while my C# WPF app displays a window (and the 2 should talk to each other of course) - not be sequential!
What's the right way to accomplish what I want to do?
public partial class App : Application
[DllImport("Client_DLL.dll", SetLastError = false)]
static extern int MyDllMain();
//IntPtr hDll = LoadLibrary("Client_DLL.dll");
int nRet = MyDllMain();