├── .gitignore ├── ComLoadRF.sln └── Server ├── Client.cpp ├── Dist ├── Server.exe ├── Server.exe.manifest ├── Server.exp └── Server.lib ├── Exports.def ├── Manifest.xml ├── Precompiled.cpp ├── Precompiled.h ├── Registration.cpp ├── Runtime.h ├── Server.cpp ├── Server.h ├── Server.vcxproj ├── Server.vcxproj.filters └── handle.h /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /ComLoadRF.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2035 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{944F8653-76B4-42F7-AC71-51EA778BD5C6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|Win32 = Debug|Win32 12 | Debug|x64 = Debug|x64 13 | Release|Any CPU = Release|Any CPU 14 | Release|Win32 = Release|Win32 15 | Release|x64 = Release|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|Any CPU.ActiveCfg = Debug|Win32 19 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|Win32.Build.0 = Debug|Win32 21 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|Win32.Deploy.0 = Debug|Win32 22 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|x64.ActiveCfg = Debug|x64 23 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Debug|x64.Build.0 = Debug|x64 24 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|Any CPU.ActiveCfg = Release|Win32 25 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|Win32.ActiveCfg = Release|Win32 26 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|Win32.Build.0 = Release|Win32 27 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|Win32.Deploy.0 = Release|Win32 28 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|x64.ActiveCfg = Release|Win32 29 | {944F8653-76B4-42F7-AC71-51EA778BD5C6}.Release|x64.Build.0 = Release|x64 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {0D0662DB-FB99-4747-A9BF-A202DA4E761D} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Server/Client.cpp: -------------------------------------------------------------------------------- 1 | #include "Precompiled.h" 2 | #include "Server.h" 3 | #include 4 | #include "Runtime.h" 5 | #include 6 | #include 7 | 8 | using namespace Microsoft::WRL; 9 | 10 | INT __stdcall WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, 11 | PSTR /*lpCmdLine*/, INT /*nCmdShow*/) 12 | { 13 | 14 | 15 | ComRuntime runtime; 16 | 17 | ComPtr armory; 18 | 19 | HR(CoGetClassObject(__uuidof(Det), 20 | CLSCTX_INPROC_SERVER, 21 | nullptr, 22 | __uuidof(armory), 23 | reinterpret_cast(armory.GetAddressOf()))); 24 | 25 | ComPtr det; 26 | 27 | HR(armory->CreateDet(det.GetAddressOf())); 28 | 29 | det->Detonate(); 30 | std::this_thread::sleep_for(std::chrono::seconds(30)); 31 | det->EndDetonate(); 32 | det->Release(); 33 | } -------------------------------------------------------------------------------- /Server/Dist/Server.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsnezhkov/HandsFreeCOM/8c7a5dc321d58c4665cb939c55ab7c0cae085d27/Server/Dist/Server.exe -------------------------------------------------------------------------------- /Server/Dist/Server.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /Server/Dist/Server.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsnezhkov/HandsFreeCOM/8c7a5dc321d58c4665cb939c55ab7c0cae085d27/Server/Dist/Server.exp -------------------------------------------------------------------------------- /Server/Dist/Server.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsnezhkov/HandsFreeCOM/8c7a5dc321d58c4665cb939c55ab7c0cae085d27/Server/Dist/Server.lib -------------------------------------------------------------------------------- /Server/Exports.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | DllGetClassObject PRIVATE 3 | DllRegisterServer PRIVATE 4 | DllUnregisterServer PRIVATE 5 | -------------------------------------------------------------------------------- /Server/Manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Server/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | #include "Precompiled.h" 2 | -------------------------------------------------------------------------------- /Server/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #define ASSERT ATLASSERT 8 | #define TRACE ATLTRACE 9 | 10 | -------------------------------------------------------------------------------- /Server/Registration.cpp: -------------------------------------------------------------------------------- 1 | #include "Precompiled.h" 2 | 3 | HRESULT __stdcall DllRegisterServer() 4 | { 5 | 6 | return S_OK; 7 | } 8 | 9 | HRESULT __stdcall DllUnregisterServer() 10 | { 11 | 12 | return S_OK; 13 | } 14 | -------------------------------------------------------------------------------- /Server/Runtime.h: -------------------------------------------------------------------------------- 1 | 2 | struct ComException 3 | { 4 | HRESULT result; 5 | 6 | explicit ComException(HRESULT const value) : result(value) {} 7 | }; 8 | 9 | inline void HR(HRESULT const result) 10 | { 11 | _ASSERTE(S_OK == result); 12 | if (S_OK != result) throw ComException(result); 13 | } 14 | 15 | struct ComRuntime 16 | { 17 | ComRuntime() 18 | { 19 | HR(CoInitializeEx(nullptr, 20 | COINIT_MULTITHREADED )); 21 | } 22 | ~ComRuntime() 23 | { 24 | CoUninitialize(); 25 | } 26 | }; -------------------------------------------------------------------------------- /Server/Server.cpp: -------------------------------------------------------------------------------- 1 | #include "Precompiled.h" 2 | #include "Server.h" 3 | #include 4 | 5 | 6 | #include 7 | 8 | using std::string; 9 | using namespace Microsoft::WRL; 10 | 11 | 12 | struct Det : IDet 13 | { 14 | long m_count; 15 | 16 | Det() : m_count(0) {} 17 | 18 | ULONG __stdcall AddRef() override 19 | { 20 | return _InterlockedIncrement(&m_count); 21 | } 22 | 23 | ULONG __stdcall Release() override 24 | { 25 | ULONG result = _InterlockedDecrement(&m_count); 26 | 27 | if (0 == result) 28 | { 29 | delete this; 30 | } 31 | 32 | return result; 33 | } 34 | 35 | HRESULT __stdcall QueryInterface(IID const & id, 36 | void ** result) override 37 | { 38 | ASSERT(result); 39 | 40 | if (id == __uuidof(IDet) || 41 | id == __uuidof(IUnknown)) 42 | { 43 | *result = static_cast(this); 44 | } 45 | else 46 | { 47 | *result = 0; 48 | return E_NOINTERFACE; 49 | } 50 | 51 | static_cast(*result)->AddRef(); 52 | return S_OK; 53 | } 54 | 55 | void __stdcall Detonate() override 56 | { 57 | // return; 58 | // Open a handle to the file 59 | HANDLE hFile = CreateFile( 60 | L"Flag.txt", // Filename 61 | GENERIC_WRITE, // Desired access 62 | FILE_SHARE_READ, // Share mode 63 | NULL, // Security attributes 64 | CREATE_NEW, // Creates a new file, only if it doesn't already exist 65 | FILE_ATTRIBUTE_NORMAL, // Flags and attributes 66 | NULL); // Template file handle 67 | 68 | 69 | // Write data to the file 70 | std::string strText = "Hello World!"; // For C use LPSTR (char*) or LPWSTR (wchar_t*) 71 | DWORD bytesWritten; 72 | WriteFile( 73 | hFile, // Handle to the file 74 | strText.c_str(), // Buffer to write 75 | strText.size(), // Buffer size 76 | &bytesWritten, // Bytes written 77 | nullptr); // Overlapped 78 | 79 | // Close the handle once we don't need it. 80 | CloseHandle(hFile); 81 | } 82 | 83 | void __stdcall EndDetonate() override { 84 | 85 | TRACE("Deleting File."); 86 | DeleteFile(L"Flag.txt"); 87 | } 88 | }; 89 | 90 | 91 | struct Armory : IDetFactory 92 | { 93 | ULONG __stdcall AddRef() override 94 | { 95 | return 2; 96 | } 97 | 98 | ULONG __stdcall Release() override 99 | { 100 | return 1; 101 | } 102 | 103 | HRESULT __stdcall QueryInterface(IID const & id, 104 | void ** result) override 105 | { 106 | ASSERT(result); 107 | 108 | if (id == __uuidof(IDetFactory) || 109 | id == __uuidof(IUnknown)) 110 | { 111 | *result = static_cast(this); 112 | } 113 | else 114 | { 115 | *result = 0; 116 | return E_NOINTERFACE; 117 | } 118 | 119 | return S_OK; 120 | } 121 | 122 | HRESULT __stdcall CreateDet(IDet ** result) override 123 | { 124 | ASSERT(result); 125 | 126 | *result = new (std::nothrow) Det; 127 | 128 | if (0 == *result) 129 | { 130 | return E_OUTOFMEMORY; 131 | } 132 | 133 | (*result)->AddRef(); 134 | return S_OK; 135 | } 136 | }; 137 | 138 | HRESULT __stdcall DllGetClassObject(CLSID const & clsid, 139 | IID const & iid, 140 | void ** result) 141 | { 142 | ASSERT(result); 143 | *result = nullptr; 144 | 145 | if (__uuidof(Det) == clsid) 146 | { 147 | static Armory armory; 148 | 149 | return armory.QueryInterface(iid, result); 150 | } 151 | 152 | return CLASS_E_CLASSNOTAVAILABLE; 153 | } 154 | 155 | 156 | -------------------------------------------------------------------------------- /Server/Server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct __declspec(uuid("5d8a7d33-059f-418a-8d77-5f3944d63b6d")) Det; 6 | 7 | struct __declspec(uuid("5a196c0f-e296-4b35-9249-f3d7ad5999fd")) IDet : IUnknown 8 | { 9 | virtual void __stdcall Detonate() = 0; 10 | virtual void __stdcall EndDetonate() = 0; 11 | }; 12 | 13 | 14 | 15 | 16 | struct __declspec(uuid("9362f817-85b6-4a80-81de-772c792922ff")) IDetFactory : IUnknown 17 | { 18 | virtual HRESULT __stdcall CreateDet(IDet ** hen) = 0; 19 | }; 20 | -------------------------------------------------------------------------------- /Server/Server.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {944F8653-76B4-42F7-AC71-51EA778BD5C6} 23 | Win32Proj 24 | Server 25 | 10.0.17134.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | Unicode 33 | 34 | 35 | Application 36 | true 37 | v141 38 | Unicode 39 | 40 | 41 | Application 42 | false 43 | v141 44 | true 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v141 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | false 73 | C:\Users\dimas\Desktop\3-com-advanced-topics-m3-exercise-files\5 Registration Free Activation\Server\Dist;$(ExecutablePath) 74 | .\Dist\ 75 | 76 | 77 | true 78 | false 79 | C:\Users\dimas\Desktop\3-com-advanced-topics-m3-exercise-files\5 Registration Free Activation\Server\Dist;$(ExecutablePath) 80 | C:\Users\dimas\Desktop\3-com-advanced-topics-m3-exercise-files\5 Registration Free Activation\Server\Dist\ 81 | 82 | 83 | false 84 | false 85 | 86 | 87 | false 88 | false 89 | 90 | 91 | 92 | Use 93 | Level4 94 | Disabled 95 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SERVER_EXPORTS;%(PreprocessorDefinitions) 96 | true 97 | Precompiled.h 98 | 99 | 100 | Windows 101 | true 102 | Exports.def 103 | 104 | 105 | Manifest.xml 106 | 107 | 108 | mt -manifest Manifest.xml -outputresource:"$(TargetPath)";#1 -nologo 109 | 110 | 111 | 112 | 113 | Use 114 | Level4 115 | Disabled 116 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SERVER_EXPORTS;%(PreprocessorDefinitions) 117 | true 118 | Precompiled.h 119 | 120 | 121 | 122 | 123 | Windows 124 | true 125 | Exports.def 126 | 127 | 128 | Manifest.xml 129 | 130 | 131 | mt -manifest Manifest.xml -outputresource:"$(TargetPath)";#1 -nologo 132 | 133 | 134 | 135 | 136 | Level4 137 | Use 138 | MaxSpeed 139 | true 140 | true 141 | WIN32;NDEBUG;_WINDOWS;_USRDLL;SERVER_EXPORTS;%(PreprocessorDefinitions) 142 | true 143 | Precompiled.h 144 | 145 | 146 | Windows 147 | true 148 | true 149 | true 150 | Exports.def 151 | 152 | 153 | Manifest.xml 154 | 155 | 156 | mt -manifest Manifest.xml -outputresource:"$(TargetPath)";1 -nologo 157 | 158 | 159 | 160 | 161 | Level4 162 | Use 163 | MaxSpeed 164 | true 165 | true 166 | WIN32;NDEBUG;_WINDOWS;_USRDLL;SERVER_EXPORTS;%(PreprocessorDefinitions) 167 | true 168 | Precompiled.h 169 | 170 | 171 | Windows 172 | true 173 | true 174 | true 175 | Exports.def 176 | 177 | 178 | Manifest.xml 179 | 180 | 181 | mt -manifest Manifest.xml -outputresource:"$(TargetPath)";1 -nologo 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | Create 193 | Create 194 | Create 195 | Create 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /Server/Server.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Server/handle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define HANDLE_ASSERT _ASSERTE 7 | 8 | #ifdef _DEBUG 9 | #define HANDLE_VERIFY(expression) HANDLE_ASSERT(expression) 10 | #define HANDLE_VERIFY_(expected, expression) HANDLE_ASSERT(expected == expression) 11 | #else 12 | #define HANDLE_VERIFY(expression) (expression) 13 | #define HANDLE_VERIFY_(expected, expression) (expression) 14 | #endif 15 | 16 | namespace KennyKerr 17 | { 18 | template 19 | class unique_handle 20 | { 21 | struct boolean_struct { int member; }; 22 | typedef int boolean_struct::* boolean_type; 23 | typedef typename Traits::pointer pointer; 24 | 25 | unique_handle(unique_handle const &); 26 | unique_handle & operator=(unique_handle const &); 27 | bool operator==(unique_handle const &); 28 | bool operator!=(unique_handle const &); 29 | 30 | void close() throw() 31 | { 32 | if (*this) 33 | { 34 | Traits::close(m_value); 35 | } 36 | } 37 | 38 | pointer m_value; 39 | 40 | public: 41 | 42 | explicit unique_handle(pointer value = Traits::invalid()) throw() : 43 | m_value(value) 44 | { 45 | } 46 | 47 | ~unique_handle() throw() 48 | { 49 | close(); 50 | } 51 | 52 | unique_handle(unique_handle && other) throw() : 53 | m_value(other.release()) 54 | { 55 | } 56 | 57 | unique_handle & operator=(unique_handle && other) throw() 58 | { 59 | HANDLE_ASSERT(this != &other); 60 | 61 | reset(other.release()); 62 | return *this; 63 | } 64 | 65 | operator boolean_type() const throw() 66 | { 67 | return Traits::invalid() != m_value ? &boolean_struct::member : nullptr; 68 | } 69 | 70 | pointer get() const throw() 71 | { 72 | return m_value; 73 | } 74 | 75 | bool reset(pointer value = Traits::invalid()) throw() 76 | { 77 | if (m_value != value) 78 | { 79 | close(); 80 | m_value = value; 81 | } 82 | 83 | return *this; 84 | } 85 | 86 | pointer release() throw() 87 | { 88 | auto value = m_value; 89 | m_value = Traits::invalid(); 90 | return value; 91 | } 92 | }; 93 | 94 | struct null_handle_traits 95 | { 96 | typedef HANDLE pointer; 97 | 98 | static pointer invalid() throw() 99 | { 100 | return nullptr; 101 | } 102 | 103 | static void close(pointer value) throw() 104 | { 105 | HANDLE_VERIFY(CloseHandle(value)); 106 | } 107 | }; 108 | 109 | struct invalid_handle_traits 110 | { 111 | typedef HANDLE pointer; 112 | 113 | static pointer invalid() throw() 114 | { 115 | return INVALID_HANDLE_VALUE; 116 | } 117 | 118 | static void close(pointer value) throw() 119 | { 120 | HANDLE_VERIFY(CloseHandle(value)); 121 | } 122 | }; 123 | 124 | typedef unique_handle null_handle; 125 | typedef unique_handle invalid_handle; 126 | 127 | static_assert(sizeof(HANDLE) == sizeof(null_handle), "The handle wrapper should not impose any space overhead"); 128 | } 129 | --------------------------------------------------------------------------------