Reputation: 160
I'm attempting to use the SimpleCommunication C++ DLL that Microsoft in one of their UWP sample examples inside a Win32 C# WPF application.
I've tried to add a reference to the both the .dll and .winmd files that are generated when building the SimpleCommunication .dll into my Win32 C# WPF application however whenever I attempt to call any function from SimpleCommunication I get the following exception message:
Exception thrown: 'System.TypeLoadException' in mscorlib.dll An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll Could not find Windows Runtime type 'Microsoft.Samples.SimpleCommunication.StspMediaSinkProxy'.
As far as I know this C++ dll is being built as a C++/CX (because its using the /ZW flag in the compiler) and because of this it contains unmanaged code, so I'm assuming I'll need some sort of wrapper to be able to call these functions from my managed wpf application but I'm not really sure what the best way to approach this would be, any help would be really appreciated!
Upvotes: 2
Views: 1020
Reputation: 12019
Although WPF applications can use system-provided WinRT types (those in the Windows
namespace), they cannot use custom WinRT types because Windows doesn't know how to locate them. The solution is to use the Desktop Bridge to add your WPF application to an AppX package, at which point Windows will be able to locate and activate your types.
(Note: you do not have to submit your app to the Store to use the Desktop Bridge; it's just a mechanism to package your app).
Upvotes: 3