1.编写WinANE.dll:
#include <windows.h>
#include <stdlib.h>
#include <FlashRuntimeExtensions.h>
#pragma comment( lib, "FlashRuntimeExtensions.lib" )
FREObject test(FREContext ctx, void*funcData, uint32_t argc, FREObject argv[])
{
const uint8_t* msg = (const uint8_t*)"hello world";
FREObject retObj;
FRENewObjectFromUTF8(strlen((const char*)msg)+1, msg, &retObj);
return retObj;
}
void ContextFinalizer(FREContext ctx)
{
return;
}
void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet)
{
*numFunctionsToTest= 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*1);
func[0].name= (const uint8_t*)"test";
func[0].functionData= NULL;
func[0].function= &test;
*functionsToSet= func;
}
extern "C" __declspec(dllexport) void ExtFinalizer(void* extData)
{
return;
}
extern "C" __declspec(dllexport) void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer*ctxFinalizerToSet)
{
*extDataToSet= NULL;
*ctxInitializerToSet= ContextInitializer;
*ctxFinalizerToSet= ContextFinalizer;
}
2.编写 swc库:
package
{
import flash.events.EventDispatcher;
import flash.external.ExtensionContext;
public class TestWinANE
{
private static var context:ExtensionContext;
public function TestWinANE()
{
try
{
context= ExtensionContext.createExtensionContext("WinANE", "");
}
catch(e:Error)
{
}
}
public function print():String
{
var str:String = context.call("test") as String;
return str;
}
}
}
使用如下命令编译:
acompc -compiler.debug=false -library-path+=D:/FlexSDK4.9.1 -external-library-path+=D:/FlexSDK4.9.1/frameworks/libs/framework.swc
-swf-version=20 -compiler.source-path ./ -include-sources ./ -output WinANE.swc
3.编写extension.xml:
<extension xmlns="http://ns.adobe.com/air/extension/3.7">
<id>WinANE</id>
<versionNumber>1.0.0</versionNumber>
<platforms>
<platform name="Windows-x86">
<applicationDeployment>
<nativeLibrary>WinANE.dll</nativeLibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
4.生成 WinANE.ane:
解压WinANE.swc,将library.swf与WinANE.swc和WinANE.dll,extension.xml放同一目录,执行如下命令:
adt.bat -package -target ane WinANE.ane extension.xml -swc WinANE.swc -platform Windows-x86 library.swf WinANE.dll
5.修改使用ANE的应用程序的XML文件,添加如下段:
<supportedProfiles>extendedDesktop</supportedProfiles>
<extensions>
<extensionID>WinANE</extensionID>
</extensions>