This is a native library to read and write clipboard data from Haxe. It uses Ammer to generate bindings.
Note: This is a Windows only library for now!
You could compile the Dll and include it in your C/C++ project.
PR welcome :)
- fix hl
- add linux
- add mac
- Install
- API
- Directory structure
- Building the native library
- Building the Sample Haxe project
- Running
- Troubleshooting
haxelib install native-clipboard
If you want to use with OpenFl, you just have to add this to your project.xml
:
<haxelib name="native-clipboard"/>
And you can use x86 binaries instead of the default x64 by adding this above your haxelib tag:
<define name="X86"/>
If you want the last version of native-clipboard, you can install with git:
haxelib git native-clipboard https://github.com/loudoweb/native-clipboard.git
But you will also have to build the dll by yourself (see building native library)
//example: get an image with openfl
var bytes = Clipboard.get_image();
if(bytes != null && bytes.length > 0)
{
bd = BitmapData.fromBytes(bytes);
}
//example: get an html text
var htmlstr = Clipboard.get_data(EClipboard.HTML);
//example: get a svg
var svgstr = Clipboard.get_data(EClipboard.SVG);
//example: get a pdf
var svgstr = Clipboard.get_bytes(EClipboard.PDF);
/set html text
Clipboard.set_data(EClipboard.HTML, ClipboardUtils.formatHTML('<p>test html : this is <b>bold</b></p>'))
haxe/extension
Clipboard.hx
-ammer
library definition for theClipboard
library. This class essentially maps Haxe types to the C library.EClipboard.hx
- helper class: some types you may encounter in clipboard.ClipboardUtils.hx
- helper class: format html (input/output), svg, etc.
Sample.hx
- sample using the library in regular Haxe code.build-common.hxml
- build configuration common to all targets.build-cpp.hxml
- build configuration for hxcpp.build-hl.hxml
- build configuration for HashLink. Must be call from VS developer prompt.build-cpp.bat
- executable to build hxcpp.build-hl.bat
- executable to build hl. Must be call from VS developer prompt.include.xml
- Lime/OpenFl extensionnative
- contains sources to theclipboard
library.clipboard.c
clipboard.h
Makefile.win
- build script for building the library on Windows (using MSVC). Must be call from x86 VS developer prompt.Makefile64.win
- build script for building the library on Windows (using MSVC). Must be call from x64 VS developer prompt.build_windows.bat
- executable that call the makefile. Must be call from x86 VS developer prompt.build_windows64.bat
- executable that call the makefile. Must be call from x64 VS developer prompt.
library
- contains dlls in different folder depending on OS/architecture.
Execute native/Makefile from VS developer prompt.
Assuming MSVC is set up on the local machine, navigate to the native
directory in a Visual Studio Developer Command Prompt, then use the provided Makefile.win
:
$ cd <path to poc directory>/native
$ nmake /F Makefile.win
This should create (among others) the files clipboard.dll
and clipboard.lib
in the native
directory.
If you want to compile dll for 32bit, use the x86 VS developer prompt, and the x64 VS developer prompt to compile for 64 bit.
Once the native library is built, the Haxe project itself can be compiled. The necessary configuration is already provided in the HXML files. Some targets require additional configuration, which needs to be provided on the command line via a define. See the target-specific configuration section in the main README for more information about these defines.
You can execute the build_{target}.bat.
Note: HL bat needs to be executed from VS developer prompt.
ammer
works with dynamic libraries (except on hxcpp on Windows), which must either be distributed alongside with the program or already be present on the system.
$ cp native/adder.dll bin/hl
$ cd bin/hl
$ hl sample.hl
$ cd bin/cpp
$ ./Main
Due to issue in ammer library, clipboard is not working on hl yet.
This error can occur during the build phase when targeting HashLink. It indicates that the native compiler cannot find the hl.h
header file. Use the ammer.hl.hlInclude
option to point the compiler to a directory containing the hl.h
file.
- When using HashLink binary distributions, the directory is
include
in the downloaded folder. - When using HashLink built from source, the directory is
src
in the repository root.
This error can occur during the build phase when using MSVC on Windows. It indicates that the native compiler cannot find header files of the C standard library. To solve this:
- Either use the "Visual Studio Developer Command Prompt"; or
- Use a regular command-line prompt, but use the
vcvars32
script to initialise the environment.
This error can occur when testing HashLink for two reasons (possibly both at the same time):
The hl
command will look for hdll
files in the current working directory as well as the system library directories. Therefore, if clipboard.hdll
is in the bin/hl
directory (which is the case if the default configuration of this project is used), invoking hl
from the samples/poc
directory will NOT work.
- Either
cd bin/hl
before invokinghl
; or - Copy
clipboard.hdll
frombin/hl
into the current working directory.
Refer to the next section.
This error can occur when the system cannot find the compiled native library (.dll
, .dylib
, or .so
file).
On Windows, the system will look for dll
files in the current working directory.
- Copy
clipboard.dll
from thenative
directory into the current working directory.
On OS X and Linux, the dynamic linker needs to be told where to look for additional dynamic libraries with an environment variable.
- On OS X, prepend
DYLD_LIBRARY_PATH=<path to samples/poc/native>
to the command, e.g.DYLD_LIBRARY_PATH=../../native hl sample.hl
. - On Linux, prepend
LD_LIBRARY_PATH=<path to samples/poc/native>
to the command, e.g.LD_LIBRARY_PATH=../../native hl sample.hl
.
See also general notes about dynamic libraries in the main README.