Close

Hooking into the Windows message queue in UE4

I recently came across several community projects that try to process Windows messages by hacking the Engine’s message loop, but there is a better way. Earlier this year I added the IWindowsMessageHandler API, which does not require any Engine code changes and keeps your plug-in completely self-contained.

Some third-party hardware and software SDKs for Windows communicate with the host application via Windows messages. When trying to integrate such SDKs into Unreal Engine 4 plug-ins, access to the Windows message queue is required. There are many examples on the internet that show how to use the message queue, and it is often tempting to shoehorn such code into the Windows platform layer in UE4. However, this makes the plug-in less modular and more dependent on future Engine changes, and excludes a potentially large number of users, because not everyone is able or willing to merge Engine code changes. It also prevents the plug-in from making it into the Unreal Engine Marketplace.

Luckily, there is an Engine API that allows any plug-in to intercept and process Windows messages without requiring such modifications. This article explains how to use it and provides working sample code on Github.

Read More