目录

native_interface.h

Overview

Provides a unified entry for the native module APIs, which are used to initialize the C API environment, obtain the API set of a native module of a specified type, and obtain the latest error information.

File to include: <arkui/native_interface.h>

Library: libace_ndk.z.so

System capability: SystemCapability.ArkUI.ArkUI.Full

Since: 12

Related module: ArkUI_NativeModule

Sample: NativeNodeInterfaceSample

Summary

[h2]Enums

Name typedef Keyword Description
ArkUI_NativeAPIVariantKind ArkUI_NativeAPIVariantKind Enumerates the types of native API collections.

[h2]Functions

Name Description
void* OH_ArkUI_QueryModuleInterfaceByName(ArkUI_NativeAPIVariantKind type, const char* structName) Initializes the C API environment and obtains the native module API collection of the specified type.
const char* OH_ArkUI_NativeModule_GetErrorMessage() Obtains the latest error message, including the error codes, API names, and error causes.

[h2]Macros

Name Description
OH_ArkUI_GetModuleInterface(nativeAPIVariantKind, structType, structPtr) Initializes the C API environment and obtains the corresponding struct pointer based on the struct type.

Enum Description

[h2]ArkUI_NativeAPIVariantKind

enum ArkUI_NativeAPIVariantKind

Description

Enumerates the types of native API collections.

Since: 12

Value Description
ARKUI_NATIVE_NODE = 0 API related to UI components. For details, see the struct definition in native_node.h.
ARKUI_NATIVE_DIALOG = 1 API related to dialog boxes. For details, see the struct definition in native_dialog.h.
ARKUI_NATIVE_GESTURE = 2 API related to gestures. For details, see the struct definition in native_gesture.h.
ARKUI_NATIVE_ANIMATE = 3 API related to animations. For details, see the struct definition in native_animate.h.
ARKUI_MULTI_THREAD_NATIVE_NODE = 4

API related to multi-threaded UI components. For details, see the struct definition in native_node.h.

Since: 22

Function Description

[h2]OH_ArkUI_QueryModuleInterfaceByName()

void* OH_ArkUI_QueryModuleInterfaceByName(ArkUI_NativeAPIVariantKind type, const char* structName)

Description

Initializes the C API environment and obtains the native module API collection of the specified type.

Since: 12

Parameters

Name Description
ArkUI_NativeAPIVariantKind type Type of the native API collection provided by ArkUI, for example, the UI component API type ARKUI_NATIVE_NODE and the gesture API type ARKUI_NATIVE_GESTURE.
const char* structName Pointer to the name of a native API struct, which can be obtained by querying the struct definition in the corresponding header file, for example, "ArkUI_NativeNodeAPI_1" in native_node.h.

Return value

Type Description
void* Pointer to the native API abstraction, which must be cast to the specific type for use.

[h2]OH_ArkUI_GetModuleInterface()

#define OH_ArkUI_GetModuleInterface(nativeAPIVariantKind, structType, structPtr)                     \
do {                                                                                                 \
        void* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(nativeAPIVariantKind, #structType); \
        if (anyNativeAPI) {                                                                          \
            structPtr = (structType*)(anyNativeAPI);                                                 \
        }                                                                                            \
    } while (0)

Description

Initializes the C API environment and obtains the corresponding struct pointer based on the struct type.

It applies to the scenario where the native API set type and the API struct type have been determined, and a specific native API struct pointer needs to be obtained to call ArkUI native C APIs. This macro function receives the enumeration parameter nativeAPIVariantKind of the ArkUI_NativeAPIVariantKind type, the struct type parameter structType, and the struct pointer variable structPtr. structPtr must match structType. This macro function calls OH_ArkUI_QueryModuleInterfaceByName to initialize the C API environment and obtain the abstract pointer of the native API, converts it to the structType* type, and assigns it to structPtr.

Since: 12

[h2]OH_ArkUI_NativeModule_GetErrorMessage()

const char* OH_ArkUI_NativeModule_GetErrorMessage()

Description

Obtains the latest error information, including the error codes, API names, and error causes. For details about the error code, see ArkUI_ErrorCode. When other APIs return an error code, the corresponding error information is saved, and the currently stored error information can be obtained through this API. The returned string is a thread-local global string created by the system, and its content must not be modified. If any editing is required, create a copy of the string content. The information returned by this API may change as versions evolve. It is used only for output to assist in analysis and troubleshooting, and must not be used as a basis for logical judgment. The returned error information does not need to be released manually.

Since: 26.0.0

Return value

Type Description
const char* Pointer to the latest error information, including the error codes, API names, and error causes.