Skip to content

Commit edb372c

Browse files
committed
fixed Guid generation
1 parent f5f6f02 commit edb372c

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

App16.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ VisualStudioVersion = 16.0.31025.218
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "App16 (Package)", "App16\App16 (Package)\App16 (Package).wapproj", "{5E028D7B-E358-4EA0-B19B-791AA3B50229}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App16", "App16\App16\App16.csproj", "{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App16", "App16\App16\App16.csproj", "{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
1213
Debug|arm64 = Debug|arm64
1314
Debug|x64 = Debug|x64
1415
Debug|x86 = Debug|x86
16+
Release|Any CPU = Release|Any CPU
1517
Release|arm64 = Release|arm64
1618
Release|x64 = Release|x64
1719
Release|x86 = Release|x86
1820
EndGlobalSection
1921
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|Any CPU.ActiveCfg = Debug|x86
2023
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|arm64.ActiveCfg = Debug|arm64
2124
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|arm64.Build.0 = Debug|arm64
2225
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|arm64.Deploy.0 = Debug|arm64
@@ -26,6 +29,7 @@ Global
2629
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|x86.ActiveCfg = Debug|x86
2730
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|x86.Build.0 = Debug|x86
2831
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Debug|x86.Deploy.0 = Debug|x86
32+
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|Any CPU.ActiveCfg = Release|x86
2933
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|arm64.ActiveCfg = Release|arm64
3034
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|arm64.Build.0 = Release|arm64
3135
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|arm64.Deploy.0 = Release|arm64
@@ -35,12 +39,14 @@ Global
3539
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|x86.ActiveCfg = Release|x86
3640
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|x86.Build.0 = Release|x86
3741
{5E028D7B-E358-4EA0-B19B-791AA3B50229}.Release|x86.Deploy.0 = Release|x86
42+
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|Any CPU.ActiveCfg = Debug|x86
3843
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|arm64.ActiveCfg = Debug|arm64
3944
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|arm64.Build.0 = Debug|arm64
4045
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|x64.ActiveCfg = Debug|x64
4146
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|x64.Build.0 = Debug|x64
4247
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|x86.ActiveCfg = Debug|x86
4348
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Debug|x86.Build.0 = Debug|x86
49+
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Release|Any CPU.ActiveCfg = Release|x86
4450
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Release|arm64.ActiveCfg = Release|arm64
4551
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Release|arm64.Build.0 = Release|arm64
4652
{46A6E40C-6177-4560-8C5A-FCAE6B7143A5}.Release|x64.ActiveCfg = Release|x64

App16/App16/MainWindow.xaml.cs

+40-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ private async void myButton_Click(object sender, RoutedEventArgs e)
3838

3939
//Interop helpers for non-CoreWindow
4040
IntPtr windowHandle = (App.Current as App).WindowHandle;
41-
System.Diagnostics.Debug.WriteLine("WindowId:" + windowHandle.ToString());
4241
var result = await UserConsentVerifierInterop.RequestVerificationForWindowAsync(windowHandle, "test");
42+
4343
}
4444
}
4545

46-
46+
4747
//MIDL_INTERFACE("39E050C3-4E74-441A-8DC0-B81104DF949C")
4848
//IUserConsentVerifierInterop : public IInspectable
4949
//{
@@ -54,7 +54,7 @@ private async void myButton_Click(object sender, RoutedEventArgs e)
5454
// /* [in] */ REFIID riid,
5555
// /* [iid_is][retval][out] */ void **asyncOperation) = 0;
5656
//};
57-
57+
5858
[ComImport]
5959
[Guid("39E050C3-4E74-441A-8DC0-B81104DF949C")]
6060
// Note: Invoking methods on ComInterfaceType.InterfaceIsIInspectable interfaces
@@ -65,23 +65,56 @@ public interface IUserConsentVerifierInterop
6565
void GetIids(out int iidCount, out IntPtr iids);
6666
void GetRuntimeClassName(out IntPtr className);
6767
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);
6969
}
7070

7171
//Helper to initialize UserConsentVerifier
7272
public static class UserConsentVerifierInterop
7373
{
7474
public static IAsyncOperation<UserConsentVerificationResult> RequestVerificationForWindowAsync(IntPtr hWnd, string Message)
7575
{
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
7880
IUserConsentVerifierInterop userConsentVerifierInterop = UserConsentVerifier.As<IUserConsentVerifierInterop>();
81+
82+
//Handle marshalling the string to WinRT's HString
7983
var marshalStr = MarshalString.CreateMarshaler(Message);
8084

85+
//Call the Interop api that pops a dialog, passing in the hWnd parameter
8186
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<>
8390
return (IAsyncOperation<UserConsentVerificationResult>)IInspectable.FromAbi(outPtr);
91+
8492
}
8593
}
8694

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+
87120
}

0 commit comments

Comments
 (0)