Haxe: Giving Neko VM executables a custom icon

This is a little post about how to give your Haxe-Neko (or just Neko VM) executables (made using nekotools boot) a custom icon on Windows.

The problem

If you have already tried replacing your icon in the resulting executable using Resource Hacker or other software, you might have noticed that this does not work - the application crashes with std@module_read.

Apparently this is due to how nekotools boot works, and can be fixed by patching the neko executable that it is going to use.

The solution

The solution is to make a new neko.exe with a custom icon in a separate directory, change the working directory to that, and run nekotools - since the tool prefers working directory over the program directory we don't have to copy nekotools itself into that directory.

So, you could have nekotools_boot_with_icon.bat in Neko directory with the following inside:

@echo off
:: create temp directory if it doesn't exist yet:
if not exist "%~dp0_ntbt" (
	mkdir "%~dp0_ntbt"
) else (
	del /Q "%~dp0_ntbt\neko.exe"
)

:: run ResourceHacker to make a version of neko.exe with a new icon in temp directory:
"C:\Wherever\ResourceHacker.exe" -open "%~dp0neko.exe" -save "%~dp0_ntbt\neko.exe" -action add -res "%~2" -mask ICONGROUP,MAINICON,
if not exist "%~dp0_ntbt\neko.exe" (
	echo "ResourceHacker failed!"
	exit /B 1
)

:: run nekotools from the temp directory:
:: (this works because nekotools looks for neko.exe in cwd first)
set _ntbt_cd=%cd%
cd "%~dp0_ntbt"
nekotools boot %1
cd %_ntbt_cd%

(note: replace ResourceHacker path with your own)

and then do

nekotools_boot_with_icon app.n icon.ico

to pack up app.n into app.exe and attach icon.ico to it.


That's all.

Related posts:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.