Windows ANE tutorial: The native DLL code

At the end of this part you will have:

A Windows DLL, ready to communicate with ActionScript and to be packaged in an ANE.

Time

10-15 miutes

Wait, have you done this first?

  • Part 1: The native DLL project, 8-10 minutes
  • Note: You don’t need an IDE or a full-blown project as shown in the previous step in this tutorial. If you have a compiler that can build C/C++ code and have set your source root to see FlashRuntimeExtensions.h and link with FlashRuntimeExtensions.lib from the Adobe AIR SDK, you are good to go.

Step 1: Include the C API header

Open the dllMain.cpp file you created in the previous part of this tutorial.

Start by adding the Adobe AIR C API header to the top:

Step 2: Add the extension initializer and finailzer

This is what they look like in a C++ file for Windows:

We are going to code in C++ and the AIR SDK for Windows comes as a C implementation. Our ExtensionInitializer and ExtensionFinalizer functions will also be imlpemented in C, rather than C++. The extern “C” bit around them is a signal to the compiler to use C linkage.

If you need a reminder of what an extension initializer and finalizer are, read this blog post: Extension Initializer and Finalizer in C.

Step 3: Add the extension context initializer and finailzer

Note: add this code above your ExtensionInitializer and ExtensionFinalizer functions, so that it’s visible to them.

Here is a diagram that shows where the Extension Context Initializer and Finalizer fit in your native extension and the order of calls when your ANE is used.

Step 3: Add some meaningful code

Finally! Let us add a function that will take a string parameter from ActionScript and pass it back. Again, add this code above your contextInitializer and contextFinalizer functions.

You will also need to also add the following include directives to the top of your file:

Step 3: Build your DLL

That’s it. That’s the Windows part of the Native Extension done. Hit build and if you are using Visual C++, you should see something like this:

Questions?

Shoot in the comments below.

What’s next?

Helpful reading

If you are new to Windows programming, these might be a helpful companion to understanding the code you have just written:

Opt In Image
Early bird offer on the ANE eBooks

 

Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.

 

 

  • step-by-step guide to making your iOS extension in under an hour
  • library for data conversion between ActionScript and native code
  • tutorials
  • infographics
  • code included

Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Comments

  1. Eric Zwar

    Thank you for this great tutorial. However, to get this dll to compile in Visual C++ 2010 Express Edition I had to change the order of the functions as follows:

    1) FREObject ASPassAString
    2) void contextInitializer
    3) void contextFinalizer
    4) the extern C (which is now the last function)

    Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">