• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adobe Animate, C extensibility, sample code not working

Community Beginner ,
Mar 17, 2024 Mar 17, 2024

Copy link to clipboard

Copied

Hey everyone,

 

Sorry to bother.

Recently I'm trying to call functions from cutomised .dll.

The instruction I follow is this one:

https://github.com/AdobeDocs/developers-animatesdk-docs/blob/master/C-Level_Extensibility/Integratin...

 

Here's what I do:

1) I use VS 2022, create a new project, choose Dynamic-link library

2) creating a Header file named mm_jsapi.h, and copying the sample code into this header file.

3) creating a cpp file named test.cpp, and copying the sample code under section 'Sample DLL implementation'.

4) build solution, and I get the test.dll file

5) test.dll is then renamed to Sample.dll, and moved to ..\Animate 2023\en_US\Configuration\External Libraries

6) creating Sample.jsfl, copying the jsfl code into it, then moving Sample.jsfl to ..\Configuration\Commands

7) restart Adobe Animate, and run the command

 

it jumps out an error message, says

error.png

 

I'm so confused now and I don't know what to do.

If anyone ever succeeded in calling .dll function, could you please share some ideas?

 

Much appreciated.

Views

344

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Mar 23, 2024 Mar 23, 2024

Solved.

 

The sample code on github is NOT complete, that is to say, there are missing lines of code.

https://github.com/AdobeDocs/developers-animatesdk-docs/blob/master/C-Level_Extensibility/

Integrating_C_functions.md

 

1. The missing part

Thanks to The Blender18590443wuel and his post @

https://community.adobe.com/t5/animate-discussions/c-level-jsapi-array-object-returns-crash/m-p/13877627#M366451

After copying the sample code from the official doc, add the code below

 

MM_STATE

void
MM_Init()
{
     
...

Votes

Translate

Translate
Community Beginner ,
Mar 23, 2024 Mar 23, 2024

Copy link to clipboard

Copied

Solved.

 

The sample code on github is NOT complete, that is to say, there are missing lines of code.

https://github.com/AdobeDocs/developers-animatesdk-docs/blob/master/C-Level_Extensibility/

Integrating_C_functions.md

 

1. The missing part

Thanks to The Blender18590443wuel and his post @

https://community.adobe.com/t5/animate-discussions/c-level-jsapi-array-object-returns-crash/m-p/1387...

After copying the sample code from the official doc, add the code below

 

MM_STATE

void
MM_Init()
{
        /* (unsigned short*)L"computeSum"
        *  assume you write (unsigned short*)L"test1", then you use Sample.test1(a,b) to evoke your customised fuction in AN

        *  computeSum
        *  this is the name of your customised function in sample.c

        *  2
        *  this is the number of arguments your customised function expects to receive
        *  the function does a+b, so it needs 2 arguments */
        JS_DefineFunction((unsigned short*)L"computeSum", computeSum, 2);
}

 

 

2. If want to use sample.cpp instead of sample.c

Then change this part.

//this one is for sample.c
#include "mm_jsapi.h"

//this one is for sample.cpp
extern "C"
{
#include "mm_jsapi.h"
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

 

Can you help me? Why does my execution keep reporting this error after completing your modifications?

 

 

gcc -shared -o test.dll test.c

C:\Users\ADMINI~1\AppData\Local\Temp\cccWXxpW.o:test.c:(.text+0x14): undefined reference to `mmEnv'
C:\Users\ADMINI~1\AppData\Local\Temp\cccWXxpW.o:test.c:(.text+0x1d): undefined reference to `mmEnv'
C:\Users\ADMINI~1\AppData\Local\Temp\cccWXxpW.o:test.c:(.text+0x3e): undefined reference to `mmEnv'
C:\Users\ADMINI~1\AppData\Local\Temp\cccWXxpW.o:test.c:(.text+0x47): undefined reference to `mmEnv'

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

undefined reference to `mmEnv'

mmEnv is defined in mm_jsapi.h. Have you included it?

Make sure mm_jsapi.h contains no error. Or paste your code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

thank you for your reply. The problem with `mmEnv` has been solved, but a new problem has arisen with the same problem as the current questioner. Below is my complete code.

`mm_jsapi.h` has been modified according to the solution provided by The Blender18590443wuel.

 

#include <windows.h>
#include <stdio.h>
#include "mm_jsapi.h"

int main(void) {
	return 0;
}

JSBool computeSum(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval)
{
    long a, b, sum;
    // Make sure the right number of arguments were passed in.
    if (argc != 2)
    return JS_FALSE;

    // Convert the two arguments from jsvals to longs.
    if (JS_ValueToInteger(cx, argv[0], &a) == JS_FALSE ||
        JS_ValueToInteger(cx, argv[1], &b) == JS_FALSE)
         return JS_FALSE;

    /* Perform the actual work. */
    sum = a + b;
    
    /* Package the return value as a jsval. */
    *rval = JS_IntegerToValue(sum);

    /* Indicate success. */
    return JS_TRUE;
}

MM_STATE

void MM_Init() {
  JS_DefineFunction((unsigned short*) L"computeSum", computeSum, 2);
}

 

Ryan_ypm_1-1713836014471.png

 

After successfully compiling into dll, put the dll file into: C:\Users\Administrator\AppData\Local\Adobe\Animate 2023\zh_CN\Configuration\External Libraries\, output the dll object `DeviceInfo` I defined, and successfully print `[object Extension]`, but when I output `DeviceInfo.computeSum`, it shows undefined.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

Is that screenshot from Animate console? I don't see that.

 

It looks like DeviceInfo is registered successfully.

Try output DeviceInfo.computeSum().

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

LATEST

Also check your spelling.

It is case-sensitive when you call a function in Animate.

If in .c you named it computeSum, write computeSum in jsfl. On the other hand, computesum WON'T WORK.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines