0

我正在尝试为 adobe flex 项目构建一个用 C++ 编写的本机扩展。我仔细检查了所有内容一百次,但无论我做什么,我总是得到错误“扩展上下文没有名为 getHelloWorld 的方法”。

这是我的代码:

Flash builder actionscript 类:

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

    public class QCARBridge extends EventDispatcher
    {
        private var extContext:ExtensionContext;

        public function QCARBridge()
        {
            extContext = ExtensionContext.createExtensionContext("NativeQCAR", null);

            if(!extContext) {
                throw new Error("Extension context couldn't be created :(");
            }
        }

        // Native methods
        public function getTestString():String {
            return extContext.call("getTestString") as String;
        }

        public function isSupported():int {
            return extContext.call("isSupported") as int;
        }

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

Flash builder extension.xml:

<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
    <id>NativeQCAR</id>
    <versionNumber>1</versionNumber>
    <platforms>
        <platform name="Windows-x86">
            <applicationDeployment>
                <nativeLibrary>libNativeQCAR.dll</nativeLibrary>
                <initializer>initializer</initializer>
                <finalizer>finalizer</finalizer>
            </applicationDeployment>
        </platform>
    </platforms>
</extension>

和 C++ 代码:

#include "main.h"
#include "Stdlib.h"
#include "String.h"

FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
  FREObject result;

  uint32_t isSupportedInThisOS = 1;

  FRENewObjectFromBool( isSupportedInThisOS,  &result);

  return result;
}

FREObject getTestString(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
  FREObject result;

  const char *str = "De android library zegt ook eens hallo...";
  FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t *)str, &result);

  return result;
}

FREObject getHelloWorld(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
  FREObject result;

  const char *str = "Hello World!!  This is your DLL talking!";
  FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t *)str, &result);

  return result;
}

void contextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctions, const FRENamedFunction** functions)
{
  *numFunctions = 3;
  FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctions));

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

  func[1].name = (const uint8_t*) "isSupported";
  func[1].functionData = NULL;
  func[1].function = &isSupported;

  func[2].name = (const uint8_t*) "getHelloWorld";
  func[2].functionData = NULL;
  func[2].function = &getHelloWorld;

  *functions = func;
}

void contextFinalizer(FREContext ctx)
{
  return;
}

void initializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer)
{
  *ctxInitializer = &contextInitializer;
  *ctxFinalizer = &contextFinalizer;
}

void finalizer(void* extData)
{
  return;
}

似乎我已经以正确的方式连接了所有点,但为什么它不工作呢?

4

0 回答 0