次の方法で共有


WMI クラスの例

次の例は、シリアル ポート ドライバーのスキーマからのクラス定義を示しています。 これらの例に示す guid 値はプレースホルダーであることに注意してください。 各クラス定義には、(Microsoft Windows SDK に含まれている) guidgen.exe または uuidgen.exe によって生成される一意の GUID が必要です。

// Standard class for reporting serial port information
// Class qualifiers 
[WMI, guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
Dynamic, Provider("WMIProv"),
WmiExpense(1),
Locale("MS\\0x409"),
Description("Description of class"]
 
//Class name 
class Vendor_SerialInfo {
 
//Required items 
    [key, read] 
     string InstanceName;
    [read]
     boolean Active;
 
// Bytes sent on port
// Property qualifiers 
    [read,
     WmiDataId(1),
     WmiScale(0),
     WmiComplexity(1),
     WmiVolatility(1000)]
     Description("Description of property")]
// Data item 
     uint64 BytesSent;
 
// Bytes received on port
    [read,
     write,
     WmiDataId(2),
     WmiScale(0), 
     WmiVolatility(1000)]
     uint64 BytesReceived;
 
// Who owns the port 
    [read,
     WmiDataId(4),
     WmiScale(0),              
     WmiVolatility(60000)] 
    string Owner;
 
// Status bit array
    [read, write,
     WmiDataId(3),
     WmiScale(0)]
     byte Status[16];
 
//The number of items in the XmitBufferSize array
    [read,
     WmiDataId(5),
     WmiScale(0),
     WmiComplexity(1),
     WmiVolatility(1000)]
     uint32 XmitDescriptorCount;       
 
//Array of XmitDescriptor classes
    [read,
     WmiDataId(6),
     WmiSizeIs("XmitDescriptorCount"),
     WmiScale(0),
     WmiComplexity(1),
     WmiVolatility(1000)]
    Vendor_XmitDescriptor XmitBufferSize[];
}

前の例で示した埋め込みクラスのクラス定義を次に示します。 このクラスには、 InstanceName または Active 項目が含まれていないことに注意してください。

// Example of an embedded class 
[WMI, guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
class Vendor_XmitDescriptor {
    [read, WmiDataId(1)] int32 DestinationIndex;
    [read, WmiDataId(2)] int32 DestinationTarget;
}

イベント ブロックのクラス定義を次に示します。 クラスは WmiEventから派生しています。

// Example of an event
[WMI, Dynamic, Provider("WMIProv"),
guid("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"),
locale("MS\\0x409"),
WmiExpense(1),
Description("Notify Toaster Arrival")]
class ToasterNotifyDeviceArrival : WMIEvent
{
    [key, read]
    string      InstanceName;

    [read]
    boolean           Active;

    [read,
     Description("Device Model Name"),
     WmiDataId(1)]    string     ModelName;
};