Skip to content

Commit 62f5f7e

Browse files
committed
Convert from WinExe to Library
1 parent 972b62e commit 62f5f7e

File tree

9 files changed

+187
-641
lines changed

9 files changed

+187
-641
lines changed

MessageToImage.sln

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,24 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Direct2DWrapper", "Direct2D
1212
EndProject
1313
Global
1414
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15-
Debug|Any CPU = Debug|Any CPU
1615
Debug|x64 = Debug|x64
1716
Debug|x86 = Debug|x86
18-
Release|Any CPU = Release|Any CPU
1917
Release|x64 = Release|x64
2018
Release|x86 = Release|x86
2119
EndGlobalSection
2220
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x64.ActiveCfg = Debug|Any CPU
26-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x64.Build.0 = Debug|Any CPU
27-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x86.ActiveCfg = Debug|Any CPU
28-
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x86.Build.0 = Debug|Any CPU
29-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|Any CPU.ActiveCfg = Release|Any CPU
30-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|Any CPU.Build.0 = Release|Any CPU
31-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x64.ActiveCfg = Release|Any CPU
32-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x64.Build.0 = Release|Any CPU
33-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x86.ActiveCfg = Release|Any CPU
34-
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x86.Build.0 = Release|Any CPU
35-
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Debug|Any CPU.ActiveCfg = Debug|Win32
21+
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x64.ActiveCfg = Debug|x64
22+
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x64.Build.0 = Debug|x64
23+
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x86.ActiveCfg = Debug|x86
24+
{57453944-E799-45CC-8C8B-1AA277955736}.Debug|x86.Build.0 = Debug|x86
25+
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x64.ActiveCfg = Release|x64
26+
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x64.Build.0 = Release|x64
27+
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x86.ActiveCfg = Release|x86
28+
{57453944-E799-45CC-8C8B-1AA277955736}.Release|x86.Build.0 = Release|x86
3629
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Debug|x64.ActiveCfg = Debug|x64
3730
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Debug|x64.Build.0 = Debug|x64
3831
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Debug|x86.ActiveCfg = Debug|Win32
3932
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Debug|x86.Build.0 = Debug|Win32
40-
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Release|Any CPU.ActiveCfg = Release|Win32
4133
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Release|x64.ActiveCfg = Release|x64
4234
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Release|x64.Build.0 = Release|x64
4335
{A5887581-E13D-4FC6-966D-00AD9AC05647}.Release|x86.ActiveCfg = Release|Win32

MessageToImage/App.xaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

MessageToImage/App.xaml.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

MessageToImage/Direct2DWrapper.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
7+
namespace uk.JohnCook.dotnet.MessageToImage
8+
{
9+
public class Direct2DWrapper : IDisposable
10+
{
11+
/// <summary>
12+
/// Instances of ID2D1Factory, IDWriteFactory, and IWICImagingFactory should be reused for the life of an application
13+
/// </summary>
14+
private Interop.Direct2DPointers direct2DPointers = new Interop.Direct2DPointers();
15+
private bool disposedValue;
16+
17+
/// <summary>
18+
/// Constructor
19+
/// </summary>
20+
public Direct2DWrapper()
21+
{
22+
CreateDirect2DPointers();
23+
24+
// Original DLL existence test - README needs modifying if changed
25+
Trace.WriteLine(Interop.UnsafeNativeMethods.Add(3, 6));
26+
}
27+
28+
/// <summary>
29+
/// Create pointers for ID2D1Factory, IDWriteFactory, and IWICImagingFactory
30+
/// </summary>
31+
private void CreateDirect2DPointers()
32+
{
33+
try
34+
{
35+
Marshal.ThrowExceptionForHR(Interop.UnsafeNativeMethods.CreateD2D1Factory(ref direct2DPointers));
36+
Marshal.ThrowExceptionForHR(Interop.UnsafeNativeMethods.CreateDWriteFactory(ref direct2DPointers));
37+
Marshal.ThrowExceptionForHR(Interop.UnsafeNativeMethods.CreateImagingFactory(ref direct2DPointers));
38+
}
39+
catch (COMException ce)
40+
{
41+
Interop.UnsafeNativeMethods.ReleaseDWriteFactory(direct2DPointers);
42+
Interop.UnsafeNativeMethods.ReleaseImagingFactory(direct2DPointers);
43+
Interop.UnsafeNativeMethods.ReleaseD2D1Factory(direct2DPointers);
44+
Trace.WriteLine($"COMException in {nameof(CreateDirect2DPointers)} - {ce.Message} - {ce.InnerException?.Message}");
45+
throw;
46+
}
47+
}
48+
49+
/// <summary>
50+
/// Create a MessagePanel instance
51+
/// </summary>
52+
/// <param name="canvasSize">Size of the canvas</param>
53+
/// <param name="backgroundColor">Background color of the canvas</param>
54+
/// <returns></returns>
55+
public MessagePanel CreateMessagePanel(Interop.SizeU canvasSize, UInt32 backgroundColor)
56+
{
57+
return new MessagePanel(
58+
direct2DPointers: ref direct2DPointers,
59+
canvasSize: canvasSize,
60+
backgroundColor: backgroundColor
61+
);
62+
}
63+
64+
protected virtual void Dispose(bool disposing)
65+
{
66+
if (!disposedValue)
67+
{
68+
if (disposing)
69+
{
70+
// TODO: dispose managed state (managed objects)
71+
}
72+
73+
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
74+
Interop.UnsafeNativeMethods.ReleaseDWriteFactory(direct2DPointers);
75+
Interop.UnsafeNativeMethods.ReleaseImagingFactory(direct2DPointers);
76+
Interop.UnsafeNativeMethods.ReleaseD2D1Factory(direct2DPointers);
77+
// TODO: set large fields to null
78+
disposedValue = true;
79+
}
80+
}
81+
82+
// TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
83+
~Direct2DWrapper()
84+
{
85+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
86+
Dispose(disposing: false);
87+
}
88+
89+
public void Dispose()
90+
{
91+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
92+
Dispose(disposing: true);
93+
GC.SuppressFinalize(this);
94+
}
95+
}
96+
}

MessageToImage/MainWindow.xaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)