Thursday, July 12, 2018

New Job, New work - Marrying Win32 C DLL with a VB.NET WinForms, Now a WPF, Application

Working at a company in Boise, ID, and the work consist of presenting data from a device in such a way so that the application reading the data can make sense of it. Can you tell, mum's the word regarding what the device is because the device is being R&D'ed from the ground-up and the device hasn't been publicly announced. I thought implementing linear algebra, eigen values and vectors only applied to augmented and virtual reality applications. Well I was wrong.

Anyway, my first job, after figuring out how to convert a SVN repo to a Git repo and setting up an SSH public/private key authentication server, was to convert functionality in a Windows Win32 (BTW, Win32 now also refers to the 64bit platform) cpp executable source, which really was only a C programming language source, into a DLL and then call into the DLL with a VB.NET WinForms graphics application that currently didn't work. Wow, and I thought I'd never use, let alone learn, VB.NET. But really, to my surprise, VB.NET is not that bad. I'm using Windows 10 Pro and Visual Studio 2017 Pro. Both of which are stable and I'm please with.

Steps I took:
1) Convert the Win32 C++ project to a Win32 C programming language project and splitting the project into two pieces, one project as an executable, as a test driver of sorts, that calls into the other C Programming language DLL project.

2) Added build configurations to the now two project Win32 C solution to build and run release and debug, 32bit and 64bit binaries, and build using warning level 4. Build with no resulting warnings.

3) Updated the Win32 C DLL project to generate export libraries and created a header file to go with the library to expose the calls into the DLL. I can never remember how to do this step even though I've done it a million times before. Requires a lot from Google.

4) Fixed the threading in the VB.NET app (wow, kind of messed up). In the VB.NET application, started to use Windows Presentation Foundation (WPF) namespaces and updated the project to use the latest .NET framework. Modernizing the app a bit.

5) Expose the C programming language DLL to the VB.NET application and, from the VB.NET application, P/Invoke into the DLL. The difficult part was configuring Visual Studio 2017 to be able to debug the DLL from the running the VB.NET application in such a way to step into and add working breakpoints inside the DLL code.

Viola. An up-to-date VB.NET WinForms charting application that has dependencies on 64bit Win32 DLL written in C. The application that actually keeps pace with the UDP datagram spewing device using Telnet as a controller and for configuration. The demo was well received thanks to a little trick with the RGBA color alpha setting.

The next major step is to convert the VB.NET WinForms application to a C#.NET WPF application. I'm doing this to get the higher performance and capability graphics APIs. This will require me switch out the WinForms controls for XAML controls.

If anybody needs the details on any of the steps, let me know in a comment and I'll gladly add the details.