kvanbere
kvanbere

Reputation: 3352

Load a C# WPF form inside a library from a CLI C++ application

I have a dll file written in C# that is in the same solution as my application which is written in C++ with some files set to compile under the /cli flag. I'd like to load the WPF form inside my C# dll and display it in the C++ /cli application.

I already have my C++ application configured to display WPF content, as I am currently programatically adding controls onto the WPF form but I have not been able to find out how to load a form from an external resource at runtime.

Upvotes: 2

Views: 1557

Answers (2)

Miguel Tomás
Miguel Tomás

Reputation: 1911

You can load an external DLL into your project like this

Dim assembly As Assembly = Assembly.LoadFile(libraryPath & "filename.dll")
Dim type As Type = assembly.[GetType]("NameSpace.ClassName")

// i'm loading as a form here but can be any control
Dim frm As Form = TryCast(Activator.CreateInstance(type), Form)

one final note, if you're loading a class or control inside the loaded form (above) that resides also inside the same assembly you also need to load it first before calling it in the form

Upvotes: 0

gliderkite
gliderkite

Reputation: 8928

If you added the control reference to your CLI project, you should be able to have access to your control; having application handle use ApplicationHandle->Run(YourWindow) method.

Upvotes: 2

Related Questions