Skip to content

Commit

Permalink
Fix vtable problem for 0xa0000 ndr version by specifying NT target ve…
Browse files Browse the repository at this point in the history
…rsion explicitly.
  • Loading branch information
miniksa committed Sep 10, 2020
1 parent dceadd8 commit 7f54db2
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/common.build.pre.props
Expand Up @@ -70,6 +70,9 @@
</PropertyGroup>

<ItemDefinitionGroup>
<Midl>
<AdditionalOptions>/target NT100 %(AdditionalOptions)</AdditionalOptions>
</Midl>
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
Expand Down
2 changes: 1 addition & 1 deletion src/host/dll/Host.DLL.vcxproj
Expand Up @@ -50,4 +50,4 @@
</ItemDefinitionGroup>
<!-- Careful reordering these. Some default props (contained in these files) are order sensitive. -->
<Import Project="$(SolutionDir)src\common.build.post.props" />
</Project>
</Project>
46 changes: 23 additions & 23 deletions src/host/exe/CConsoleHandoff.cpp
Expand Up @@ -16,29 +16,29 @@ void _releaseNotifier() noexcept

DWORD g_cTerminalHandoffRegistration = 0;

template<int RegClsType>
class DefaultOutOfProcModuleWithRegistrationFlag;

template<int RegClsType, typename ModuleT = DefaultOutOfProcModuleWithRegistrationFlag<RegClsType>>
class OutOfProcModuleWithRegistrationFlag : public Microsoft::WRL::Module<Microsoft::WRL::ModuleType::OutOfProc, ModuleT>
{
public:
STDMETHOD(RegisterCOMObject)
(_In_opt_z_ const wchar_t* serverName, _In_reads_(count) IID* clsids, _In_reads_(count) IClassFactory** factories, _Inout_updates_(count) DWORD* cookies, unsigned int count)
{
return Microsoft::WRL::Details::RegisterCOMObject<RegClsType>(serverName, clsids, factories, cookies, count);
}
};

template<int RegClsType>
class DefaultOutOfProcModuleWithRegistrationFlag : public OutOfProcModuleWithRegistrationFlag<RegClsType, DefaultOutOfProcModuleWithRegistrationFlag<RegClsType>>
{
};

int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
{
OutOfProcModuleWithRegistrationFlag<REGCLS_SINGLEUSE>::Create();
}
//template<int RegClsType>
//class DefaultOutOfProcModuleWithRegistrationFlag;
//
//template<int RegClsType, typename ModuleT = DefaultOutOfProcModuleWithRegistrationFlag<RegClsType>>
//class OutOfProcModuleWithRegistrationFlag : public Microsoft::WRL::Module<Microsoft::WRL::ModuleType::OutOfProc, ModuleT>
//{
//public:
// STDMETHOD(RegisterCOMObject)
// (_In_opt_z_ const wchar_t* serverName, _In_reads_(count) IID* clsids, _In_reads_(count) IClassFactory** factories, _Inout_updates_(count) DWORD* cookies, unsigned int count)
// {
// return Microsoft::WRL::Details::RegisterCOMObject<RegClsType>(serverName, clsids, factories, cookies, count);
// }
//};
//
//template<int RegClsType>
//class DefaultOutOfProcModuleWithRegistrationFlag : public OutOfProcModuleWithRegistrationFlag<RegClsType, DefaultOutOfProcModuleWithRegistrationFlag<RegClsType>>
//{
//};
//
//int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
//{
// OutOfProcModuleWithRegistrationFlag<REGCLS_SINGLEUSE>::Create();
//}

// Routine Description:
// - Performs registrations for our COM types and waits until COM tells us we're done being a server.
Expand Down
59 changes: 59 additions & 0 deletions src/host/srvinit.cpp
Expand Up @@ -26,6 +26,12 @@

#include "..\host\dll\ITerminalHandoff_h.h"

#include <wil/resource.h>
#include <wil/winrt.h>
#include <windows.foundation.collections.h>
#include <Windows.ApplicationModel.h>
#include <Windows.ApplicationModel.AppExtensions.h>

#pragma hdrstop

using namespace Microsoft::Console::Interactivity;
Expand All @@ -34,6 +40,57 @@ using namespace Microsoft::Console::Render;
const UINT CONSOLE_EVENT_FAILURE_ID = 21790;
const UINT CONSOLE_LPC_PORT_FAILURE_ID = 21791;

using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::ApplicationModel;
using namespace ABI::Windows::ApplicationModel::AppExtensions;

HRESULT LookupCatalog()
{
auto coinit = wil::CoInitializeEx(COINIT_MULTITHREADED);

ComPtr<IAppExtensionCatalogStatics> catalogStatics;
RETURN_IF_FAILED(Windows::Foundation::GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_AppExtensions_AppExtensionCatalog).Get(), &catalogStatics));

ComPtr<IAppExtensionCatalog> catalog;
RETURN_IF_FAILED(catalogStatics->Open(HStringReference(L"com.microsoft.windows.console.host").Get(), &catalog));

ComPtr<IAsyncOperation<IVectorView<AppExtension*>*>> findOperation;
RETURN_IF_FAILED(catalog->FindAllAsync(&findOperation));

ComPtr<IVectorView<AppExtension*>> extensionList;
RETURN_IF_FAILED(wil::wait_for_completion_nothrow(findOperation.Get(), &extensionList));

UINT extensionCount;
RETURN_IF_FAILED(extensionList->get_Size(&extensionCount));
for (UINT index = 0; index < extensionCount; index++)
{
ComPtr<IAppExtension> extension;
RETURN_IF_FAILED(extensionList->GetAt(index, &extension));

ComPtr<IPackage> extensionPackage;
RETURN_IF_FAILED(extension->get_Package(&extensionPackage));

ComPtr<IPackageId> extensionPackageId;
RETURN_IF_FAILED(extensionPackage->get_Id(&extensionPackageId));

HString publisherId;
RETURN_IF_FAILED(extensionPackageId->get_PublisherId(publisherId.GetAddressOf()));

// PackageId.Name
HString name;
RETURN_IF_FAILED(extensionPackageId->get_Name(name.GetAddressOf()));

// PackageId.Version
PackageVersion version;
RETURN_IF_FAILED(extensionPackageId->get_Version(&version));
}

return S_OK;
}

[[nodiscard]] HRESULT ConsoleServerInitialization(_In_ HANDLE Server, const ConsoleArguments* const args)
try
{
Expand All @@ -50,6 +107,8 @@ try

FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

//LookupCatalog();

// TODO: This is looked up twice in the middle hop console.
IID delegationClsid;
if (SUCCEEDED(DelegationConfig::s_GetConsole(delegationClsid)))
Expand Down

1 comment on commit 7f54db2

@github-actions

This comment was marked as outdated.

Please sign in to comment.