@@ -38,12 +38,12 @@ private async void myButton_Click(object sender, RoutedEventArgs e)
38
38
39
39
//Interop helpers for non-CoreWindow
40
40
IntPtr windowHandle = ( App . Current as App ) . WindowHandle ;
41
- System . Diagnostics . Debug . WriteLine ( "WindowId:" + windowHandle . ToString ( ) ) ;
42
41
var result = await UserConsentVerifierInterop . RequestVerificationForWindowAsync ( windowHandle , "test" ) ;
42
+
43
43
}
44
44
}
45
45
46
-
46
+
47
47
//MIDL_INTERFACE("39E050C3-4E74-441A-8DC0-B81104DF949C")
48
48
//IUserConsentVerifierInterop : public IInspectable
49
49
//{
@@ -54,7 +54,7 @@ private async void myButton_Click(object sender, RoutedEventArgs e)
54
54
// /* [in] */ REFIID riid,
55
55
// /* [iid_is][retval][out] */ void **asyncOperation) = 0;
56
56
//};
57
-
57
+
58
58
[ ComImport ]
59
59
[ Guid ( "39E050C3-4E74-441A-8DC0-B81104DF949C" ) ]
60
60
// Note: Invoking methods on ComInterfaceType.InterfaceIsIInspectable interfaces
@@ -65,23 +65,56 @@ public interface IUserConsentVerifierInterop
65
65
void GetIids ( out int iidCount , out IntPtr iids ) ;
66
66
void GetRuntimeClassName ( out IntPtr className ) ;
67
67
void GetTrustLevel ( out TrustLevel trustLevel ) ;
68
- void RequestVerificationForWindowAsync ( IntPtr appWindow , IntPtr hstrMessage , [ In ] Guid riid , out IntPtr outPtr ) ;
68
+ void RequestVerificationForWindowAsync ( IntPtr appWindow , IntPtr hstrMessage , [ In ] ref Guid riid , out IntPtr outPtr ) ;
69
69
}
70
70
71
71
//Helper to initialize UserConsentVerifier
72
72
public static class UserConsentVerifierInterop
73
73
{
74
74
public static IAsyncOperation < UserConsentVerificationResult > RequestVerificationForWindowAsync ( IntPtr hWnd , string Message )
75
75
{
76
- Guid guid = typeof ( IAsyncOperation < UserConsentVerificationResult > ) . GUID ;
77
-
76
+ //Use WinRT's GuidGenerator to get the correct guid
77
+ var guid = GuidGenerator . CreateIID ( typeof ( IAsyncOperation < UserConsentVerificationResult > ) ) ;
78
+
79
+ //leverage winrt .As<> operator to cast winrt type to its interop interface
78
80
IUserConsentVerifierInterop userConsentVerifierInterop = UserConsentVerifier . As < IUserConsentVerifierInterop > ( ) ;
81
+
82
+ //Handle marshalling the string to WinRT's HString
79
83
var marshalStr = MarshalString . CreateMarshaler ( Message ) ;
80
84
85
+ //Call the Interop api that pops a dialog, passing in the hWnd parameter
81
86
IntPtr outPtr ;
82
- userConsentVerifierInterop . RequestVerificationForWindowAsync ( hWnd , MarshalString . GetAbi ( marshalStr ) , guid , out outPtr ) ;
87
+ userConsentVerifierInterop . RequestVerificationForWindowAsync ( hWnd , MarshalString . GetAbi ( marshalStr ) , ref guid , out outPtr ) ;
88
+
89
+ //Marshal the return object as an IAsyncOperation<>
83
90
return ( IAsyncOperation < UserConsentVerificationResult > ) IInspectable . FromAbi ( outPtr ) ;
91
+
84
92
}
85
93
}
86
94
95
+
96
+ //MIDL_INTERFACE("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")
97
+ //IInspectable : public IUnknown
98
+ //{
99
+ //public:
100
+ // virtual HRESULT STDMETHODCALLTYPE GetIids(
101
+ // /* [out] */ __RPC__out ULONG *iidCount,
102
+ // /* [size_is][size_is][out] */ __RPC__deref_out_ecount_full_opt(* iidCount) IID **iids) = 0;
103
+ // virtual HRESULT STDMETHODCALLTYPE GetRuntimeClassName(
104
+ // /* [out] */ __RPC__deref_out_opt HSTRING *className) = 0;
105
+ // virtual HRESULT STDMETHODCALLTYPE GetTrustLevel(
106
+ // /* [out] */ __RPC__out TrustLevel *trustLevel) = 0;
107
+ //};
108
+
109
+ //[ComImport]
110
+ //[Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")]
111
+ //[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
112
+ //public interface WinRTIInspectable
113
+ //{
114
+ // void GetIids(out int iidCount, out IntPtr iids);
115
+ // void GetRuntimeClassName(out IntPtr className);
116
+ // void GetTrustLevel(out TrustLevel trustLevel);
117
+ //}
118
+
119
+
87
120
}
0 commit comments