How to pass a Win32 struct to a C++/WinRT class

loop123123 1 Reputation point
2023-03-30T01:53:02.9233333+00:00

How do you set up a WinRT class such that it can accept a Win32 struct as a method parameter? For example, a PROPERTYKEY struct? MIDL 3.0 won't accept that as a type, and box_value won't convert it either. Any suggestions? Thanks.

Windows development | Windows App SDK
Developer technologies | C++
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2023-03-31T02:45:36.4+00:00

    Hello @loop123123 , Welcome to Microsoft Q&A!

    As far as I'm concerned,

    1. you can define a structure or a class for the Win32 structure. Use ref const for immutable Struct only to optimize Performance, See Parameters.
    2. even further, you can write an overload of the winrt::box_value function for the Win32 structure like winrt::hstring.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.