I have Universal Windows C# class library with UI components. I was wondering if I can use it from Native C++.
I tried to use regasm to convert class library dll into tlb file, but it throws error
Error: Assembly must not be a Windows Runtime assembly.
Also I tried to make a WinRT/WRL wrapper for C# class library, and tried to load it from Native C++. But when I call LoadLibrary
for wrapper dll, it returns 'nullptr' with 126 error, even though all dlls and executables are in the same directory.
So how can I use Universal Windows class library from Native C++? Is it possible?
You will have to expose your class library as COM component and call it from native code, this is the most convenient solution. you won't be able to call Universal Windows C# class library from native C++, as it won't be recognized and, as you mentioned in your question, it will cause a nullptr
exception.
The interesting things is, you can do the other way around!
you can create a native C++ library and call it in Universal Windows C# platform - there is whole post in MSDN regarding this practice:
Use Existing C++ Code in a Universal Windows Platform App
funny thing in my opinion you can do one thing but not the other way around but still, it's good to know that at least one way is actually possible.
I am not sure "convenient" is the word I would use to describe exposing native C++ as a COM component.
You should take a look at C++/WinRT
https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis .
It appears to supersede C++/CX which was Microsoft's initial approach to allow C++ to be used to build and use WinRT components.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.