Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Scenario 1: Initialization

Updated on 2024-07-30 GMT+08:00

Description

The initialization API can be called for SDK initialization after a third-party application starts. You only need to call this API once. You must call this API before calling other functional APIs.

Service Process

During SDK initialization, change the name of the HwmSdk.exe file in the HwmSdk folder, call the Init API, and then process the callback function OnInitResult.

  1. Change the name of the .exe file.

    Change the name of the HwmSdk.exe file in the HwmSdk folder to MySdk.exe.

  2. Call the API.

    1. Construct the HwmInitInfo data structure.
      1. Define the derived class demoNotifyProc that it inherits from the base class HwmAgentNotify, and create a derived class object.
        1
        static demoNotifyProc *notifyObj = new demoNotifyProc();
        
      1. Define the derived class demoCallbackProc that it inherits from the base class HwmAgentCallback, and create a derived class object.
        1
        static demoCallbackProc *callbackObj = new demoCallbackProc();
        
      1. Construct other variables.
    2. Call the Init API to initialize the configuration. The data in the preceding step is used as input parameters.

  3. Implement the callback function.

    Implement the OnInitResult function.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Call the initialization API and start the application.
*/
int CdemoBeforeLoginDlg::Init()
{
    // Assemble the input parameter structure.
    hwmsdkagent::HwmInitInfo initParam;
    memset(&initParam, 0, sizeof(HwmInitInfo));
 
    // (Not required for Win32) Configure the SDK path, that is, the .exe file path, for the x64 platform after renaming the .exe file.
    // Convert the SDK path into the UTF-8 format and copy it to initParam. The conversion code is omitted here.
    strcpy_s(initParam.exePath, HWM_MAX_FILE_PATH_LEN, GetHwmSdkExePath().c_str());
    // Specify the log path, convert the path into the UTF-8 format, and copy the converted path to initParam. The conversion code is omitted here.
    strcpy_s(initParam.logPath, HWM_MAX_FILE_PATH_LEN, GetLogPath().c_str());
    // Specify the data path, convert the path into the UTF-8 format, and copy the converted path to initParam. The conversion code is omitted here.
    strcpy_s(initParam.userDataPath, HWM_MAX_FILE_PATH_LEN, GetUserDataPath().c_str());
    strncpy_s(initParam.appId, GetAppId.c_str(), HWM_MAX_APPID_LEN);
    
    initParam.notify = notifyObj;
    initParam.callback = callbackObj;
    initParam.authType = hwmsdkagent::HWM_AUTH_TYPE_APPID;
    int ret = hwmsdkagent::Init(&initParam);
 
    return ret;
}
NOTE:

The value of exePath is the parent directory of the HwmSdk directory. For example, if the HwmSdk directory is E:\Hello_World\debug\win32\HwmSdk, the value of exePath is E:\Hello_World\debug\win32\.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
/**
* Initialization callback
*/
void demoCallbackProc::OnInitResult(hwmsdk::HwmErrCode ret, const char* msg, HwmSdkInfo *sdkInfo)
{
    CString codeStr;
    codeStr.Format(_T("%d"), ret);
    string msgStr = CTools::UTF82MultiByte(msg);
    string verStr = "";
    if (sdkInfo != NULL) {
        verStr = CTools::UTF82MultiByte(sdkInfo->version);
    }
    CString tips = _T("OnInitResult code:") + codeStr + _T(", msg:") + CString(msgStr.c_str()) + _T(" version:") + CString(verStr.c_str());
    AfxMessageBox(tips);
 
}

NOTE:

The sample code in the typical scenario and API reference is pseudo code and cannot be directly used.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback