# Haxe code visibility

**URL:** https://community.haxe.org/t/haxe-code-visibility/2962
**Category:** Haxe
**Created:** [April 1, 2021, 11:57am UTC](https://community.haxe.org/t/haxe-code-visibility/2962 "2021-04-01T11:57:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Bobi](https://avatars.discourse-cdn.com/v2/letter/b/ee7513/32.png) [@Bobi](https://community.haxe.org/u/Bobi)
#### Post date: [April 1, 2021, 11:57am UTC](https://community.haxe.org/t/haxe-code-visibility/2962/1 "2021-04-01T11:57:22Z")

</div>

Good morning guys!

I have a simple question (been searching the web for a solution for hours by now and can’t find an answer).

Is there a way to pack your haxe classes into a dll similar structure?  
So basically I want someone to reuse my code but don’t want to expose what actually the functions do?

---

<div class="post-metadata">

### Author: ![haxiomic](https://community.haxe.org/user_avatar/community.haxe.org/haxiomic/32/75_2.png) [@haxiomic](https://community.haxe.org/u/haxiomic)
#### Post date: [April 2, 2021, 6:08pm UTC](https://community.haxe.org/t/haxe-code-visibility/2962/2 "2021-04-02T18:08:53Z")

</div>

Hey @Bobi!

I’ve created [haxe-c-bridge](https://github.com/haxiomic/haxe-c-bridge) as a tool for making native haxe libraries that expose a C API. It uses hxcpp.

Firstly, set your target to hxcpp by adding `--cpp bin` to your hxml, next tell hxcpp you want a dll rather than an exe by adding `-D dll_link`

When you compile now you’ll get a dll 🥳 but you still need some way to use it. There’s two things to think about here: first, we need to expose functions so you can call them from C/C++/Swift/whatever. Next, we need to consider how to play nicely with haxe’s garbage collection and its event-loop so haxe events (like `haxe.Timer.delay()`) and haxe threads all work correctly. Haxe-c-bridge exists to handle both these things.

Install haxe-c-bridge into your project (it’s a single file so you can just copy it if you want), then add `@:build(HaxeCBridge.expose())` to any class you want to expose. It will generate a C header file alongside your .dll exposing all public methods on that class. All haxe code is executed in a separate thread called the haxe-thread so before you call any methods just call `initializeHaxeThread(onHaxeException);` and you’re good to go!

Because it’s plain-old-c you can use it from any language with a C interface, i.e. Swift, Go etc. Checkout the [github page](https://github.com/haxiomic/haxe-c-bridge) for the full details
