Latest blog posts in category "Programming"

The programming section covers a wide range of topics related to coding and software development.

LegacyWrapper 2.1 is out!

20.08.2017 | Programming | .NET C# Legacy Wrapper

Today, I released version 2.1 of my NuGet package LegacyWrapper. It comes with a major enhancement regarding the cross-architecture loading of DLLs: It is now possible to load 64bit DLLs from a 32bit process:

1using (var client = new WrapperClient(TestDllPath, TargetArchitecture.Amd64))
2{
3    result = (int)client.Invoke<TestStdCallDelegate>("TestStdCall", new object[] { input });
4}

As the second constructor parameter is optional and defaults to X86, the new release should be fully backwards compatible.

Read this post in about 1 minute

Improving page speed with a framework change

20.07.2017 | Programming | Framework Bootstrap Pagespeed

When I migrated my website to Jekyll a few months ago, I used a free template for my layout. Although it looked quite good, it came with a major tradeoff. It used Skel, a JavaScript framework for responsive websites. Skel loads arbitrary CSS stylesheets with JavaScript, based on the user’s screen resolution. This may sound convenient, but the page will load visibly slower, because the stylesheets will only load after all the JavaScript is loaded and executed. See an example of Skel in action in the following listing:

 1skel.init({
 2    reset: 'full',
 3    breakpoints: {
 4        global:   { range: '*', href: '/css/style.css', containers: 1400, grid: { gutters: 50 } },
 5        wide:     { range: '-1680', href: '/css/style-wide.css', containers: 1200, grid: { gutters: 40 } },
 6        normal:   { range: '-1280', href: '/css/style-normal.css', containers: 960, viewport: { scalable: false } },
 7        narrow:   { range: '-980', href: '/css/style-narrow.css', containers: '95%', grid: { gutters: 30 } },
 8        narrower: { range: '-840', href: '/css/style-narrower.css', grid: { collapse: 1 } },
 9        mobile:   { range: '-736', href: '/css/style-mobile.css', containers: '100%', grid: { gutters: 15, collapse: 2 } }
10    },
11    // ...
12});

Read this post in about 2 minutes

Invoking an unmanaged 32bit library out of a 64bit process

28.09.2015 | Programming | .NET C# Legacy Wrapper

When loading unmanaged / native libraries from managed .NET code, the normal way is to use the “Platform Invoke (P/Invoke)” mechanism.

1[DllImport("shell32.dll", CallingConvention = CallingConvention.Winapi)]
2static extern int DllGetVersion(ref DLLVERSIONINFO pdvi);

The problem

P/Invoke has an annoying limitation: You can not load an x86 (32bit) library into a 64bit process and vice versa. This is especially problematic when your application is compiled with the “AnyCPU”-flag - which lets the .NET runtime decide which architecture to use at runtime - and there is only one 32bit version of a specific DLL. If recompiling the library against a different architecture is not an option, you have to find another solution.

Read this post in about 3 minutes