Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interop interfaces are all pass-by-ref for IID param #894

Merged
merged 2 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Tests/TestComponentCSharp/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,25 @@ namespace winrt::TestComponentCSharp::implementation
return winrt::make<service_provider>();
}

struct __declspec(uuid("15651B9F-6C6B-4CC0-944C-C7D7B0F36F81")) IComInterop : ::IUnknown
Scottj1s marked this conversation as resolved.
Show resolved Hide resolved
{
virtual HRESULT __stdcall GetForWindow(HWND window, guid riid, int64_t* value) noexcept = 0;
};

WF::IInspectable Class::ComInterop()
{
struct com_interop : winrt::implements<com_interop, WF::IInspectable, IComInterop>
{
HRESULT __stdcall GetForWindow(HWND window, guid riid, int64_t* value) noexcept override
{
*value = riid == winrt::guid_of<IComInterop>() ? (int64_t)window : 0;
return 0;
}
};

return winrt::make<com_interop>();
}

// INotifyDataErrorInfo
bool Class::HasErrors()
{
Expand Down
1 change: 1 addition & 0 deletions src/Tests/TestComponentCSharp/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ namespace winrt::TestComponentCSharp::implementation

static IProperties1 NativeProperties1();
static Windows::Foundation::IInspectable ServiceProvider();
static winrt::Windows::Foundation::IInspectable ComInterop();

// IStringable
hstring ToString();
Expand Down
1 change: 1 addition & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ namespace TestComponentCSharp
// Interface projections
static IProperties1 NativeProperties1{ get; };
static Object ServiceProvider{ get; };
static Object ComInterop{ get; };

// INotifyDataErrorInfo
void RaiseDataErrorChanged();
Expand Down
30 changes: 30 additions & 0 deletions src/Tests/UnitTest/ComInteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,43 @@
using Windows.UI.Input.Spatial;
using Windows.UI.ViewManagement;
using Xunit;
using WinRT;
using TestComponentCSharp;

namespace UnitTest
{
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("15651B9F-6C6B-4CC0-944C-C7D7B0F36F81")]
internal interface IComInterop
{
Int64 GetForWindow(IntPtr hwnd, Guid iid);
}

// Note: Many of the COM interop APIs cannot be easily tested without significant test setup.
// These cases either expect a runtime exception, or are compile-time only (skipped to validate types).
public class ComInteropTests
{
[Fact]
public void TestHWND()
{
var comInterop = Class.ComInterop.As<IComInterop>();
if (System.Environment.Is64BitProcess)
{
var hwnd = new IntPtr(0x0123456789ABCDEF);
var value = comInterop.GetForWindow(hwnd, typeof(IComInterop).GUID);
var hwndValue = hwnd.ToInt64();
Assert.Equal(hwndValue, value);
}
else
{
var hwnd = new IntPtr(0x01234567);
var value = comInterop.GetForWindow(hwnd, typeof(IComInterop).GUID);
var hwndValue = hwnd.ToInt32();
Assert.Equal(hwndValue, value);
}
}

[Fact]
public void TestAccountsSettingsPane()
{
Expand Down
6 changes: 5 additions & 1 deletion src/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ if "%cswinrt_build_only%"=="true" goto :eof
:unittest
rem Build/Run xUnit tests, generating xml output report for Azure Devops reporting, via XunitXml.TestLogger NuGet
echo Running cswinrt unit tests for %cswinrt_platform% %cswinrt_configuration%
set dotnet_exe="%DOTNET_ROOT%\dotnet.exe"
if %cswinrt_platform%==x86 (
set dotnet_exe="%DOTNET_ROOT(86)%\dotnet.exe"
) else (
set dotnet_exe="%DOTNET_ROOT%\dotnet.exe"
)
if not exist %dotnet_exe% (
if %cswinrt_platform%==x86 (
set dotnet_exe="%ProgramFiles(x86)%\dotnet\dotnet.exe"
Expand Down
34 changes: 17 additions & 17 deletions src/cswinrt/WinRT.Interop.idl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND appWindow,
GUID riid);
ref const GUID riid);
Object ShowManageAccountsForWindowAsync(
HWND appWindow,
GUID riid);
ref const GUID riid);
Object ShowAddAccountForWindowAsync(
HWND appWindow,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -41,7 +41,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND hwnd,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -52,7 +52,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND appWindow,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -63,7 +63,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND appWindow,
GUID riid);
ref const GUID riid);

void ShowPlayToUIForWindow(
HWND appWindow);
Expand All @@ -77,11 +77,11 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND appWindow,
GUID riid);
ref const GUID riid);

Object ShowPrintUIForWindowAsync(
HWND appWindow,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -92,7 +92,7 @@ namespace WinRT.Interop
{
Object CreateForWindow(
HWND hwnd,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -102,7 +102,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND hwnd,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -112,7 +112,7 @@ namespace WinRT.Interop
{
Object CreateForWindow(
HWND hwnd,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -124,7 +124,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND window,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -135,7 +135,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND appWindow,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -146,7 +146,7 @@ namespace WinRT.Interop
{
Object GetForWindow(
HWND hwnd,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -158,7 +158,7 @@ namespace WinRT.Interop
Object RequestVerificationForWindowAsync(
HWND appWindow,
String message,
GUID riid);
ref const GUID riid);
}
#endif

Expand All @@ -170,13 +170,13 @@ namespace WinRT.Interop
Object RequestTokenForWindowAsync(
HWND appWindow,
Windows.Security.Authentication.Web.Core.WebTokenRequest request,
GUID riid); // __uuidof(IAsyncOperation<WebTokenRequestResult*>)
ref const GUID riid); // __uuidof(IAsyncOperation<WebTokenRequestResult*>)

Object RequestTokenWithWebAccountForWindowAsync(
HWND appWindow,
Windows.Security.Authentication.Web.Core.WebTokenRequest request,
Windows.Security.Credentials.WebAccount webAccount,
GUID riid); // __uuidof(IAsyncOperation<WebTokenRequestResult*>)
ref const GUID riid); // __uuidof(IAsyncOperation<WebTokenRequestResult*>)
}
#endif
}