Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@
/PackageMultipleApps/x64/Debug/ControlsLib
/WinUI3_GenCsProjection/WinRtComponentProjection/bin/Debug/net7.0-windows10.0.22621.0
/WinUI3_GenCsProjection/WinUI3_GenCsProjection/bin/x64/Debug/net7.0-windows10.0.22621.0/win10-x64
/WinUi3_Ipc_comm/WinUi3_Ipc_comm/Generated Files
/WinUi3_Ipc_comm/WinUi3_Ipc_comm/x64/Debug
/WinUi3_Ipc_comm/x64/Debug
/WinUi3_Ipc_comm/packages
/WinUi3_Ipc_comm/.vs/WinUi3_Ipc_comm
43 changes: 43 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33927.249
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IpcApp", "WinUi3_Ipc_comm\WinUi3_Ipc_comm.vcxproj", "{8CE8331A-546C-4F93-942A-910BA6AFD7A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|ARM64.ActiveCfg = Debug|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|ARM64.Build.0 = Debug|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|ARM64.Deploy.0 = Debug|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x64.ActiveCfg = Debug|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x64.Build.0 = Debug|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x64.Deploy.0 = Debug|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x86.ActiveCfg = Debug|Win32
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x86.Build.0 = Debug|Win32
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Debug|x86.Deploy.0 = Debug|Win32
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|ARM64.ActiveCfg = Release|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|ARM64.Build.0 = Release|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|ARM64.Deploy.0 = Release|ARM64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x64.ActiveCfg = Release|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x64.Build.0 = Release|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x64.Deploy.0 = Release|x64
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x86.ActiveCfg = Release|Win32
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x86.Build.0 = Release|Win32
{8CE8331A-546C-4F93-942A-910BA6AFD7A6}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2782595A-5155-48EF-8ABB-F8ECC89EBC8B}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/App.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace IpcApp
{
}
16 changes: 16 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="IpcApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:IpcApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
50 changes: 50 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/App.xaml.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"

#include "App.xaml.h"
#include "MainWindow.xaml.h"

using namespace winrt;
using namespace Windows::Foundation;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Microsoft::UI::Xaml::Navigation;
using namespace IpcApp;
using namespace IpcApp::implementation;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
InitializeComponent();

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched(LaunchActivatedEventArgs const&)
{
window = make<MainWindow>();
window.Activate();


}
19 changes: 19 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/App.xaml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "App.xaml.g.h"

namespace winrt::IpcApp::implementation
{
struct App : AppT<App>
{
App();

void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

private:
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WinUi3_Ipc_comm/WinUi3_Ipc_comm/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 145 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/CoComProxyData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#pragma once

#include <unknwn.h>

namespace IpcApp
{
static constexpr GUID COM_PROXY_DATA_GUID // {BAF2FA77-E111-4Cb9-A841-CE335B6F917F}
{
0xBAF2FA77, 0xE111, 0x4Cb9, { 0xA8, 0x41, 0xCE, 0x33, 0x5B, 0x6F, 0x91, 0x7F }
};

struct __declspec(uuid("BAF2FA77-E111-4Cb9-A841-CE335B6F917F"))
CoComProxyData : winrt::implements<CoComProxyData, IUnknown>
{
winrt::hstring ToString()
{
return L"MyCoclass as a string";
}

// // Implement the IUnknown methods.
// ULONG STDMETHODCALLTYPE AddRef() noexcept override
// { return InterlockedIncrement(&m_refCount); }
// ULONG STDMETHODCALLTYPE Release() noexcept override
// { if (InterlockedDecrement(&m_refCount) == 0) { delete this; return 0; } return m_refCount; }

// HRESULT STDMETHODCALLTYPE QueryInterface(
// /* [in] */ REFIID riid,
// /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) noexcept override
// {
// if (riid == IID_IUnknown || riid == __uuidof(CoComProxyData))
// {
// *ppvObject = static_cast<CoComProxyData*>(this);
// AddRef();
// return S_OK;
// }
// *ppvObject = NULL;
// return E_NOINTERFACE;
// }

//private:
// long m_refCount;
};

struct CoComProxyData_factory : winrt::implements<CoComProxyData_factory, IClassFactory>
{
HRESULT __stdcall CreateInstance(
IUnknown* outer,
GUID const& iid,
void** result) noexcept final
{
*result = nullptr;

if (outer)
{
return CLASS_E_NOAGGREGATION;
}

return winrt::make<CoComProxyData>()->QueryInterface(iid, result);
}

HRESULT __stdcall LockServer(BOOL) noexcept final
{
return S_OK;
}
};


std::wstring get_module_path()
{
std::wstring path(100, L'?');
uint32_t path_size{};
DWORD actual_size{};

do
{
path_size = static_cast<uint32_t>(path.size());
actual_size = ::GetModuleFileName(nullptr, path.data(), path_size);

if (actual_size + 1 > path_size)
{
path.resize(path_size * 2, L'?');
}
} while (actual_size + 1 > path_size);

path.resize(actual_size);
return path;
}

struct registry_traits
{
using type = HKEY;

static void close(type value) noexcept
{
WINRT_VERIFY_(ERROR_SUCCESS, ::RegCloseKey(value));
}

static constexpr type invalid() noexcept
{
return nullptr;
}
};
using registry_key = winrt::handle_type<registry_traits>;
void UpdateRegistry(winrt::guid guid)
{
std::wstring key_path{ LR"(SOFTWARE\Classes\CLSID\{????????-????-????-????-????????????})" };
::StringFromGUID2(guid, key_path.data() + 23, 39);
key_path += LR"(\LocalServer32)";
registry_key key;

winrt::check_win32(::RegCreateKeyEx(
HKEY_CURRENT_USER,
key_path.c_str(),
0,
nullptr,
0,
KEY_WRITE,
nullptr,
key.put(),
nullptr));
::RegDeleteValue(key.get(), nullptr);

std::wstring path{ get_module_path() };

winrt::check_win32(::RegSetValueEx(
key.get(),
nullptr,
0,
REG_SZ,
reinterpret_cast<BYTE const*>(path.c_str()),
static_cast<uint32_t>((path.size() + 1) * sizeof(wchar_t))));
}

void Register()
{
DWORD registration{};

winrt::check_hresult(::CoRegisterClassObject(
::IpcApp::COM_PROXY_DATA_GUID,
winrt::make<::IpcApp::CoComProxyData_factory>().get(),
CLSCTX_LOCAL_SERVER,
REGCLS_SINGLEUSE,
&registration));
}
}
11 changes: 11 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/ComProxyData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "pch.h"

#include "ComProxyData.h"
#if __has_include("ComProxyData.g.cpp")
#include "ComProxyData.g.cpp"
#endif

namespace IpcApp
{

}
31 changes: 31 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/ComProxyData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "ComProxyData.g.h"

namespace winrt::IpcApp::implementation
{
struct ComProxyData : ComProxyDataT<ComProxyData>
{
ComProxyData() = default;

winrt::hstring Data()
{
return m_data;
}

void Data(winrt::hstring const& val)
{
m_data = val;
}

private:
winrt::hstring m_data{ L"initial_val" };
};
}

namespace winrt::IpcApp::factory_implementation
{
struct ComProxyData : ComProxyDataT<ComProxyData, implementation::ComProxyData>
{
};
}
10 changes: 10 additions & 0 deletions WinUi3_Ipc_comm/WinUi3_Ipc_comm/ComProxyData.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace IpcApp
{
[default_interface]
runtimeclass ComProxyData
{
ComProxyData();

String Data{ get; set; };
}
}
Loading