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
On this page

Getting Started

Updated on 2024-12-27 GMT+08:00

This section uses SDK initialization as an example to describe how to use the Windows SDK for secondary development.

Preparations

During the development, ensure that the following environment requirements are met:

Table 1 Environment requirements

Environment and Tool

Version

Description

OS

Windows 10/11 Professional

Hardware requirements

  • CPU: i5-2400 quad-core, 3.1 GHz or above
  • Memory: 4 GB or above

Microsoft Visual Studio

Visual Studio 2017

During the installation, select Desktop development with C++, Visual C++ MFC for x86 and x64, and Windows 10 SDK (10.0.15063.0).

Requesting test resources and app IDs

-

For details, see Preparations.

SDK Integration

NOTE:

The high DPI awareness function of each monitor must be enabled for the exe program that integrates the SDK on a computer with a high DPI (zoom ratio greater than 100%). Otherwise, the image will be displayed abnormally. For example, the image is blurry, or the image is incomplete or tilted on the receiver during sharing.

For details, see Figure 12.

  1. Decompress the SDK package to the local host.

    Figure 1 Decompressing the SDK package to the local host
    Table 2 Introduction to SDK directories

    Folder

    Description

    include

    Stores the header files required for compilation.

    lib

    Contains two subfolders, win32 and x64. The two subfolders store the .lib files that the compilation of the corresponding platform depends on.

    dll

    Contains two subfolders, win32 and x64. The two subfolders store the .dll files and the executable SDK .exe files that the running of the corresponding platform depends on.

    HwmSdk

    Stores the common dependency libraries used by Win32 and x64.

    demo

    Stores demo code files and resource files.

  2. Create a project.

    1. Open Visual Studio 2017 and choose File > New > Project from the main menu.
      Figure 2 Opening a new project
    2. On the Create a new project page, choose Installed > Visual C++ from the navigation tree. Select MFC Application in the template list, set the project name to Hello_World, select E:\ from the Location drop-down list, and click OK.
      Figure 3 Creating a project
    3. On the Application Type page, set Application type to Dialog based, retain the default values for other parameters, and click Finish.
      Figure 4 Application type options

  3. Copy the static library files and header files to the project.

    1. Create a directory named SDK at the same level as the Hello_World.sln file in the Hello_World project directory.
      Figure 5 Creating the SDK directory

    2. Copy the lib and include directories in the SDK directory of the demo installation package to the Hello_World\SDK directory.
      Figure 6 Copying files

  4. Modify configuration properties of the project.

    NOTE:

    The following operations are performed based on the Debug configuration and Win32 platform. When modifying the configuration and platform, add additional include directories and dependent libraries again.

    1. Right-click the Hello_World project and choose Properties from the shortcut menu.
      Figure 7 Project properties
    2. Choose Configuration Properties > C/C++ > General, change the value of Additional Include Directories to ..\SDK\include, and click Apply.
      Figure 8 Configuring Additional Include Directories
    3. Choose Configuration Properties > Linker > General, change the value of Additional Library Directories to ..\SDK\lib\win32, and click Apply.
      Figure 9 Configuring Additional Library Directories
    4. Choose Configuration Properties > Linker > Input, change the value of Additional Dependencies to hwm_sdk_agent.lib, and click Apply.
      Figure 10 Configuring Additional Dependencies
    5. Choose Configuration Properties > General, change the value of Output Directory to ..\debug\win32, and click OK.
      Figure 11 Configuring Output Directory
    6. In the left pane of the property page, choose Configuration Properties > Manifest Tools > Input and Output, change the value of DPI Awareness to Per Monitor High DPI Aware, and click OK.
      Figure 12 Configuring the DPI awareness function

  5. Add a UI resource control.

    1. In the resource view, open the Dialog page corresponding to the project.
      Figure 13 Dialog page of the project
    2. Select all controls on the page and press Delete.
      Figure 14 Deleting existing controls
    3. Add the initialization button.
      1. Add the initialization button control. Open the toolbox page, select the button control, drag it to the dialog box, and adjust the width and height of the button.
      Figure 15 Adding the initialization button
      1. To modify the text on the button, right-click the button and choose Properties from the shortcut menu.
        Figure 16 Button properties
      2. Change the value of Caption to Init.
        Figure 17 Modifying button properties

  6. Add a button click event.

    1. Double-click the Init control. The system automatically adds the OnBnClickedButton1() method to Hello_WorldDlg.cpp for the Init button.
      Figure 18 Creating an event method for the Init button

  7. Add a code file.

    1. Add a callback processing class.
      1. Right-click the project and choose Add > Class from the shortcut menu.
        Figure 19 Adding a class
      2. In the Generic C++ class wizard dialog box, set the class name to callbackProc, retain the default values for other parameters, and click Finish.
        Figure 20 Adding the callbackProc class
    2. Add a notification processing class and set the class name to notifyProc.
      Figure 21 Adding the notifyProc class

  8. Add the logic code.

    1. Add the SDK callback class header file HwmAgentCallback.h to the callbackProc.h file, so the callbackProc class inherits the base class HwmAgentCallback. You can copy only API calling callback functions that need to be focused on in the HwmAgentCallback.h file.
       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
      26
      27
      28
      #pragma once
      #include "HwmAgentCallback.h"
       
      class callbackProc : public hwmsdkagent::HwmAgentCallback
      {
      public:
          callbackProc();
          ~callbackProc();
          /**
               * @brief [en] Callback of Init interface.
               *
               * @param [in] hwmsdk::HwmErrCode ret    [en] Return code
               * @param [in] const char* reason        [en] Fail reason
               * @attention [en] NA
               **/
          void OnInitResult(hwmsdk::HwmErrCode ret, const char* reason, HwmSdkInfo *sdkInfo);
       
          /**
           * @brief [en] Callback of Exit interface.
           *
           * @param [in] hwmsdk::HwmErrCode ret    [en] Return code
           * @param [in] const char* reason        [en] Fail reason
           * @attention [en] NA
           **/
          void OnExitResult(hwmsdk::HwmErrCode ret, const char* reason);
          
         // To save space, other callback APIs are omitted here. Copy them completely during actual operations.
      }
      
      NOTE:

      To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file.

    2. Define APIs in the callbackProc.cpp file.
       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
      26
      27
      28
      29
      30
      31
      32
      33
      34
      #include "stdafx.h"
      #include "callbackProc.h"
      
      callbackProc::callbackProc()
      {
       
      }
      callbackProc::~callbackProc()
      {
       
      }
       
      /**
      * Initialization callback
      */
      void callbackProc::OnInitResult(hwmsdk::HwmErrCode ret, const char* reason, HwmSdkInfo *sdkInfo)
      {
          CString retStr;
          retStr.Format(_T("%d"), ret);
          CString tips = _T("OnInitResult code:") + retStr;
          AfxMessageBox(tips);
      }
      
      /**
      * Exit callback */
      void callbackProc::OnExitResult(hwmsdk::HwmErrCode ret, const char* reason)
      {
          CString retStr;
          retStr.Format(_T("%d"), ret);
          CString tips = _T("OnExitResult code:") + retStr;
          AfxMessageBox(tips);
      }
      
      // To save space, some code is omitted here. In actual operations, define callback function APIs that you need to pay attention to.
      
      NOTE:

      To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file. The header files (stdafx.h or pch.h) used for precompilation in different versions may be different. If a compilation error occurs, use the local default header file.

    3. Add the SDK callback class header file HwmAgentNotify.h to the notifyProc.h file, so the callbackProc class inherits the base class HwmAgentNotify. You can copy only API calling functions that need to be focused on in the HwmAgentNotify.h file.
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      #pragma once
      #include "HwmAgentNotify.h"
       
       
      class notifyProc : public hwmsdkagent::HwmAgentNotify
      {
      public:
          notifyProc();
          ~notifyProc();
       
          /**
           * @brief [en] Notify of sdk disconnected.
           *
           * @attention [en] NA
           **/
          void OnSdkDisconnected();
      
         // To save space, other callback APIs are omitted here. Copy them completely during actual operations.
      }
      
      NOTE:

      To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file.

    4. Define APIs in the notifyProc.cpp file.
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      #include "stdafx.h"
      #include "notifyProc.h"
       
      notifyProc::notifyProc()
      {
       
      }
      notifyProc::~notifyProc()
      {
       
      }
       
      // SDK disconnection notification
      void notifyProc::OnSdkDisconnected()
      {
          CString tips = _T("OnSdkDisconnected");
          AfxMessageBox(tips);
      }
      
      // To save space, other callback APIs are omitted here. Copy them completely during actual operations.
      
      NOTE:

      To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file. The header files (stdafx.h or pch.h) used for precompilation in different versions may be different. If a compilation error occurs, use the local default header file.

    5. Include the required header files in the Hello_WorldDlg.h file.
      1
      #include "HwmErrorCodeDef.h"
      
    6. Declare functions to be used in the Hello_WorldDlg.h file.
      1
      2
      3
      4
      5
      public:
          // Initialization API
          hwmsdk::HwmErrCode Init();
          // Exit API
          static hwmsdk::HwmErrCode Exit();
      
    7. Include the required header files in the Hello_WorldDlg.cpp file.
      1
      2
      3
      4
      #include "notifyProc.h"
      #include "callBackProc.h"
      #include "HwmSdkAgent.h"
      #include <string>
      
    8. Define the callback and notification objects in the Hello_WorldDlg.cpp file.
      1
      2
      static notifyProc *notifyObj = new notifyProc();
      static callbackProc *callbackObj = new callbackProc();
      
    9. Define the initialization API in the Hello_WorldDlg.cpp file.
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      /**
      * Initialization API
      */
      hwmsdk::HwmErrCode CHello_WorldDlg::Init()
      {
          // Assemble the input parameter structure.
          hwmsdkagent::HwmInitInfo initParam;
          memset(&initParam, 0, sizeof(hwmsdkagent::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 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;
          hwmsdk::HwmErrCode ret = hwmsdkagent::Init(&initParam);
       
          return ret;
      }
      
    10. In the Hello_WorldDlg.cpp file, implement the processing of the event of clicking the Init button.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      void CHello_WorldDlg::OnBnClickedButton1()
      {
          // TODO: Add a control to notify code processing.
          hwmsdk::HwmErrCode ret = Init();
          if (hwmsdk::HWM_COMMON_SUCCESS != ret)
          {
              AfxMessageBox(_T("Init error"));
          }
      }
      
      NOTE:

      The preceding code is the same as the project code. Do not add the code repeatedly.

    11. Define the exit API in Hello_WorldDlg.cpp file.
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      /**
      * Exit API
      */
      hwmsdk::HwmErrCode CHello_WorldDlg::Exit()
      {
          hwmsdk::HwmErrCode ret = hwmsdkagent::Exit();
          if (hwmsdk::HWM_COMMON_SUCCESS != ret)
          {
              AfxMessageBox(_T("Exit error"));
          }
          return ret;
      }
      
    12. Find the InitInstance API in the Hello_World.cpp file and call the exit API when the window exits.
       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
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      // Initialize CHello_WorldApp.
       
      BOOL CHello_WorldApp::InitInstance()
      {
         // If an application running on Windows XP specifies to
         // enable the visualization mode using ComCtl32.dll version 6 or later,
         // InitCommonControlsEx() is required. Otherwise, the window cannot be created.
          INITCOMMONCONTROLSEX InitCtrls;
          InitCtrls.dwSize = sizeof(InitCtrls);
         // Set it to include all the common control classes
         // to be used in the application.
          InitCtrls.dwICC = ICC_WIN95_CLASSES;
          InitCommonControlsEx(&InitCtrls);
       
          CWinApp::InitInstance();
       
       
          AfxEnableControlContainer();
       
         // Create a shell manager to prevent the dialog box from containing
         // any shell tree view control or shell list view control.
          CShellManager *pShellManager = new CShellManager;
       
         // Activate the Windows Native visual manager to enable the theme in the MFC control.
          CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
       
         // Standard initialization
         // If these functions are not used, 
         // and you want to reduce the size of the final executable file, 
         // remove the following specific initialization routines that are not required, 
         // and change the registry key for storing settings.
         // TODO: Modify the character string as required.
          // For example, change the value to the company or organization name.
          SetRegistryKey(_T("Local applications generated by the application wizard"));
       
          CHello_WorldDlg dlg;
          m_pMainWnd = &dlg;
          INT_PTR nResponse = dlg.DoModal();
          if (nResponse == IDOK)
          {
              // TODO: Place code here 
              // to handle when to use OK to close the dialog box.
              CHello_WorldDlg::Exit();
          }
          else if (nResponse == IDCANCEL)
          {
              // TODO: Place code here 
              // to handle when to use Cancel to close the dialog box.
              CHello_WorldDlg::Exit();
       
          }
          else if (nResponse == -1)
          {
              TRACE(traceAppMsg, 0, "Warning: Creating the dialog box failed. The application will terminate unexpectedly.\n");
              TRACE(traceAppMsg, 0, "Warning: If you use the MFC control in the dialog box, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
          }
       
          // Delete the created shell manager.
          if (pShellManager != nullptr)
          {
              delete pShellManager;
          }
       
      #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
          ControlBarCleanUp();
      #endif
       
          // Because the dialog box is closed, FALSE is returned to exit the application, 
          // instead of starting the message pump of the application.
          return FALSE;
      }
      
      NOTE:

      The preceding code is the same as the project code. Do not add the code repeatedly.

  9. Compile and debug the project.

    1. Right-click the project and choose Rebuild from the shortcut menu to compile the project.
      Figure 22 Rebuilding files
    2. Observe the Output window. If the message "Rebuild All: 1 succeeded, 0 failed, 0 skipped" is displayed, the compilation is successful.
      Figure 23 Result
    3. After the compilation is successful, the generated executable program Hello_World.exe is stored in the output directory. The current output directory is ${path}\Hello_World\debug\win32.
      Figure 24 .exe file
    4. Copy the corresponding files in SDK\dll and SDK\HwmSdk to the output directory.

      If the Win32 platform is used, copy DLL files in SDK\dll\win32 to the output directory, and copy all the files in SDK\HwmSdk to the output directory.

      Figure 25 Copying DLL files in SDK\dll\win32 to the output directory

      Figure 26 Copying all files in SDK\HwmSdk to the output directory

      If the x64 platform is used, copy DLL files in SDK\dll\x64 to the output directory and the entire SDK\HwmSdk folder to the output directory, copy HwmSdk.exe in SDK\dll\x64 to the HwmSdk folder in the output directory.

      Figure 27 Copying DLL files in SDK\dll\x64 to the output directory

      Figure 28 Copying the entire SDK\HwmSdk folder to the output directory

      Figure 29 Copying HwmSdk.exe in SDK\dll\x64 to the HwmSdk folder in the output directory

      NOTE:

      When the Win32 platform is used, the directory is SDK\dll\win32. When the x64 platform is used, the directory is SDK\dll\x64. HwmSdk contains common dependency library files.

    5. Double-click Hello_World.exe.
      Figure 30 Startup screen
    6. Click Init. A dialog box is displayed indicating the initialization result. The value 0 indicates that the initialization is successful, and other values indicate that the initialization fails. After the initialization is successful, a notification dialog box is displayed.
      Figure 31 Result prompt
      Figure 32 Startup notification

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