How to call Standard C++ member functions in WinRT Class from C#?

  • Thread starter Thread starter siegfried_
  • Start date Start date
S

siegfried_

Guest
I want to create a C++ class with static and non-static member functions and call them from C#. I want to use standard C++ (and not /CX -- maybe I'll ask about /CX in another post). My C# code is not part of a Universal Windows Platform (UWP) App. It is not a GUI application.

(1) I see in Intro to WinRT that C++ WinRT is supposed to be substitute for C++/CX and WRL. This leads me to believe that my C# should be able to be independent of UWP.

(2) Can someone point me to some step by step instructions for creating a C++ project in Visual Studio and creating a second C# project that contains code that calls the C++ member functions in the first project? I've been looking for such a tutorial for years now.

(3) I've been reading this article in Microsoft Docs on Authoring APIs with C++/WinRT and I'm confused because it does not mention the using the Visual Studio extension (Download the Visual Studio WinRT Extension) and it does not explain how to create a new WinRT Component project.

(4) When I use Visual Studio 2019 V16.4.4 (after having installed the above extension) to create a new WinRT Component, the generated code has lots of syntax errors. (I also notice that in the description of the code generator, it says "A project for C++/WinRT Windows Runtime component that can be used by a Universal Windows Platform App". Perhaps this means I must call it from a UWP app and I'm out of luck. Is this true?). Rebuilding the solution does not help. The syntax errors include a missing "#include file" ("Class.g.h"). I suspect this is a file generated from the IDL and a "rebuild all" is not generating this header file. How do I fix this?

Thank you!

Siegfried


siegfried heintze

Continue reading...
 
Back
Top