ホーム › Networking.ActiveDirectory › IADsLargeInteger
IADsLargeInteger
COMIDispatch (デュアル)✅ IDispatch を実装(デュアルインターフェース)。HSP では
comobj 経由でメソッド名による遅延バインド呼び出しができます(vtableインデックス不要)。公式ドキュメント
LargeInteger 型の 64 ビット整数を操作するために使用します。
解説(Remarks)
Visual Basic には符号なしの数値データ型が組み込まれていないため、Visual Basic で IADsLargeInteger を扱うのは困難です。LowPart または HighPart の最上位ビットが設定されていると、Visual Basic はその数値を負の値として扱うため、データ変換でエラーが発生することがあります。以下の Visual Basic のコード例は、Visual Basic で IADsLargeInteger を適切に扱う方法を示しています。
例
次の例は、IADsLargeInteger オブジェクトを 16 進文字列に変換する方法を示しています。
Dim oDomain As IADs
Dim oLargeInt As LargeInteger
Set oDomain = GetObject("LDAP://DC=fabrikam,DC=com")
Set oLargeInt = oDomain.Get("creationTime")
Debug.Print oLargeInt.HighPart
Debug.Print oLargeInt.LowPart
strTemp = "&H" + CStr(Hex(oLargeInt.HighPart)) + _
CStr(Hex(oLargeInt.LowPart))
Debug.Print strTemp
Visual Basic では、日付や時刻を表す IADsLargeInteger オブジェクトを、FileTimeToSystemTime および SystemTimeToVariantTime API を使用して、時刻 Variant に変換できます。これを次のコード例に示します。
Public Declare Function FileTimeToSystemTime Lib "kernel32" _
(lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long
Public Declare Function SystemTimeToVariantTime Lib "oleaut32.dll" _
(lpSystemTime As SYSTEMTIME, _
dbTime As Double) As Long
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
' This function will convert the ADSI data type LargeInteger to
' a Variant time value in Greenwich Mean Time (GMT).
Function LargeInteger_To_Time(oLargeInt As LargeInteger, vTime As Variant)_
As Boolean
On Error Resume Next
Dim pFileTime As FILETIME
Dim pSysTime As SYSTEMTIME
Dim dbTime As Double
Dim lResult As Long
If (oLargeInt.HighPart = 0 And oLargeInt.LowPart = 0) Then
vTime = 0
LargeInteger_To_Time = True
Exit Function
End If
If (oLargeInt.LowPart = -1) Then
vTime = -1
LargeInteger_To_Time = True
Exit Function
End If
pFileTime.dwHighDateTime = oLargeInt.HighPart
pFileTime.dwLowDateTime = oLargeInt.LowPart
' Convert the FileTime to System time.
lResult = FileTimeToSystemTime(pFileTime, pSysTime)
If lResult = 0 Then
LargeInteger_To_Time = False
Debug.Print "FileTimeToSystemTime: " + Err.Number + " - "_
+ Err.Description
Exit Function
End If
' Convert System Time to a Double.
lResult = SystemTimeToVariantTime(pSysTime, dbTime)
If lResult = 0 Then
LargeInteger_To_Time = False
Debug.Print "SystemTimeToVariantTime: " + Err.Number + _
" - " + Err.Description
Exit Function
End If
' Place the double in the variant.
vTime = CDate(dbTime)
LargeInteger_To_Time = True
End Function
次の例は、IADsLargeInteger を 64 ビット整数に変換する方法を示しています。
HRESULT PrintAccountExpires(LPCWSTR pwszADsPath)
{
if(!pwszADsPath)
{
return E_INVALIDARG;
}
HRESULT hr;
CComPtr<IADs> spads;
// Bind to the object.
hr = ADsGetObject(pwszADsPath, IID_IADs, (LPVOID*)&spads);
if(FAILED(hr))
{
return hr;
}
/*
Get the accountExpires attribute, which is an
IDispatch that contains an IADsLargeInteger.
*/
CComVariant svar;
hr = spads->Get(CComBSTR("accountExpires"), &svar);
if(FAILED(hr))
{
return hr;
}
// Get the IADsLargeInteger interface.
CComPtr<IADsLargeInteger> spli;
hr = svar.pdispVal->QueryInterface(IID_IADsLargeInteger,
(LPVOID*)&spli);
if(FAILED(hr))
{
return hr;
}
// Get the high and low parts of the value.
long lHigh;
long lLow;
hr = spli->get_HighPart(&lHigh);
hr = spli->get_LowPart(&lLow);
// Convert the high and low parts to an __i64.
__int64 i64;
i64 = (ULONG)lHigh;
i64 = (i64 << 32);
i64 = i64 + (ULONG)lLow;
// Print all of the values.
wprintf(L"HighPart = %u, LowPart = %u, Combined = %I64d\n",
lHigh, lLow, i64);
return hr;
}
メソッド 4
vtbl = vtable インデックス(0始まり)。IDispatch 実装のため HSP ではメソッド名でも呼べます(上記)。低レベルの index 呼び出し用に vtbl も掲載。0〜2 は IUnknown。
| retval | INT* | out | 64ビット値の上位32ビットを受け取る出力先。INT*で返る。 |
| lnHighPart | INT | in | 設定する64ビット値の上位32ビットを指定する。 |
| retval | INT* | out | 64ビット値の下位32ビットを受け取る出力先。INT*で返る。 |
| lnLowPart | INT | in | 設定する64ビット値の下位32ビットを指定する。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
HSP用 COM定義
#usecom / #comfunc によるHSPのCOM呼び出し定義。数字は vtbl インデックス(0始まり)。クラスIDが無い場合 #usecom の末尾は "{}"、ある場合は "{CLSID}"。
出力引数:
#define global IID_IADsLargeInteger "{9068270B-0939-11D1-8BE1-00C04FD8D503}" #usecom global IADsLargeInteger IID_IADsLargeInteger "{}" #comfunc global IADsLargeInteger_get_HighPart 7 var #comfunc global IADsLargeInteger_put_HighPart 8 int #comfunc global IADsLargeInteger_get_LowPart 9 var #comfunc global IADsLargeInteger_put_LowPart 10 int ; ※数字は vtbl インデックス(0始まり)。0/1/2 は IUnknown(QueryInterface/AddRef/Release)。 ; ※このインターフェースは直接 CoCreateInstance するクラスIDが無いため "{}"(他メソッド/アクティベーションで取得)。 ; ※出力/バッファ引数は var(変数直渡し)。varptr 方式にも切替可。 ; ※IDispatch 実装。HSP では comobj 経由でメソッド名による呼び出しも可能(vtbl 不要)。#define global IID_IADsLargeInteger "{9068270B-0939-11D1-8BE1-00C04FD8D503}" #usecom global IADsLargeInteger IID_IADsLargeInteger "{}" #comfunc global IADsLargeInteger_get_HighPart 7 sptr #comfunc global IADsLargeInteger_put_HighPart 8 int #comfunc global IADsLargeInteger_get_LowPart 9 sptr #comfunc global IADsLargeInteger_put_LowPart 10 int ; ※数字は vtbl インデックス(0始まり)。0/1/2 は IUnknown(QueryInterface/AddRef/Release)。 ; ※このインターフェースは直接 CoCreateInstance するクラスIDが無いため "{}"(他メソッド/アクティベーションで取得)。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※IDispatch 実装。HSP では comobj 経由でメソッド名による呼び出しも可能(vtbl 不要)。