接著將FlashRuntimeExtensions.h以及FlashRuntimeExtensions.lib加入至專案
接著在標頭檔資料夾內加入自定義的標頭檔,並將以下程式碼貼入
MyHeader.h
#include "FlashRuntimeExtensions.h" extern "C" { __declspec(dllexport) void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet); __declspec(dllexport) void ExtFinalizer(void* extData); __declspec(dllexport) FREObject GetInfo(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); }
再原始程式碼的資料夾底下加入自定義的程式碼,將以下程式碼貼入
GetInfo是我們主要讓Flash操作用的方法,回傳值是Array,Array內包含姓名與作號和分數
MyHeader.cpp
#include "MyHeader.h" #include "stdafx.h" extern "C" { FREObject GetInfo(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { FREObject result; char *userName = "王小明"; char *number = "123456"; char *score = "80"; FRENewObject((const uint8_t*)"Array", 0, NULL, &result, NULL); FREObject objectName = dnsName; FREObject objectNumber = name; FREObject ObjectScore = score; FRESetArrayElementAt(result, 0, objectName); FRESetArrayElementAt(result, 1, objectNumber); FRESetArrayElementAt(result, 2, ObjectScore); return result; } void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctions, const FRENamedFunction** functions) { *numFunctions = 1; FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*(*numFunctions)); func[0].name = (const uint8_t*)"GetInfo"; func[0].functionData = NULL; func[0].function = &GetInfo; *functions = func; } void ContextFinalizer(FREContext ctx) { return; } void ExtInitializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer) { *ctxInitializer = &ContextInitializer; *ctxFinalizer = &ContextFinalizer; } void ExtFinalizer(void* extData) { return; } }
參考資料:
http://rhuno.com/flashblog/2012/04/30/tutorial-flash-and-c-native-extension/