Adobe AIR ane project trial

Source: Internet
Author: User
Recently, I am working on a poser project and need to use air To Call DLL. ANE is used. I have downloaded several ane instances before, and it is okay to embed them directly before release (Click here ). However, writing ane on your own is still quite troublesome, and it won't be c ++ or C. Therefore, you can only draw images from the gourd tree for the time being. Many problems have been encountered in the middle, mainly in C ++, in addition, I am familiar with Flex, so I would like to summarize my problems.

After multiple attempts, the C ++ DLL is successfully called. In the debug test, always show the DLL in the method can not find the situation, some people say that put a DLL in the windows-system32 on the line (but ultimately I did not put actually succeeded. I am using air3.4), and there is a problem with the c ++ code. I am not a computer, except for the language as, I only have a little bit of C #, so I am not very familiar with the key points of writing the DLL called by the outside. After countless failures and disappointments, I finally found the correct path. Now I have recorded this path and forgotten it.


First, add these two items # include "flashruntimeextensions. H"; # pragma comment (Lib, "flashruntimeextensions "). The two can be found in airsdk. (In the include and Lib folders ). In the C ++ project name folder. Then, when defining the interface, add the extern
In the braces "C" {} (self-built), in addition to defining the interface you want, you also need to define extension. the two methods defined by the initializer and finalizer labels in XML (do not forget to add _ declspec (dllexport) in front of them), as well as the contextinitializer and contextfinalizer methods used in the two methods. If multiple interfaces need to be configured in the contextinitializer method. For details, refer to air
Native extension implements in-APP purchase (in-APP purchase) Full tutorial (2)-air native extension for iOS devices

For example, my extension. xml file:

<Extension xmlns = "http://ns.adobe.com/air/extension/2.5">
<ID> com. posane. dlldydll </ID>
<Versionnumber> 1.0.0 </versionnumber>
<Platforms>
<Platform name = "Windows-x86">
<Applicationdeployment>
<Nativelibrary> dlldydll. dll </nativelibrary>
<Initializer> extinitializer </initializer>
<Finalizer> extfinalizer </finalizer>
</Applicationdeployment>
</Platform>
</Platforms>
</Extension>


 My c ++ code (here for Data ConversionUsing IOS-oriented native air extensions for data transmission-Part 2: connecting to C, C ++, and objective-C
Converting between basic data types, Using IOS-oriented native air extensions for data transfer-Part 1: Converting vector between ActionScript 3 and C, C ++, or objective-C
And array object):

// Dlldydll. cpp: defines the export function of the DLL application.
//
# Include "stdafx. H"
# Include "dlldydll. H"
# Include "flashruntimeextensions. H"
# Pragma comment (Lib, "flashruntimeextensions ")
# Include "string. H"
# Include "stdio. H"
# Include "stdlib. H"

// This is an example of exporting Variables
Dlldydll_api int ndlldydll = 10;

// This is an example of the export function.
Dlldydll_api int fndlldydll (void ){

Return 1;
}

Extern "C"
{
Freobject login (frecontext CTX, void * funcdata, uint32_t argc, freobject argv [])
{
Int32_t icontype;
Fregetobjectasint32 (argv [3], & icontype );

Uint32_t idlength;
Const uint8_t * PID;
Fregetobjectasutf8 (argv [0], & idlength, & pid );

Uint32_t namelength;
Const uint8_t * pname;
Fregetobjectasutf8 (argv [1], & namelength, & pname );

Const char * newname = (const char *) pname;

Freobject idname;
Frenewobjectfromutf8 (strlen (newname) + 1, (const uint8_t *) newname, & idname );
// Printf ("asfwef ");
Return idname;
}
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 *) "login ";
Func [0]. functiondata = NULL;
Func [0]. Function = & login;
* Functionstoset = func;
}
Void contextfinalizer (frecontext CTX)
{
Return;
}

_ Declspec (dllexport) void extinitializer (void ** extdatatoset, frecontextinitializer * ctxinitializertoset, frecontextfinalizer * ctxfinalizertoset)
{
* Extdatatoset = NULL;
* Ctxinitializertoset = & contextinitializer;
* Ctxfinalizertoset = & contextfinalizer;
}
_ Declspec (dllexport) void extfinalizer (void * extdata)
{
Return;
}
}
// This is the constructor of the exported class.
// For more information about class definition, see dlldydll. h.
// Cdlldydll: cdlldydll ()
//{
// Return;


Right-click the project to generate the DLL.


Let's look at how ANE is packaged. There are several articles about how to export the SWC required by ANE and how to package multi-thread serial port communication ane.
Air native extension C ++ global coordinate configuration environment to release full explanation, and how to pack ane.

First, you also need a p12 certificate and a SWF and SWC file in addition to the DLL file and XML file mentioned above (it is better to put it in the same folder ).

I use flashThe SWC created by builder4.6 is started with FlashPro do not do SWC, one is must inherit Sprite, but cannot add parameter swf-version13 (version and extension/2.5 in XML or 3.1, the former has a minimum requirement of 13, the latter requires 14, if not, an error will be reported during packaging ). so we use fb for this purpose. For details about the content format, refer to the above articles (note that the ID pointed to by the created extensioncontext must correspond to the ID in XML ). After SWC comes out, it is decompressed to catalog.xmland library.swf.

 The ADT command is required for packaging. The ADT command is the ADT. bat in the bin folder of the airsdk. If you do not set the environment variable, you need to make the command line point to the bin folder (CD command) and then run the ADT command. To set the variable environment in win7, choose "computer"> "Advanced System settings"> "environment variable", select path in the system variable, and click Edit, add ";" at the end of the path value, and then add the address of the bin folder. Click OK. Then the ADT command can be written in the TXT file, and then changed to the suffix ". Bat", so you don't have to write that long string every time. If 'java' is not an internal or external command during packaging, You need to configure the Java environment. The method is the same as above. If JDK is not installed, install JDK first. The following is my packaging statement:

ADT-package-TSA none-storetype PKCS12-keystore mycert. p12-storepass 12344321-target ane dlldydll. Ane extension. XML-SWC EPOs. SWC-platform Windows-x86 library.swf dlldydll. dll

Add the packaged ane file to the Flash project and use it.

In addition, the Updater class has the following restrictions.

Only supports desktop configuration files
Updater class. Extended desktop applications (applications installed using the local installer) do not support this function, nor does the Air Mobile configuration file or the air for TV configuration file support this function. CheckUpdater.isSupported Attribute. Extended desktop applications (applications installed using the local installer) can download new versions of the local installer and useFile.openWithDefaultApplication() Method to start it.


My original program is. air'. If it is extended, it will not be able to upgrade .air..exe's kernel (although the. exe upgrade can be solved by downloading the file and opening the EXE installation method, but the problem of converting from air to EXE for the first time cannot be solved ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.