【发布时间】:2016-12-23 13:02:24
【问题描述】:
编辑:我终于能够制作“Hello, World!”项目集。如果您也遇到Error #3500 问题,请参阅my answer below 以获取工作项目集。
我目前正在制作“Hello, World!”带有 FlashDevelop 的 Adobe AIR 原生扩展。因此,我的 Native Extension 旨在供我正在编程的 Windows-x86 平台使用。
我通过(自定义)批处理文件构建了 ANE。使用该 ANE 的测试 AIR 应用程序编译得很好,但是,就像我看到的许多其他人的帖子一样,我收到了 Error #3500: The extension context does not have a method with the name helloWorld.
三天来我一直试图了解发生了什么,尽管解决了几个原因,但我仍然遇到同样的错误。
似乎应用程序运行时实际上从未调用过initializeExtension 函数,因为 DebugView 不跟踪任何内容,即使我的初始化程序使用了OutputDebugString(L"Extension initialized");。
发了很多代码感觉有点不好意思,但是看了三天,看了几十个网页,就是不知道问题出在哪里了。
无论如何,应用程序构建分 3 步完成:
1) 在 Visual Studio 中使用 Release 标志构建 DLL。我在下面发布该代码作为对 Michael 评论的回应,但是,我不确定错误是否来自那里。
我的native端主要由一个header和一个C++文件组成:
// -------------------------
// | 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
下面是函数的实现:
// ------------------
// | 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;
}
根据 alebianco 的要求,here is the build log 在构建 DLL 时。请注意,在执行自定义构建批处理文件的最后,我在日志的最后有一个错误。我不知道这个错误来自哪里;我上次构建该项目时没有出现该错误。此外,它可能是 FlashDevelop 内部的。
2) 构建 ANE。我正在使用批处理文件来运行以下命令:
为了构建 SWC,我调用了 compc。变量展开后是这样的:
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
我的src 文件夹包含一个简单的类:
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"));
}
}
}
反过来,在将我的 Visual Studio 文件夹中的 DLL 和 library.swf(我从 SWC 中提取)复制到 ANE Build Files\platforms\Windows-x86 之后,我使用 adt 构建 ANE。变量展开后,命令如下:
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" .
这是我提供的扩展描述符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) 构建实际应用程序。我正在使用 FlashDevelop 制作的默认批处理文件(经过两次修改以包括 ANE)来构建 AIR AS3 投影仪。
请注意,如果我收到错误 #3500,这意味着(我想)我的应用程序已成功包含来自 ANE 的类,因为构造函数正在工作。
这是我正在使用的应用程序描述符,以防万一。
<?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>
我正在使用与 AIR SDK (22.0.0) 合并的 Flex (4.6.0)。
我做错了什么吗?什么可以帮助我解决这个问题?
再次抱歉,我发布了很多代码;我已经尝试精简到最相关的内容。
提前致谢!
【问题讨论】:
-
嗨,该错误通常表明本机代码存在问题,因为您尚未声明该方法。能否贴出原生端初始化扩展上下文的代码?
-
@Michael 按照你的要求,我添加了我的本地代码。
-
即使您的 ANE 代码完全错误,也不会出现编译错误,除非您尝试在 ANE 中调用某些内容。似乎扩展的 actionscript 部分在您的 C++ 代码中找不到 helloWorld 函数。我对C++一无所知,但我猜你在initializeContext中所做的函数声明出了点问题。也许函数[0].name = (const uint8_t*)"helloWorld";部分错了?
-
@Philarmon 我的应用程序调用 AS3 扩展类的
helloWorld函数。反过来(如步骤 2 中的 AS3 代码所示),该函数调用本机helloWorld函数。因此,我正在调用本机函数。至于C++的赋值,我觉得没有错,因为我基本上复用了Adobe's example中的代码。 -
@Philarmon 除非强制转换为
const uint8_t*不遵循 ANSI 表...我应该检查一下。
标签: shell actionscript-3 visual-c++ air ane