Getting Started
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:
Environment and Tool |
Version |
Description |
---|---|---|
OS |
Windows 10/11 Professional |
Hardware requirements
|
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
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.
- 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.
The Meeting-Workspace-Plugin directory stores library files related to the cloud desktop plug-in. To integrate the cloud desktop plug-in, copy this directory to HwmSdk\sdkResources.
- Create a project.
- Open Visual Studio 2017 and choose File > New > Project from the main menu.
Figure 2 Opening a new project
- 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
- 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
- Open Visual Studio 2017 and choose File > New > Project from the main menu.
- Copy the static library files and header files to the project.
- 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
- 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
- Create a directory named SDK at the same level as the Hello_World.sln file in the Hello_World project directory.
- Modify configuration properties of the project.
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.
- Right-click the Hello_World project and choose Properties from the shortcut menu.
Figure 7 Project properties
- 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
- 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
- Choose Configuration Properties > Linker > Input, change the value of Additional Dependencies to hwm_sdk_agent.lib, and click Apply.
Figure 10 Configuring Additional Dependencies
- Choose Configuration Properties > General, change the value of Output Directory to ..\debug\win32, and click OK.
Figure 11 Configuring Output Directory
- 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.
- Right-click the Hello_World project and choose Properties from the shortcut menu.
- Add a UI resource control.
- In the resource view, open the Dialog page corresponding to the project.
Figure 13 Dialog page of the project
- Select all controls on the page and press Delete.
Figure 14 Deleting existing controls
- Add the initialization button.
- 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
- To modify the text on the button, right-click the button and choose Properties from the shortcut menu.
Figure 16 Button properties
- Change the value of Caption to Init.
Figure 17 Modifying button properties
- In the resource view, open the Dialog page corresponding to the project.
- Add a button click event.
- 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
- Double-click the Init control. The system automatically adds the OnBnClickedButton1() method to Hello_WorldDlg.cpp for the Init button.
- Add a code file.
- Add a callback processing class.
- Right-click the project and choose Add > Class from the shortcut menu.
Figure 19 Adding a class
- 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
- Right-click the project and choose Add > Class from the shortcut menu.
- Add a notification processing class and set the class name to notifyProc.
Figure 21 Adding the notifyProc class
- Add a callback processing class.
- Add the logic code.
- 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. }
To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file.
- 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.
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.
- 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. }
To save space, some of the preceding code is omitted. You need to implement the complete code based on the SDK header file.
- 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.
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.
- Include the required header files in the Hello_WorldDlg.h file.
1
#include "HwmErrorCodeDef.h"
- 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();
- 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>
- Define the callback and notification objects in the Hello_WorldDlg.cpp file.
1 2
static notifyProc *notifyObj = new notifyProc(); static callbackProc *callbackObj = new callbackProc();
- 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; }
- 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")); } }
The preceding code is the same as the project code. Do not add the code repeatedly.
- 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; }
- 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; }
The preceding code is the same as the project code. Do not add the code repeatedly.
- 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.
- Compile and debug the project.
- Right-click the project and choose Rebuild from the shortcut menu to compile the project.
Figure 22 Rebuilding files
- Observe the Output window. If the message "Rebuild All: 1 succeeded, 0 failed, 0 skipped" is displayed, the compilation is successful.
Figure 23 Result
- 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
- 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 directoryFigure 26 Copying all files in SDK\HwmSdk to the output directoryIf 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 directoryFigure 28 Copying the entire SDK\HwmSdk folder to the output directoryFigure 29 Copying HwmSdk.exe in SDK\dll\x64 to the HwmSdk folder in the output directoryWhen 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.
- Double-click Hello_World.exe.
Figure 30 Startup screen
- 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
- Right-click the project and choose Rebuild from the shortcut menu to compile the project.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot