csharp-message-to-image-library is a test/sample C# solution with an ordinary (non-MFC) C++ DLL project.
The purpose of this solution is to work out how to create a C++ DLL and utilise it in C#.
This repository is an off-shoot of csharp-stream-controller
This project is a non-MFC C++ DLL project.
It exports a limited number of functions that are abstractions of some Direct2D and DirectWrite functions.
This is the main C# WPF .NET Core 3.1 project.
It is (now) a C# wrapper around Direct2DWrapper providing a limited set of features so that a message (such as a Tweet) can be transformed into a PNG file.
In order to use the library, the Direct2DWrapper project will need building to generate Direct2DWrapper.dll and a link file created in MessageToImageLibrary\lib pointing at the Direct2DWrapper.dll file.
The C# project needs to be able to find Direct2DWrapper.dll.
- In Visual Studio 2019, choose Debug or Release for Solution Configurations and x64 or x86 for Solution Platforms.
- Right-click the Direct2DWrapper project and click Build.
- Right-click the lib folder in the MessageToImageLibrary project.
- In the context menu: Add, Existing Item…
- Change the file types drop down to Executable Files (or all files, you're looking for a .dll)
- Browse to the root directory for the solution - if you're in the directory csharp-message-to-image-library\MessageToImageLibrary, you need to go up a directory.
- Find the DLL you built in step 1. If you chose Debug and x64, it will likely be in x64\Debug. Select the Direct2DWrapper.dll file.
- Click the arrow next to the Add button, and click Add as Link.
- Right-click the link file lib\Direct2DWrapper.dll and click Properties.
- Change Copy to Output Directory to Copy if newer.
- Run the MessageToImageLibrary project. If something is still wrong, you'll get a DllNotFoundException.
MessageToImageLibrary exports a generic Add(int a, double b)
function found in Direct2DWrapper.
If the projects are built correctly, the Visual Studio debug Output window should include the following output on instantiation of a C# MessageToImageLibrary.Direct2DWrapper
instance:
Result of external Add(10, 3) = 13.
class Test()
{
private readonly MessageToImageLibrary.Direct2DWrapper d2dWrapper;
Test()
{
Trace.WriteLine("Testing DLL...");
d2dWrapper = new MessageToImageLibrary.Direct2DWrapper();
}
}
The expected output listed above may be out of date as documentation changes typically lag code changes. Check recent commits for changes.