Windows ANE tutorial: The native DLL project

At the end of this part you will have:

A C/C++ project which you have set up to use the Adobe AIR C API.

Note that, although the steps here are done with Microsoft Visual C++, you don’t necessarily need to stick with it. Any IDE or command-line compiler that builds C/C++ code will do, for example GCC. The most important steps in this part of the tutorial are making sure that your C/C++ code can see FlashRuntimeExtensions.h and link with FlashRuntimeExtensions.lib from the Adobe AIR SDK.

You will see why I am using Visual C++ later, when we get round to debugging

Time

8-10 miutes

Step 1: Create a Visual C++ project

In Visual C++ select File > New > Project:

Create a new project in Visual Studio

Choose Win32 > Win32 Console Application as the type of your project. Yes, I know we are making a DLL. This choice will make sense in the next step, I promise.

Choose a Win32 Console Application

In the wizard that appears click Next and on the Application Settings page select Application Type: DLL.

Empty project?

Choose a Win32 Console Application and make it DLL - empty project

Hit Finish and you should end up with the following pretty boring project structure in Visual C++’s Solution Explorer:

Empty project in Solution Explorer

Step 2: Set up your project to see the AIR C API

Note: If you are using Visual Studio 2015 or 2017 you may need to do Step 4 before Step 2. See the comment below.

Thank you, David!

 

In Solution Explorer right-click on Header Files, then select Add > Existing Item. Navigate to your AIR SDK installation and find the include folder; from it select FlashRuntimeExensions.h. For example: C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\include\FlashRuntimeExtensions.h.

You can alternatively copy FlashRuntimeExtensions.h in your project folder and add it from there. If you are wondering which is better, read this blog post: Do you need a copy of FlashRuntimeExtensions.h in your project?

If you choose to use FlashRuntimeExtensions.h from the Adobe AIR SDK folder directly, don’t forget to tell your project to look for it in that folder. Go to your project’s Properties and under C/C++ > General > Additional Include Directories add the path to the folder which contains FlashRuntimeExtensions.h:

Additional include directories - FlashRuntimeExtensions header

Your project should now look a little less boring:

Add FlashRuntimeExtensions header to your project

 

Step 3: Tell the linker where the AIR C implementation is

What the previous step has done is expose Adobe AIR C API to the code you are about to write. This header however contains only definitions like this one and no implementation:

In order to make the imlpementation available to your code, you need to get your project to use the static library in which it lives. You do this in two stages:

First, open your project’s property pages (right-click your project in Solution Explorer and select Properties) and under Linker > General > Additional Library Directories add the path to the folder in your Adobe AIR SDK where  FlashRuntimeExtensions.lib lives.

In my install it is in C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\lib\win.

Add FlashRuntimeExtensions static library to your project - stage 1

Note that the same principle applies as when you add the FlashRuntimeExtensions.h header: you may or may not want a copy of it and FlashRuntimeExtensions.lib in your project. Have a look at: Do you need a copy of FlashRuntimeExtensions.h in your project?

Next, tell your project the name of the static library you are interested in. Still in Properties open Linker > Input > Additional Dependencies and add FlashRuntimeExtensions.lib as shown below:

Add FlashRuntimeExtensions static library to your project

Step 4: Add a source file and build the DLL

In Solution Explorer right-click Source Files, then select Add > New Item…

Add your first source file

Select C++ File (.cpp) as the type of your file and give it a name. I’ve named mine dllMain.cpp:

Add a cpp fileNow let’s build the project. Shock, horror! No code yet and we can get a DLL out of this:

I know your hands are itching to code, so let us move on to that. Go to the next part of this tutorial.

What’s next?

Helpful reading

If you are new to Windows programming, you may find this helpful:

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

Comments

  1. David

    In VisualStudio 2015 and VisualStudio 2017, it would seem Step 4 is required before Step 2 (even if it’s just an empty dllMain.cpp file), otherwise the Configuration Properties > C/C++ menu item is suppressed.

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="">