Skip to content

Commit

Permalink
PR nits
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Dec 14, 2020
1 parent 5dbf042 commit 3351e01
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion consolegit2gitfilters.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"/doc/specs/",
"/doc/cascadia/",
"/doc/user-docs/",
"/src/tools/MonarchPeasantSample",
"/src/tools/MonarchPeasantSample/",
],
"SuffixFilters": [
".dbb",
Expand Down
3 changes: 1 addition & 2 deletions src/tools/MonarchPeasantSample/AppState.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "pch.h"
#include <conio.h>
#include "Monarch.h"
#include "Peasant.h"
#include "AppState.h"
Expand Down Expand Up @@ -59,7 +58,7 @@ void AppState::remindKingWhoTheyAre(const winrt::MonarchPeasantSample::IPeasant&
}
else
{
// printf("Shoot, we wanted to be able to get the impl here but couldnt\n");
printf("Shoot, we wanted to be able to get the monarchImpl here but couldnt\n");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/MonarchPeasantSample/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace winrt::MonarchPeasantSample::implementation
}
else
{
// printf("They definitely weren't an existing process. They should make a new window.\n");
printf("They definitely weren't an existing process. They should make a new window.\n");
}

return createNewWindow;
Expand Down
8 changes: 0 additions & 8 deletions src/tools/MonarchPeasantSample/Peasant.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
#include "Peasant.g.h"
#include "../cascadia/inc/cppwinrt_utils.h"

// {50dba6cd-1111-4b12-8363-5e06f5d0082c}
constexpr GUID Peasant_clsid{
0x50dba6cd,
0x1111,
0x4b12,
{ 0x83, 0x63, 0x5e, 0x06, 0xf5, 0xd0, 0x08, 0x2c }
};

namespace winrt::MonarchPeasantSample::implementation
{
struct Peasant : public PeasantT<Peasant>
Expand Down
16 changes: 11 additions & 5 deletions src/tools/MonarchPeasantSample/PeasantMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
bool peasantReadInput(AppState& state)
{
DWORD cNumRead, i;
INPUT_RECORD irInBuf[128];
std::array<INPUT_RECORD, 128> irInBuf;

if (!ReadConsoleInput(state.hInput, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
irInBuf.data(), // buffer to read into
static_cast<DWORD>(irInBuf.size()), // size of read buffer
&cNumRead)) // number of records read
{
printf("\x1b[31mReadConsoleInput failed\x1b[m\n");
Expand Down Expand Up @@ -59,10 +59,17 @@ bool peasantReadInput(AppState& state)
return false;
}

// Returns true if we want to just exit the application.
// Returns false if the monarch dies, and we need to elect a new one.
bool peasantAppLoop(AppState& state)
{
wil::unique_handle hMonarch{ OpenProcess(PROCESS_ALL_ACCESS, FALSE, static_cast<DWORD>(state.monarch.GetPID())) };
// printf("handle for the monarch process is %d\n", hMonarch.get());
if (hMonarch.get() == nullptr)
{
const auto gle = GetLastError();
printf("\x1b[31mFailed to open the monarch process, error was %d\x1b[m\n", gle);
return false;
}

HANDLE handlesToWaitOn[2]{ hMonarch.get(), state.hInput };

Expand All @@ -71,7 +78,6 @@ bool peasantAppLoop(AppState& state)

while (!exitRequested)
{
// printf("Beginning wait...\n");
auto waitResult = WaitForMultipleObjects(2, handlesToWaitOn, false, INFINITE);

switch (waitResult)
Expand Down
6 changes: 1 addition & 5 deletions src/tools/MonarchPeasantSample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ winrt::weak_ref<MonarchPeasantSample::implementation::Monarch> g_weak{ nullptr }

struct MonarchFactory : implements<MonarchFactory, IClassFactory>
{
MonarchFactory() :
_guid{ Monarch_clsid } {};
MonarchFactory() = default;

HRESULT __stdcall CreateInstance(IUnknown* outer, GUID const& iid, void** result) noexcept final
{
Expand Down Expand Up @@ -55,9 +54,6 @@ struct MonarchFactory : implements<MonarchFactory, IClassFactory>
{
return S_OK;
}

private:
winrt::guid _guid;
};
////////////////////////////////////////////////////////////////////////////////

Expand Down
6 changes: 2 additions & 4 deletions src/tools/MonarchPeasantSample/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>

#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <windows.ui.xaml.media.dxinterop.h>

// Manually include til after we include Windows.Foundation to give it winrt superpowers
#include "til.h"

#include <conio.h>

0 comments on commit 3351e01

Please sign in to comment.