### CDiskInfoDlg Constructor Example Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Demonstrates how to create and display an instance of the CDiskInfoDlg. The flagStarupExit parameter controls application exit behavior. ```cpp CDiskInfoDlg* pDlg = new CDiskInfoDlg(NULL, TRUE); pDlg->Create(IDD_DISKINFO_DIALOG, NULL); pDlg->ShowWindow(SW_SHOW); ``` -------------------------------- ### Minimal Initialization Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Performs a basic initialization with WMI and advanced search enabled, standard drive sorting, and no special workarounds. Useful for a quick setup. ```cpp CAtaSmart ata; ata.Init(TRUE, TRUE, NULL, FALSE, FALSE, FALSE, TRUE, FALSE); // Basic setup: WMI + advanced search, standard sorting, no special workarounds ``` -------------------------------- ### InstallEventSource Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Registers CrystalDiskInfo as an event source in Windows Event Log. This function must be called once during application setup with administrator privileges. ```APIDOC ## InstallEventSource ### Description Registers CrystalDiskInfo as an event source in Windows Event Log. ### Method ```cpp BOOL InstallEventSource() ``` ### Parameters None ### Returns - BOOL - TRUE if successful ### Details Must be called once during application setup with administrator privileges. Creates registry entries in: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\CrystalDiskInfo` ### Example ```cpp if (InstallEventSource()) { // Event source registered successfully } ``` ``` -------------------------------- ### Full Initialization Example Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Initializes the CAtaSmart object with all options enabled, including WMI, advanced disk search, workarounds, and specific display flags. Tracks if the disk list changes. ```cpp CAtaSmart ata; BOOL diskListChanged = FALSE; // Full initialization with all options enabled ata.Init( TRUE, // useWmi - use Windows Management Instrumentation TRUE, // advancedDiskSearch - enable SCSI, CSMI, Silicon Image, NVMe &diskListChanged, // track if disk list changes TRUE, // workaroundHD204UI - apply WD Green workaround TRUE, // workaroundAdataSsd - apply ADATA SSD workaround FALSE, // flagHideNoSmartDisk - show all drives TRUE, // flagSortDriveLetter - sort by drive letter (C:, D:, etc) FALSE // flagHideRAIDVolume - show RAID volumes ); if (diskListChanged) { printf("Disk configuration changed\n"); } // Access detected disks for (int i = 0; i < ata.vars.GetSize(); i++) { ATA_SMART_INFO& disk = ata.vars[i]; printf("Drive %d: %s (%s)\n", i, disk.Model, disk.SerialNumber); } ``` -------------------------------- ### InstallEventSource Function Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Registers CrystalDiskInfo as an event source in the Windows Event Log. This function must be called once during application setup with administrator privileges. ```cpp BOOL InstallEventSource() { // Implementation details omitted for brevity return TRUE; // Placeholder } ``` -------------------------------- ### Get and Set APM Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Shows how to get the current and recommended Advanced Power Management (APM) settings and how to enable or disable APM for SATA drives to manage power consumption. Values range from aggressive power saving to disabled. ```cpp // Get current APM setting BYTE currentApm = ata.GetApmValue(0); // Get recommended APM value BYTE recommendedApm = ata.GetRecommendApmValue(0); // Set APM value (1-254, where 1 = most power saving) ata.EnableApm(0, 64); // Disable APM to maximize performance ata.DisableApm(0); ``` -------------------------------- ### OnInitDialog Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Called when the dialog is first created. This method is responsible for initializing controls, loading user preferences, setting up the disk monitoring engine, and starting timers. ```APIDOC ## OnInitDialog() ### Description Called when the dialog is first created. Initializes controls, loads settings, and starts disk detection. ### Method Virtual Method Override ### Endpoint None ### Parameters None ### Request Example None ### Response #### Success Response (200) - **BOOL** - Returns TRUE if initialization was successful, FALSE otherwise. ### Typical Operations - Load user preferences from registry - Initialize CAtaSmart for disk detection - Set up custom fonts and colors - Create sub-dialogs (Graph, Health, Options) - Start auto-refresh timer - Register for device notifications (WM_DEVICECHANGE) ``` -------------------------------- ### WriteEventLog Function Example Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Demonstrates how to write a warning event to the Windows Event Log with a specific ID, type, source, and message. ```cpp WriteEventLog(1001, EVENTLOG_WARNING_TYPE, _T("CrystalDiskInfo"), _T("Drive temperature exceeded threshold")); ``` -------------------------------- ### MeasuredTimeUnit Function Signature and Example Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Performs automatic detection of the power-on time unit for all disks. Call this function to initiate the measurement process. ```cpp BOOL MeasuredTimeUnit() ``` ```cpp ata.MeasuredTimeUnit(); ``` -------------------------------- ### Get QR Code Module State C++ Function Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Gets the state (black or white) of a single module within the QR code at specified X and Y coordinates. Coordinates are 0-indexed relative to the QR code size. ```cpp bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y) ``` ```cpp for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { bool black = qrcodegen_getModule(qrcode, x, y); // Draw module } } ``` -------------------------------- ### Handle WriteEventLog Failure Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Ensures the event source is installed before attempting to write to the event log. If WriteEventLog() fails (e.g., due to access denied), it suggests falling back to other logging methods. ```cpp // Ensure event source is installed first if (!InstallEventSource()) { printf("Cannot use event logging\n"); return; } // Then write events if (!WriteEventLog(1001, EVENTLOG_WARNING_TYPE, _T("CrystalDiskInfo"), _T("Temperature warning"))) { // Fall back to file logging or other method printf("Could not write to event log\n"); } ``` -------------------------------- ### Embedding CDiskInfoDlg in an MFC Application Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Example of how to create and display the CDiskInfoDlg within an existing MFC application's main dialog or view. Ensure OnInitDialog is used for initialization. ```cpp // In application main dialog or view class CMainWindow : public CDialogEx { private: CDiskInfoDlg m_DiskInfo; BOOL OnInitDialog() { CDialogEx::OnInitDialog(); // Create and initialize disk info dialog m_DiskInfo.Create(IDD_DISKINFO_DIALOG, this); m_DiskInfo.ShowWindow(SW_SHOW); return TRUE; } }; ``` -------------------------------- ### Get and Set AAM Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Demonstrates how to retrieve the current and recommended Automatic Acoustic Management (AAM) values and how to enable or disable AAM for a drive. AAM controls drive noise at the expense of performance. ```cpp // Get current AAM setting BYTE currentAam = ata.GetAamValue(0); // Get recommended AAM value (vendor-specific) BYTE recommendedAam = ata.GetRecommendAamValue(0); // Set AAM value (128-254, where 254 = most quiet) ata.EnableAam(0, 200); // Disable AAM to restore performance ata.DisableAam(0); ``` -------------------------------- ### Iterating Through Disk SMART Information Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Accesses and iterates through the 'vars' array, which contains ATA_SMART_INFO structures for each disk. This example shows how to retrieve the model and disk status for each disk. ```cpp for (int i = 0; i < ata.vars.GetSize(); i++) { CString model = ata.vars[i].Model; int status = ata.vars[i].DiskStatus; } ``` -------------------------------- ### UpdateSmartInfo Method Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Updates SMART attribute data for the disk at the specified index. This should be called periodically to get the latest SMART status. ```APIDOC ## UpdateSmartInfo ### Description Updates SMART attribute data for the disk at the specified index. ### Method DWORD UpdateSmartInfo(DWORD index) ### Parameters #### Path Parameters - **index** (DWORD) - Required - Zero-based disk index (0 to MAX_DISK-1) ### Returns DWORD - status code (0 = success) ### Example ```cpp ata.UpdateSmartInfo(0); // Update first disk ``` ``` -------------------------------- ### Get Automatic Acoustic Management (AAM) Value Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Retrieves the AAM value for a disk. Returns 0 if the feature is not supported. ```cpp BYTE aamValue = ata.GetAamValue(0); ``` -------------------------------- ### Get QR Code Size C++ Function Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Gets the dimension (size) of an encoded QR code. The size is calculated based on the QR code version. ```cpp int qrcodegen_getSize(const uint8_t qrcode[]) ``` ```cpp int size = qrcodegen_getSize(qrcode); // Returns 21 for v1, 25 for v2, etc. ``` -------------------------------- ### Basic Disk Monitoring with CAtaSmart Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/INDEX.md This snippet demonstrates how to initialize the CAtaSmart engine, iterate through detected disks, read basic information and SMART attributes, update disk data, and control power management features. ```cpp // 1. Create and initialize SMART engine CAtaSmart ata; ata.Init(TRUE, TRUE, NULL, FALSE, FALSE, FALSE, TRUE, FALSE); // 2. Access detected disks for (int i = 0; i < ata.vars.GetSize(); i++) { ATA_SMART_INFO& disk = ata.vars[i]; // Read basic info CString model = disk.Model; int status = disk.DiskStatus; // DISK_STATUS_GOOD, etc. // Read SMART attributes for (int j = 0; j < disk.AttributeCount; j++) { SMART_ATTRIBUTE& attr = disk.Attribute[j]; BYTE id = attr.Id; BYTE current = attr.CurrentValue; } } // 3. Update SMART data ata.UpdateSmartInfo(0); // Update disk 0 ata.UpdateIdInfo(0); // Update device info // 4. Control power management (if supported) if (ata.vars[0].IsAamSupported) { ata.EnableAam(0, 200); // Enable acoustic management } ``` -------------------------------- ### Server/Monitoring Application Initialization Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Provides an initialization pattern suitable for server or monitoring applications. It enables all detection methods, ensures all drives are shown, and activates workarounds for broader compatibility. ```cpp CAtaSmart ata; ata.Init(TRUE, TRUE, NULL, TRUE, TRUE, FALSE, FALSE, FALSE); // All detection methods, show all drives, workarounds enabled ``` -------------------------------- ### CAtaSmart::Init Method Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md The primary initialization method for the CrystalDiskInfo disk detection system. This method configures various aspects of disk detection, including WMI usage, advanced search methods, drive sorting, and specific workarounds for certain drive models. ```APIDOC ## CAtaSmart::Init Method ### Description Initializes the CrystalDiskInfo disk detection system with a variety of configurable options. ### Method ```cpp VOID Init(BOOL useWmi, BOOL advancedDiskSearch, PBOOL flagChangeDisk, BOOL workaroundHD204UI, BOOL workaroundAdataSsd, BOOL flagHideNoSmartDisk, BOOL flagSortDriveLetter, BOOL flagHideRAIDVolume) ``` ### Parameters #### Initialization Options - **useWmi** (BOOL) - Enable Windows Management Instrumentation (WMI) for disk queries. WMI provides access to disk model, serial number, and capacity without low-level I/O. Recommended: TRUE - **advancedDiskSearch** (BOOL) - Enable advanced disk detection methods beyond standard PhysicalDrive enumeration. Includes: SCSI miniport, CSMI (Common Storage Management Interface), Silicon Image controllers, and special USB bridge support. Recommended: TRUE for complete drive detection - **workaroundHD204UI** (BOOL) - Apply workaround for Western Digital Green drive HD204UI which has a firmware bug in sector size reporting. Recommended: TRUE if WD Green drives expected - **workaroundAdataSsd** (BOOL) - Apply workaround for ADATA SSD firmware compatibility issues. Improves SMART attribute interpretation for certain ADATA drives. Recommended: TRUE for ADATA SSD support - **flagHideNoSmartDisk** (BOOL) - Hide disks that do not support SMART from the main disk list. Useful for UI where you want to show only SMART-capable drives. Recommended: FALSE to show all drives - **flagSortDriveLetter** (BOOL) - Sort detected disks by Windows drive letter (C:, D:, etc.) rather than physical drive ID. Recommended: TRUE for more intuitive drive ordering - **flagHideRAIDVolume** (BOOL) - Hide RAID virtual volumes and only show physical drives in the detection results. Useful when monitoring individual drives in RAID arrays. Recommended: varies by use case #### Output Parameter - **flagChangeDisk** (PBOOL) - Pointer to BOOL that will be set to TRUE if the disk list changes during initialization. Can be NULL if change detection not needed. Used for UI updates. ### Initialization Sequence 1. WMI Initialization (if useWmi=TRUE) 2. Standard PhysicalDrive Enumeration 3. Advanced Detection (if advancedDiskSearch=TRUE) 4. Drive Sorting (based on flagSortDriveLetter) 5. List Filtering (based on flagHideNoSmartDisk and flagHideRAIDVolume) 6. Workaround Application (for HD204UI and ADATA SSDs) ### Detection Methods Priority 1. PhysicalDrive Interface 2. SCSI Miniport 3. ATA Pass-Through 4. IDE Pass-Through 5. SAT (SCSI-ATA Translation) 6. CSMI 7. WMI 8. NVMe Storage Query ### Search Limits - MAX_SEARCH_PHYSICAL_DRIVE: 56 - MAX_SEARCH_SCSI_PORT: 16 - MAX_SEARCH_SCSI_TARGET_ID: 8 - MAX_DISK: 80 - MAX_ATTRIBUTE: 30 ### Return Value Returns void. Check `flagChangeDisk` pointer for results. Disk data populated in `vars` array. ``` -------------------------------- ### Initialize CAtaSmart Instance Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Creates and initializes a new instance of the CAtaSmart class. Use this to begin disk detection. ```cpp CAtaSmart ata; BOOL changed = FALSE; ata.Init(TRUE, TRUE, &changed, FALSE, FALSE, FALSE, TRUE, FALSE); ``` -------------------------------- ### Init Method Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Initializes the disk detection engine and scans for connected drives. This method must be called before other methods that access disk information. ```APIDOC ## Init ### Description Initializes the disk detection engine and scans for connected drives. ### Method VOID Init(BOOL useWmi, BOOL advancedDiskSearch, PBOOL flagChangeDisk, BOOL workaroundHD204UI, BOOL workaroundAdataSsd, BOOL flagHideNoSmartDisk, BOOL flagSortDriveLetter, BOOL flagHideRAIDVolume) ### Parameters #### Path Parameters - **useWmi** (BOOL) - Required - Enable WMI-based disk queries - **advancedDiskSearch** (BOOL) - Required - Enable advanced disk search methods - **flagChangeDisk** (PBOOL) - Required - Pointer to flag set when disk list changes - **workaroundHD204UI** (BOOL) - Required - Apply workaround for WD Green HD204UI - **workaroundAdataSsd** (BOOL) - Required - Apply workaround for ADATA SSDs - **flagHideNoSmartDisk** (BOOL) - Required - Hide disks that don't support SMART - **flagSortDriveLetter** (BOOL) - Required - Sort disks by drive letter - **flagHideRAIDVolume** (BOOL) - Required - Hide RAID volume information ### Returns void ### Example ```cpp CAtaSmart ata; BOOL changed = FALSE; ata.Init(TRUE, TRUE, &changed, FALSE, FALSE, FALSE, TRUE, FALSE); ``` ``` -------------------------------- ### GetApmValue Function Signature Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Gets the Advanced Power Management (APM) value for a specific disk. The index parameter specifies the disk to query. ```cpp BYTE GetApmValue(DWORD index) ``` -------------------------------- ### Handling BOOL Return Values for Device Info and Settings Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Shows how to interpret BOOL return values from functions like UpdateIdInfo, EnableAam, and EnableApm. TRUE indicates success, FALSE indicates failure. ```cpp if (ata.UpdateIdInfo(0)) { CString model = ata.vars[0].Model; // Safe to use } else { // Failed to get device info // Disk may not support IDENTIFY command } ``` -------------------------------- ### qrcodegen_getModule Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Gets the state of a single module (pixel) within the QR code. This function allows checking if a specific module at given coordinates is black or white. ```APIDOC ## qrcodegen_getModule ### Description Gets the state of a single module (pixel) within the QR code. This function allows checking if a specific module at given coordinates is black or white. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **qrcode** (const uint8_t[]) - Required - QR code array - **x** (int) - Required - X coordinate (0 to size-1) - **y** (int) - Required - Y coordinate (0 to size-1) ### Response #### Success Response (200) - **bool** (bool) - TRUE if module is black (1), FALSE if white (0) ### Response Example ```cpp for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { bool black = qrcodegen_getModule(qrcode, x, y); // Draw module } } ``` ``` -------------------------------- ### Initialize CAtaSmart for Desktop Application Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Initializes CAtaSmart with standard settings suitable for a desktop application, enabling change tracking for UI updates. ```cpp CAtaSmart ata; BOOL changed = FALSE; ata.Init(TRUE, TRUE, &changed, FALSE, FALSE, FALSE, TRUE, FALSE); // Standard settings, track changes for UI updates ``` -------------------------------- ### Global Application Instance Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Provides access to the main application object, which holds application-wide configuration such as file paths and theme directories. ```cpp extern CDiskInfoApp theApp; ``` -------------------------------- ### Working with Power Management (AAM/APM) Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/types.md Checks for and enables Acoustic Management (AAM) and Advanced Power Management (APM) if supported by the disk, using recommended values. ```cpp ATA_SMART_INFO& info = ata.vars[0]; if (info.IsAamSupported) { BYTE current = ata.GetAamValue(0); BYTE recommended = ata.GetRecommendAamValue(0); ata.EnableAam(0, recommended); } if (info.IsApmSupported) { BYTE current = ata.GetApmValue(0); BYTE recommended = ata.GetRecommendApmValue(0); ata.EnableApm(0, recommended); } ``` -------------------------------- ### Get PCIe Slot Speed Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Detects the PCIe slot speed and width for a specified drive. Queries device properties to determine PCIe specification version and lane width. ```cpp SlotMaxCurrSpeed GetPCIeSlotSpeed(const INT physicalDriveId, const BOOL IsKernelVerEqualOrOver6) ``` ```cpp SlotMaxCurrSpeed speeds = GetPCIeSlotSpeed(0, TRUE); int maxGen = speeds.Maximum.SpecVersion; // 3 = PCIe 3.0 int maxLanes = speeds.Maximum.LinkWidth; // 4 = x4 int currGen = speeds.Current.SpecVersion; int currLanes = speeds.Current.LinkWidth; ``` -------------------------------- ### Diagnostic Initialization Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Configures CAtaSmart for extended diagnostics, enabling advanced search, hiding non-SMART drives, and tracking configuration changes. Includes specific workarounds. ```cpp CAtaSmart ata; BOOL changed = FALSE; ata.Init(FALSE, TRUE, &changed, TRUE, TRUE, TRUE, FALSE, TRUE); // Extended diagnostics: advanced search, hide non-SMART, track changes ``` -------------------------------- ### CAtaSmart::Init Method Signature Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md The primary initialization method for the CrystalDiskInfo disk detection system. It accepts several boolean flags to customize disk detection and display behavior. ```cpp VOID Init(BOOL useWmi, BOOL advancedDiskSearch, PBOOL flagChangeDisk, BOOL workaroundHD204UI, BOOL workaroundAdataSsd, BOOL flagHideNoSmartDisk, BOOL flagSortDriveLetter, BOOL flagHideRAIDVolume) ``` -------------------------------- ### Safe Disk Info Pattern Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Safely retrieves device identification information. It checks for errors during retrieval and flags potentially unreliable data. Use to get model and serial number. ```cpp ATA_SMART_INFO& disk = ata.vars[diskIndex]; // Get device identification if (!ata.UpdateIdInfo(diskIndex)) { printf("Cannot get device info\n"); // Use defaults disk.Model = _T("Unknown"); disk.SerialNumber = _T("Unknown"); return FALSE; } if (disk.IsIdInfoIncorrect) { printf("Device info may be unreliable\n"); // Still usable, but take with caution } return TRUE; ``` -------------------------------- ### Initialize CAtaSmart for Minimal/Embedded Use Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Initializes CAtaSmart with minimal settings for embedded systems or scenarios requiring low resource usage, focusing only on the PhysicalDrive interface. ```cpp CAtaSmart ata; ata.Init(FALSE, FALSE, NULL, FALSE, FALSE, FALSE, FALSE, FALSE); // PhysicalDrive interface only, minimal resource usage ``` -------------------------------- ### Handle InstallEventSource Failure Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Checks if InstallEventSource() fails, which typically indicates insufficient privileges. If it fails, event logging is disabled, and a warning is printed. ```cpp if (!InstallEventSource()) { // Likely no admin privileges // Proceed without event logging printf("Warning: Could not register event source\n"); } ``` -------------------------------- ### Checking for Administrator Privileges Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Demonstrates how to check if the application is running with administrator privileges, which is often required for hardware access. Requires including . ```cpp // Check if running as administrator BOOL isAdmin = IsUserAnAdmin(); // Requires if (!isAdmin) { printf("This application requires administrator privileges\n"); // Restart with admin privileges } ``` -------------------------------- ### CAtaSmart Constructor Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Initializes a new instance of the CAtaSmart class. This is the entry point for using the class. ```APIDOC ## CAtaSmart Constructor ### Description Initializes a new instance of the CAtaSmart class. ### Method Constructor ### Parameters None ### Example ```cpp CAtaSmart ata; ``` ``` -------------------------------- ### Initialize CAtaSmart for Advanced RAID/Enterprise Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Initializes CAtaSmart with advanced settings for RAID and enterprise environments, enabling full detection without hiding RAID volumes. ```cpp CAtaSmart ata; ata.Init(TRUE, TRUE, NULL, TRUE, TRUE, FALSE, FALSE, TRUE); // Full detection including RAID, no RAID volume hiding ``` -------------------------------- ### Shizuku Build Window Size Constants Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Defines window dimensions and offsets specific to Shizuku builds, accommodating an anime-themed interface. ```cpp static const int SIZE_X = 1000; // Width static const int SIZE_SMART_X = 1000; static const int SIZE_Y = 288; static const int SIZE_SMART_Y = 640; static const int SIZE_MIN_Y = 500; static const int SIZE_MAX_Y = 1000; static const int OFFSET_X = 328; // Image offset static const int DRIVE_MENU_SIZE = 84; static const int IMAGE_ALPHA = 192; // Image transparency static const int TEXT_ALPHA = 255; // Text transparency static const int LIST_CTL_ALPHA = 192; // List control transparency ``` -------------------------------- ### CDiskInfoDlg Constructor Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Creates a new instance of the disk information dialog. It takes a parent window pointer and a flag to determine if the application should exit when the dialog closes. ```APIDOC ## CDiskInfoDlg(CWnd* pParent /*=NULL*/, BOOL flagStarupExit) ### Description Creates a new instance of the disk information dialog. It takes a parent window pointer and a flag to determine if the application should exit when the dialog closes. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **pParent** (CWnd*) - Parent window (typically NULL for main window) - **flagStarupExit** (BOOL) - If TRUE, application exits when dialog closes ### Request Example ```cpp CDiskInfoDlg* pDlg = new CDiskInfoDlg(NULL, TRUE); pDlg->Create(IDD_DISKINFO_DIALOG, NULL); pDlg->ShowWindow(SW_SHOW); ``` ### Response #### Success Response (200) None (Constructor) #### Response Example None ``` -------------------------------- ### Handling DWORD Return Values for SMART Updates Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Demonstrates how to check the DWORD return value from UpdateSmartInfo to determine success or failure. Non-zero values indicate specific error codes. ```cpp DWORD result = ata.UpdateSmartInfo(0); if (result == 0) { // Success } else { // Handle error based on code printf("SMART update failed: error code %d\n", result); } ``` -------------------------------- ### Default Window Size Constants Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Defines the default dimensions for the application window and its components when not using Shizuku builds. ```cpp static const int SIZE_X = 672; // Width static const int SIZE_SMART_X = 672; // SMART table width static const int SIZE_Y = 260; // Height static const int SIZE_SMART_Y = 640; // SMART table height static const int SIZE_MIN_Y = 260; // Minimum height static const int SIZE_MAX_Y = 1000; // Maximum height static const int OFFSET_X = 0; // Horizontal offset static const int DRIVE_MENU_SIZE = 84; // Drive selection menu height ``` -------------------------------- ### Accessing SMART Disk Information Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Illustrates how to iterate through the detected disks using the m_Ata.vars member to access individual ATA_SMART_INFO structures. ```cpp for (int i = 0; i < m_Ata.vars.GetSize(); i++) { ATA_SMART_INFO& disk = m_Ata.vars[i]; // Use disk information } ``` -------------------------------- ### Accessing Disk SMART Data Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/types.md Initializes the CAtaSmart object and iterates through disk variables to access SMART attributes like model, serial, temperature, and health status. ```cpp CAtaSmart ata; ata.Init(TRUE, TRUE, NULL, FALSE, FALSE, FALSE, TRUE, FALSE); for (int i = 0; i < ata.vars.GetSize(); i++) { ATA_SMART_INFO& info = ata.vars[i]; CString model = info.Model; CString serial = info.SerialNumber; int temp = info.Temperature; int health = info.DiskStatus; // DISK_STATUS_GOOD, etc. // Access SMART attributes for (int j = 0; j < info.AttributeCount; j++) { SMART_ATTRIBUTE& attr = info.Attribute[j]; BYTE id = attr.Id; BYTE current = attr.CurrentValue; BYTE raw[6]; memcpy(raw, attr.RawValue, 6); } } ``` -------------------------------- ### Detecting SMART Data Availability Issues Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Provides conditional checks to diagnose why SMART data might not be available, covering scenarios like unsupported drives, disabled features, or data corruption. ```cpp if (!disk.IsSmartSupported) { // SMART physically not supported } else if (!disk.IsSmartEnabled) { // SMART is disabled - may be enableable } else if (!disk.IsSmartCorrect) { // SMART read succeeded but data is corrupt } else if (disk.Attribute[0].Id == 0) { // No SMART attributes available } ``` -------------------------------- ### Accessing Detected Disks Information Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Iterates through the detected disks to retrieve and print SMART information such as model, status, temperature, and power-on hours. Requires a pointer to a CDiskInfoDlg instance. ```cpp // From main dialog or parent window CDiskInfoDlg* pDlg = /* get dialog pointer */; // Iterate detected disks for (int i = 0; i < pDlg->m_Ata.vars.GetSize(); i++) { ATA_SMART_INFO& disk = pDlg->m_Ata.vars[i]; printf("Disk %d: %s\n", i, disk.Model); printf(" Status: %d\n", disk.DiskStatus); printf(" Temperature: %d°C\n", disk.Temperature); printf(" Power-on: %d hours\n", disk.MeasuredPowerOnHours); } ``` -------------------------------- ### Safe Control Pattern (AAM) Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Safely enables the Acoustic Management (AAM) feature on a disk. It first checks for support and then attempts to enable it, handling potential command failures. Use when needing to control drive acoustics. ```cpp // Check if feature is supported before using if (!disk.IsAamSupported) { printf("AAM not supported on this drive\n"); return FALSE; } // Try operation if (!ata.EnableAam(diskIndex, 200)) { printf("Failed to enable AAM\n"); // Feature supported but command failed // Possibly disabled in firmware return FALSE; } printf("AAM enabled successfully\n"); return TRUE; ``` -------------------------------- ### Fallback for Unknown Interface Type Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Handles cases where the drive's interface type is unknown. It falls back to generic SATA handling and assumes the drive is an HDD. ```cpp if (disk.InterfaceType == INTERFACE_TYPE_UNKNOWN) { printf("Unknown interface type - automatic detection failed\n"); // Fall back to generic HDD handling disk.InterfaceType = INTERFACE_TYPE_SATA; disk.IsSsd = FALSE; } ``` -------------------------------- ### Set Device Timeout on Open Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Sets a timeout for I/O operations when opening a device handle. Use this when dealing with potentially unresponsive drives to prevent application hangs. ```cpp // Set timeout on open HANDLE hDevice = CreateFile(_T("\\.\\PhysicalDrive0"), ...); if (hDevice != INVALID_HANDLE_VALUE) { // Use with timeout-aware I/O // Or set device properties for faster timeout } ``` -------------------------------- ### Disk Selection Handler Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Called when the user selects a different disk from the list. This handler loads SMART attributes, updates charts, and refreshes status information for the selected disk. ```cpp void OnSelchangeDiskListCombo() ``` -------------------------------- ### Convert NVMe Temperature Sensor to ATA SMART Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Maps NVMe temperature sensor readings (1-8) to ATA SMART attributes for temperature monitoring. ```cpp void NVMeTemperatureSensorSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted) ``` -------------------------------- ### Enable ATA Pass-Through Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Configures the CAtaSmart library to use the newer IOCTL_ATA_PASS_THROUGH method for SMART commands, which offers better compatibility with USB bridges and supports 48-bit LBA. It can be disabled to fall back to legacy methods if issues arise. ```cpp // Enable ATA pass-through for SMART commands // (uses newer IOCTL_ATA_PASS_THROUGH instead of legacy I/O control) ata.SetAtaPassThroughSmart(TRUE); // Disable to use legacy methods if problems occur ata.SetAtaPassThroughSmart(FALSE); ``` -------------------------------- ### Interpreting Disk Status Enum Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Shows how to use a switch statement to interpret the DISK_STATUS enum, which indicates the health of the drive. ```cpp switch (disk.DiskStatus) { case DISK_STATUS_GOOD: printf("Drive is healthy\n"); break; case DISK_STATUS_CAUTION: printf("Drive shows signs of wear - monitor temperature and attributes\n"); break; case DISK_STATUS_BAD: printf("CRITICAL: Disk failure imminent - backup data immediately\n"); break; case DISK_STATUS_UNKNOWN: printf("Cannot determine drive status\n"); break; } ``` -------------------------------- ### Temperature Unit Conversion Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/configuration.md Illustrates how to access the detected temperature unit type, perform auto-detection, and convert raw temperature values to hours using the `GetPowerOnHours` function. This is crucial for interpreting temperature readings correctly. ```cpp // After Init(), check detected unit type DWORD unitType = ata.vars[0].DetectedTimeUnitType; // POWER_ON_HOURS_UNIT // Perform auto-detection/measurement ata.MeasuredTimeUnit(); DWORD measuredType = ata.vars[0].MeasuredTimeUnitType; // Convert raw value to hours INT powerOnHours = ata.GetPowerOnHours( ata.vars[0].PowerOnRawValue, ata.vars[0].MeasuredTimeUnitType ); ``` -------------------------------- ### Timer Handler Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Handles periodic timer events for refreshing disk data and updating the system tray icon. Configure timer events for auto-refresh, manual refresh, and auto-detect. ```cpp void OnTimer(UINT_PTR nIDEvent) ``` -------------------------------- ### Refreshing SMART Data and Updating Display Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Manually updates SMART information for all detected disks and then refreshes the dialog's display. Use UpdateSmartInfo for individual disks and UpdateData/Invalidate for UI updates. ```cpp // Manual refresh for (int i = 0; i < pDlg->m_Ata.vars.GetSize(); i++) { pDlg->m_Ata.UpdateSmartInfo(i); } // Update display pDlg->UpdateData(FALSE); // MFC DDX update pDlg->Invalidate(); // Redraw window ``` -------------------------------- ### GetRecommendAamValue Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Retrieves the recommended Automatic Acoustic Management (AAM) value for a specified disk. Returns 0 if the value is not supported. ```APIDOC ## GetRecommendAamValue ### Description Gets the recommended Automatic Acoustic Management value for the disk. ### Method Not specified (likely a function call in a C++ API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **index** (DWORD) - Required - Zero-based disk index ### Returns - **BYTE** - Recommended AAM value, or 0 if not supported ``` -------------------------------- ### EnableAam Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Enables Automatic Acoustic Management (AAM) for a disk with a specified parameter. The AAM parameter value should be between 128 and 254. ```APIDOC ## EnableAam ### Description Enables Automatic Acoustic Management with the specified parameter. ### Method Not specified (likely a function call in a C++ API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **index** (DWORD) - Required - Zero-based disk index - **param** (BYTE) - Required - AAM parameter value (128-254) ### Returns - **BOOL** - TRUE if successful ``` -------------------------------- ### GetRecommendApmValue Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Retrieves the recommended Advanced Power Management (APM) value for a specified disk. Returns 0 if the value is not supported. ```APIDOC ## GetRecommendApmValue ### Description Gets the recommended Advanced Power Management value for the disk. ### Method Not specified (likely a function call in a C++ API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **index** (DWORD) - Required - Zero-based disk index ### Returns - **BYTE** - Recommended APM value, or 0 if not supported ``` -------------------------------- ### EnableApm Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Enables Advanced Power Management (APM) for a disk with a specified parameter. The APM parameter value should be between 1 and 254. ```APIDOC ## EnableApm ### Description Enables Advanced Power Management with the specified parameter. ### Method Not specified (likely a function call in a C++ API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **index** (DWORD) - Required - Zero-based disk index - **param** (BYTE) - Required - APM parameter value (1-254) ### Returns - **BOOL** - TRUE if successful ``` -------------------------------- ### UninstallEventSource Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Unregisters CrystalDiskInfo from Windows Event Log. This function requires administrator privileges. ```APIDOC ## UninstallEventSource ### Description Unregisters CrystalDiskInfo from Windows Event Log. ### Method ```cpp BOOL UninstallEventSource() ``` ### Parameters None ### Returns - BOOL - TRUE if successful ### Details Removes registry entries for the event source. Requires administrator privileges. ### Example ```cpp if (UninstallEventSource()) { // Event source unregistered } ``` ``` -------------------------------- ### MeasuredTimeUnit Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Initiates automatic detection of the power-on time unit for all disks. This operation is performed without any parameters. ```APIDOC ## MeasuredTimeUnit ### Description Performs automatic detection of the power-on time unit for all disks. ### Method Not specified (likely a function call in a C++ API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Returns - **BOOL** - TRUE if measurement was performed ### Example ```cpp ata.MeasuredTimeUnit(); ``` ``` -------------------------------- ### NVMe Interpreter Functions Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Functions for converting NVMe SMART data to ATA SMART format for unified presentation. ```APIDOC ## NVMeSmartToATASmart ### Description Converts raw NVMe SMART/Health Information Log Page (Log Page 02h) data to ATA SMART attribute format. ### Method `void NVMeSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **NVMeSmartBuf** (UCHAR*) - Pointer to 512-byte NVMe SMART log page data - **ATASmartBufUncasted** (void*) - Pointer to 512-byte ATA SMART data buffer (output) ### Returns void ### Details Maps NVMe SMART fields to ATA SMART attributes: - NVMe Critical Composite Temperature → Attribute 194 (Temperature) - NVMe Available Spare → Attribute 241 (Total NAND writes) - NVMe Data Units Written → Attribute 241 (SSD write count) - NVMe Controller Busy Time → Attribute 226 (Workload) ### Request Example ```cpp UCHAR nvmeSmartData[512]; BYTE ataSmartData[512]; NVMeSmartToATASmart(nvmeSmartData, ataSmartData); ``` ## NVMeCompositeTemperatureSmartToATASmart ### Description Converts NVMe SMART composite temperature to ATA SMART attribute 194. ### Method `void NVMeCompositeTemperatureSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **NVMeSmartBuf** (UCHAR*) - Pointer to NVMe SMART log page - **ATASmartBufUncasted** (void*) - Pointer to ATA SMART data buffer (output) ### Returns void ### Details Extracts and converts only the composite temperature field from NVMe SMART data. ## NVMeTemperatureSensorSmartToATASmart ### Description Converts NVMe temperature sensor readings to ATA SMART attributes. ### Method `void NVMeTemperatureSensorSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **NVMeSmartBuf** (UCHAR*) - Pointer to NVMe SMART log page - **ATASmartBufUncasted** (void*) - Pointer to ATA SMART data buffer (output) ### Returns void ### Details Maps NVMe temperature sensor readings 1-8 to ATA attributes for temperature monitoring. ## NVMeThermalManagementTemperatureSmartToATASmart ### Description Converts NVMe thermal management temperature data to ATA SMART format. ### Method `void NVMeThermalManagementTemperatureSmartToATASmart(UCHAR* NVMeSmartBuf, void* ATASmartBufUncasted)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **NVMeSmartBuf** (UCHAR*) - Pointer to NVMe SMART log page - **ATASmartBufUncasted** (void*) - Pointer to ATA SMART data buffer (output) ### Returns void ### Details Extracts thermal management threshold and current temperature from NVMe SMART data. ``` -------------------------------- ### Handle NVMe SMART Data Unavailable Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Checks if NVMe SMART data is unavailable (e.g., zero attributes or temperature). It allows reading composite temperature from the TemperatureNVMe array if available. ```cpp if (disk.IsNVMe && disk.AttributeCount == 0) { printf("NVMe SMART data unavailable\n"); // Still can read from TemperatureNVMe[] array int temp = disk.TemperatureNVMe[0]; if (temp > 0) { printf("Composite temperature: %d C\n", temp); } } ``` -------------------------------- ### UninstallEventSource Function Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/HelperFunctions.md Unregisters CrystalDiskInfo from the Windows Event Log by removing associated registry entries. Requires administrator privileges. ```cpp BOOL UninstallEventSource() { // Implementation details omitted for brevity return TRUE; // Placeholder } ``` -------------------------------- ### EnableApm Function Signature Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Enables Advanced Power Management (APM) for a disk with a specified parameter. The index identifies the disk, and param sets the APM level. ```cpp BOOL EnableApm(DWORD index, BYTE param) ``` -------------------------------- ### Checking Data Validation Flags in ATA_SMART_INFO Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/errors.md Illustrates how to use boolean status flags within the ATA_SMART_INFO structure to validate the integrity and availability of SMART data. ```cpp ATA_SMART_INFO& disk = ata.vars[0]; if (!disk.IsSmartSupported) { printf("SMART not supported\n"); } else if (!disk.IsSmartEnabled) { printf("SMART disabled on drive\n"); } else if (!disk.IsSmartCorrect) { printf("SMART data corrupt or unreadable\n"); } else { // Safe to use SMART data int temp = disk.Temperature; int status = disk.DiskStatus; } ``` -------------------------------- ### Device Change Handler Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Handles WM_DEVICECHANGE messages for detecting USB drive hot-plugging. Use this to re-scan the disk list when devices are connected or removed. ```cpp LRESULT OnDeviceChange(WPARAM wParam, LPARAM lParam) ``` -------------------------------- ### EnableAam Function Signature Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Enables Automatic Acoustic Management (AAM) for a disk with a specified parameter. The index identifies the disk, and param sets the AAM level. ```cpp BOOL EnableAam(DWORD index, BYTE param) ``` -------------------------------- ### Message Map for CDiskInfoDlg Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/DiskInfoDlg.md Defines the message handlers for CDiskInfoDlg, including WM_DEVICECHANGE, WM_TIMER, and selection change events for the disk combo box. This map is essential for the dialog's event-driven behavior. ```cpp BEGIN_MESSAGE_MAP(CDiskInfoDlg, CMainDialogFx) ON_WM_INITDIALOG() ON_WM_DEVICECHANGE() ON_WM_TIMER() ON_WM_SIZE() ON_WM_CLOSE() ON_CBN_SELCHANGE(IDC_DISK_COMBO, OnSelchangeDiskListCombo) ON_COMMAND(IDM_GRAPH, OnGraphDialog) ON_COMMAND(IDM_HEALTH, OnHealthDialog) ON_COMMAND(IDM_OPTION, OnOptionDialog) ON_COMMAND(IDM_SETTING, OnSettingDialog) // ... additional message handlers END_MESSAGE_MAP() ``` -------------------------------- ### UpdateIdInfo Method Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/api-reference/CAtaSmart.md Updates device identification information such as model, serial number, and firmware version for the disk at the specified index. ```APIDOC ## UpdateIdInfo ### Description Updates device identification information (model, serial, firmware) for the disk. ### Method BOOL UpdateIdInfo(DWORD index) ### Parameters #### Path Parameters - **index** (DWORD) - Required - Zero-based disk index ### Returns BOOL - TRUE if successful ### Example ```cpp if (ata.UpdateIdInfo(0)) { CString model = ata.vars[0].Model; CString serial = ata.vars[0].SerialNumber; } ``` ``` -------------------------------- ### EXTERNAL_DISK_INFO Structure Source: https://github.com/hiyohiyo/crystaldiskinfo/blob/master/_autodocs/types.md Represents information about external USB drives or enclosures, including enclosure model and USB vendor/product IDs. ```cpp struct EXTERNAL_DISK_INFO { CString Enclosure; DWORD UsbVendorId; DWORD UsbProductId; }; ```