鸿蒙ACE框架-使用JS调用C++(1)

开发 后端
文章由鸿蒙社区产出,想要了解更多内容请前往:51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com

[[397654]]

想了解更多内容,请访问:

51CTO和华为官方合作共建的鸿蒙技术社区

https://harmonyos.51cto.com

 鸿蒙ACE框架-使用JS调用C++(1)

1.下载编译烧录代码

https://blog.csdn.net/qq_33259323/article/details/116143820

2.编写测试用例

打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.h

  1. static JSIValue ToggleLed(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum); 
  1. JSI::SetModuleAPI(exports, "toggleLed", AppModule::ToggleLed); 

打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.cpp

  1. JSIValue AppModule::ToggleLed(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) 
  2.     HILOG_ERROR(HILOG_MODULE_ACE, "led button pressed."); 
  3.     printf("led button pressed\n"); 
  4.   
  5.     return JSI::CreateUndefined(); 

 

之后就进行编译烧录,C++层的就弄好了

3.编写HAP

打开C:\Users\XX\AppData\Local\Huawei\Sdk\js\2.1.1.18\api\smartVision\@system.app.d.ts添加API

static toggleLed(): void;

然后打开DEVECO在你的页面上写个按钮和加个点击事件

  1. <input class="btu" type="button" value="进入" onclick="led"></input> 

  1. import router from '@system.router'
  2. import app from '@system.app' 
  3.   
  4. export default { 
  5.     data: { 
  6.   
  7.     }, 
  8.     onInit() { 
  9.   
  10.     }, 
  11.     led: function(){ 
  12.          
  13.         app.toggleLed(); 
  14.     } 

 然后把编写好的HAP包装到3516上面

https://blog.csdn.net/qq_33259323/article/details/111307192

4.运行

参考:https://harmonyos.51cto.com/posts/3112

想了解更多内容,请访问:

51CTO和华为官方合作共建的鸿蒙技术社区

https://harmonyos.51cto.com

 

责任编辑:jianghua 来源: 鸿蒙社区
相关推荐

2010-01-28 13:35:41

调用C++函数

2010-01-20 14:35:55

C++调用

2010-01-21 11:23:58

C++函数调用

2021-10-11 11:53:07

C++接口代码

2020-11-11 12:13:59

JS

2021-08-16 15:49:31

开发框架单线程异步

2010-01-26 15:51:06

C++变量

2012-08-08 09:32:26

C++多进程并发框架

2023-01-04 15:24:46

ACE组件UI布局

2023-03-15 15:58:11

Python动态库C++

2015-04-21 13:37:44

Google开源CC++版

2012-04-28 15:28:21

JNI混合编程Java

2019-08-28 14:21:39

C++C接口代码

2020-07-31 18:33:56

C++编程语言

2010-01-26 14:10:22

Visual C++

2011-08-22 17:25:31

LuaC++函数

2010-02-01 13:25:32

Python脚本

2023-11-09 23:31:02

C++函数调用

2020-11-11 11:56:05

HarmonyOS

2010-01-20 14:25:56

函数调用
点赞
收藏

51CTO技术栈公众号