2

EDIT: I was finally able to make a "Hello, World!" project set. If you are also having Error #3500 problems, see my answer below for a working project set.

I'm currently making a "Hello, World!" Native Extension for Adobe AIR with FlashDevelop. My Native Extension is thus meant to be used by Windows-x86 platforms, which I'm programming on.

I've built the ANE via a (custom) batch file. The test AIR Application which uses that ANE compiles fine, but, like so many other people I've seen the posts of, I'm getting Error #3500: The extension context does not have a method with the name helloWorld.

I've been trying to understand what was going on for three days now, and, despite fixing several causes, I'm still getting the same error.

It seems the application runtime never actually gets to call the initializeExtension function, since DebugView doesn't trace anything, even though my initializer uses OutputDebugString(L"Extension initialized");.

I feel a bit bad for posting a lot of code, but after three days and dozens of webpages read, I'm just not sure where my problem is coming from.

Anyway, application building is done in 3 steps :

1) Building the DLL in Visual Studio with the Release flag. I'm posting that code as a response to Michael's comment below, however, I'm not sure the error is coming from there.

My native side is mainly made up of a header and a C++ file :

// -------------------------
// | NativeExtensionTest.h |
// -------------------------

#pragma once

#include "FlashRuntimeExtensions.h"

#ifdef __cplusplus
EXTERN_C
{
#endif

    __declspec(dllexport) void initializeExtension(
    void** dataToSet,
    FREContextInitializer* contextInitializer,
    FREContextFinalizer* contextFinalizer
    );


    __declspec(dllexport) void finalizeExtension(
        void* extData
        );


    __declspec(dllexport) void initializeContext(
        void* contextData,
        const uint8_t* contextType,
        FREContext context,
        uint32_t* nFunctionsToSet,
        const FRENamedFunction** functionsToSet
        );


    __declspec(dllexport) void finalizeContext(
        FREContext context
        );


    __declspec(dllexport) FREObject helloWorld(
        FREContext context,
        void* functionData,
        uint32_t argc,
        FREObject argv[]
        );

#ifdef __cplusplus
}
#endif

And here is the implementation of the functions:

// ------------------
// | HelloWorld.cpp |
// ------------------

#pragma once

#include "stdafx.h" // precompiled header ; includes cstdlib, cstring and windows.h
#include "FlashRuntimeExtensions.h"
#include "NativeExtensionTest.h"


using namespace std;


void initializeExtension(
void** dataToSet,
FREContextInitializer* contextInitializer,
FREContextFinalizer* contextFinalizer
)
{
    dataToSet = NULL;
    *contextInitializer = &initializeContext;
    *contextFinalizer = &finalizeExtension;
}



void finalizeExtension(
    void* extData
    )
{ }



void initializeContext(
    void* contextData,
    const uint8_t* contextType,
    FREContext context,
    uint32_t* nFunctionsToSet,
    const FRENamedFunction** functionsToSet
    )
{
    *nFunctionsToSet = 1;
    FRENamedFunction* functions = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)* (*nFunctionsToSet));

    functions[0].name = (const uint8_t*)"helloWorld";
    functions[0].function = &helloWorld;
    functions[0].functionData = NULL;

    *functionsToSet = functions;
}


void finalizeContext(
    FREContext context
    )
{ }


FREObject helloWorld(
    FREContext context,
    void* functionData,
    uint32_t argc,
    FREObject argv[]
    )
{
    char* hello = "Hello, World!";
    unsigned int helloLength = strlen(hello) + 1;
    FREObject ret;

    FRENewObjectFromUTF8(helloLength, (const uint8_t*)hello, &ret);

    return ret;
}

As alebianco requested, here is the build log when building the DLL. Note that I have an error at the very end of the log, at the end of the execution of a custom build batch file. I don't know where this error is coming from ; I didn't have that error last time I built that project. Besides, it's probably internal to FlashDevelop.

2) Building the ANE. I'm using a batch file to run the following commands:

To build the SWC, I invoke compc. After variable expansion, it looks like this:

compc -include-sources"C:\Users\Anthony Dentinger\Desktop\Native Extension Test\src" -output "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\NativeExtHelloWorld.swc" -load-config "C:\Users\Anthony Dentinger\AppData\Local\FlashDevelop\Apps\flexsdk\4.6.0\frameworks\air-config.xml" -swf-version 14

My src folder contains a simple class:

package
{
    import flash.events.EventDispatcher;
    import flash.external.ExtensionContext;


    public class NativeExtHelloWorld extends EventDispatcher {

        private var extContext:ExtensionContext;

        public function NativeExtHelloWorld()
        {
            extContext = ExtensionContext.createExtensionContext("NativeExtHelloWorld", "helloWorldContext");
        }

        public function helloWorld() : String
        {
            return String(extContext.call("helloWorld"));
        }

    }

}

In turn, after copying both the DLL from my Visual Studio folder and library.swf (which I extract from the SWC) to ANE Build Files\platforms\Windows-x86, I build the ANE with adt. After variable expansion, the command looks like this:

call adt -package -target ane "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\HelloExtension.ane" "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\descriptor.xml" -swc "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\NativeExtHelloWorld.swc" -platform "Windows-x86" -C "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\platforms\Windows-x86" .

Here is the extension descriptor that I provide adt:

<?xml version="1.0" encoding="utf-8"?> 
<extension xmlns="http://ns.adobe.com/air/extension/3.1">

    <id>NativeExtHelloWorld</id> <!--I'll later change that ID to something like com.example.myExt.HelloWorld-->
    <name>Exension Name</name>
    <description>Description of the Extension</description>
    <versionNumber>0.0.1</versionNumber>
    <copyright>© 2010, Examples, Inc. All rights reserved.</copyright>

    <platforms>
        <platform name="Windows-x86">
            <applicationDeployment>
                <nativeLibrary>HelloWorld.dll</nativeLibrary>
                <initializer>initializeExtension</initializer>
                <finalizer>finalizeExtension</finalizer>
            </applicationDeployment>
        </platform>
    </platforms>

</extension>

3) Building the actual application. I'm using the default batch files made by FlashDevelop (with two modifications to include the ANE) for building AIR AS3 Projectors.

Note that, if I'm getting error #3500, it means (I suppose) that my application has successfully included my class from the ANE, since the constructor is working.

This is the application descriptor I'm using, in case that's helpful.

<?xml version="1.0" encoding="utf-8" ?> 
<application xmlns="http://ns.adobe.com/air/application/15.0">

    <id>TEST</id>
    <versionNumber>1.0</versionNumber>
    <filename>TEST</filename>
    <name>TEST</name>

    <initialWindow> 
        <title>TEST</title> 
        <content>TEST.swf</content> 
        <systemChrome>standard</systemChrome> 
        <transparent>false</transparent> 
        <visible>true</visible> 
        <minimizable>true</minimizable> 
        <maximizable>true</maximizable> 
        <resizable>true</resizable> 
    </initialWindow> 

    <supportedProfiles>extendedDesktop</supportedProfiles>

    <extensions>
        <extensionID>NativeExtHelloWorld</extensionID>
    </extensions>
</application>

I'm using Flex (4.6.0) merged with the AIR SDK (22.0.0).

Have I done something wrong? What will help me fix this issue?

Once again, I'm sorry I posted quite a bit of code ; I've tried trimming down to what was most relevant.

Thanks in advance!

Community
  • 1
  • 1
adentinger
  • 1,367
  • 1
  • 14
  • 30
  • Hi, That error generally indicates an issue with the native code in that you haven't declared the method. Can you post the code for the initialisation of the extension context on the native side? – Michael Aug 17 '16 at 07:22
  • @Michael As you requested, I added my native code. – adentinger Aug 17 '16 at 12:50
  • 1
    There will be no compile errors even if your ANE code is completely wrong unless you try to call something within your ANE. It seems that the actionscript part of the extension can not find the helloWorld function within your C++ code. I have no idea about C++ but I'd guess something went wrong in your function declarations that you do in initializeContext. Maybe the functions[0].name = (const uint8_t*)"helloWorld"; part is wrong? – Philarmon Aug 17 '16 at 13:31
  • @Philarmon My application calls the AS3 extension class' `helloWorld` function. In turn (as the AS3 code in step 2 shows), that function calls the native `helloWorld` function. Thus, I _am_ calling the native function. As regards the C++ assignment, I don't think this is wrong, since I basically reused the code in [Adobe's example](http://help.adobe.com/en_US/air/extensions/WS460ee381960520ad-866f9c112aa6e1ad46-7ffe.html). – adentinger Aug 17 '16 at 13:45
  • @Philarmon Unless coercion to `const uint8_t*` doesn't follow the ANSI table... I should check that. – adentinger Aug 17 '16 at 13:54
  • Yes, and it seems the error happens when the AS3 part is trying to call the native helloWorld function. The native functions need to be registered with a name (as you do in the initializeContext) to be visible for the AS3 part. So my guess is that your function is either not registered correctly or maybe the ANE is not packaged correctly. Are you using the latest AIR SDK ? – Philarmon Aug 17 '16 at 13:58
  • @Philarmon Yes, I'm using Flex SDK 4.6.0 merged with the AIR SDK 22.0.0. Using AIR SDK 22.0.0 alone yields the same result. – adentinger Aug 17 '16 at 13:58
  • @Philarmon I've done the check by outputting the `const uint8_t*` table in a binary file. The coercion is correct ; it also follows the ASCII table and is ended by a NULL character. – adentinger Aug 17 '16 at 15:31
  • can you log the operations on the native side? I've never worked with windows extensions, but with android and ios extensions, logging saved me in a lot of situations. often the initialisation goes wrong and the function is not registered correctly – alebianco Aug 19 '16 at 16:36
  • @alebianco Done. Thanks in advance for helping! (P.S., my Visual Studio version is French.) – adentinger Aug 19 '16 at 20:58

1 Answers1

1

I've somehow solved the problem, and everything works now. I tried going back to see what I was doing wrong, but I can't quite figure it out. My guess is one of the batch files that copies and unzips the ANE was using the wrong target, so I ended up using the same old ANE, rather than using the ANE I was building (silly me).

Following Colonize.bat's request, here is a working Hello, World! example. I used VisualStudio 2013 and FlashDevelop to make this.

You can find several Error #3500 causes in the following files:

  • 1_Build_DLL/Hello World/main.cpp
  • 2_Build_ANE/lib/descriptor.xml
  • 2_Build_ANE/src/HelloWorldExtension.as

Causes of some other errors I've read about (or encountered!) as also indicated in other files. In fact, the custom batch files indicate the procedure to follow in order to make and use your own ANE.

NOTE : Don't try to build directly from these files. I'm using batch files in order not to have to run commands and copy/paste/unzip files by hand, so the targets and environment variables will not be valid on your computer.

adentinger
  • 1,367
  • 1
  • 14
  • 30
  • Dou you think you can provide a dump of that project for others to check out? I'm currently on day 4 figuring out the #3500 error and am very much stuck on why and where. – Colonize.bat Sep 10 '16 at 13:54
  • 1
    @Colonize.bat Yeah, it's annoying, isn't it? Sure, I can do that. However, because of the number of times I've made the project from scratch, I have several semi-working files. Give me a couple of days and I'll upload a working project set. – adentinger Sep 11 '16 at 02:21
  • 1
    @Colonize.bat Sorry for the delay ; I was busy in the past few days. You can find a working project set in the link in the answer above. – adentinger Sep 14 '16 at 22:11