This is mostly for my own benefit so I have a model to follow when creating Hashlink extensions because I will forget how. See the references section below for the resources I referred to in doing this.
- First create a project directory which will contain
- the C++ extension,
- its Haxe wrapper module
- the test code - in this code that is just a Main.hx to demo a simple function
- Open up Visual Studio (the big one not VSCode)
For reference I am using Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.4
- Create a new project
- File -> New Project...
- Select the Empty Project template and click Next
- Project Name: The name of the extension - here
hlextLib
- Location: the project directory you created in the very first step above
- Solution: Create new solution
- Leave solution name blank
- Check "Place solution and project in the same directory"
- Hit Create
- In the Solution Explorer you should see the project (the VS project that is) directory.
- Right click on that and select Properties at the bottom of the context menu
- Make sure the Configuration Platform: is Active(x64).
- Under Configuration Properties
- Select the General tab, and
- Make the Configuration Type
Dynamic Library (.dll)
- Make the Configuration Type
- Select the VC++ Directories tab, and
- Add to Include Directories your Hashlink include directory. For example
D:\Program Files\HashLink1.14\include
- Add to Library Directories your hashlink directory. For example
D:\Program Files\HashLink1.14
- Add to Include Directories your Hashlink include directory. For example
- Select the Build Events tab, and
- Add a Post-Build Event
- Command Line
copy $(TargetDir)$(TargetFileName) $(TargetDir)$(TargetName).hdll
- This will make the dll and hdll which is what HL will load.
- Command Line
- Add a Post-Build Event
- Select the General tab, and
- Under Linker
3. Select the Input tab, and
4. Add
libhl.lib
to Additional Dependencies
- Right click on that and select Properties at the bottom of the context menu
- In the Solution Explorer right click on the Source Files directory
- New Item...
- C++ File
- and name is whatever you like, here
hlext.cpp
- Follow reference [1] in creating the code you need.
- And then build the solution
- if all goes well you will have an hdll undex
\x64\Debug
in your VS project
- if all goes well you will have an hdll undex
- Create a new project
- Now in the hlextLib directory
- Create another directory to house the Haxe wrapper module for the hdll. Here this is
hlext
- Create a Haxe module in it like
HLExt.hx
- Create another directory to house the Haxe wrapper module for the hdll. Here this is
- Now in the overall project directory create a
- build.hxml containing this, or similar
-cp hlextLib -main Main -hl export/hl/main.hl
- Main.hx
- This will contain the test code.
You should now be able to build the test code. If all goes well you will have a main.hl
under export\hl
.
At this point you can open another Powershell to run the program. This will require adding the <FULL PATH>/hlextLib/x64/Debug
directory to the shell PATH
variable so that HL can load the extension.
Run with something like & 'D:\Program Files\HashLink1.14\hl.exe' .\export\hl\main.hl
First, my thanx those who created these.
[1] https://github.com/HaxeFoundation/hashlink/wiki/HashLink-native-extension-tutorial
This got me most of what I needed though I found a few omissions that left me casting around for exactly how to get a full runnable program using the extension. This also contains good reference material on data types, how to pass parameters and how to handle returns.
[2] https://github.com/josuigoa/hl-extension/tree/master
This is a good example but more complex for a first try than I wanted. What I took from this mostly was the directory layout and build file.