CfGetPlaceholderRangeInfoForHydration
関数シグネチャ
// cldapi.dll
#include <windows.h>
HRESULT CfGetPlaceholderRangeInfoForHydration(
CF_CONNECTION_KEY ConnectionKey,
LONGLONG TransferKey,
LONGLONG FileId,
CF_PLACEHOLDER_RANGE_INFO_CLASS InfoClass,
LONGLONG StartingOffset,
LONGLONG RangeLength,
void* InfoBuffer,
DWORD InfoBufferSize,
DWORD* InfoBufferWritten // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ConnectionKey | CF_CONNECTION_KEY | in | 同期プロバイダーが管理する同期ルートに対して CfConnectSyncRoot が作成した不透明なハンドル。CF_CALLBACK_TYPE_FETCH_DATA コールバックやその他のコールバックの CF_CALLBACK_INFO でも返されます。 | ||||||||
| TransferKey | LONGLONG | in | CF_CALLBACK_TYPE_FETCH_DATA コールバックが呼び出されたプレースホルダーファイルへの不透明なハンドル。CF_CALLBACK_TYPE_FETCH_DATA コールバックの CF_CALLBACK_INFO でも返されます。CF_CALLBACK_TYPE_FETCH_DATA コールバック以外からこの API を呼び出す場合は、CfGetTransferKey で取得することもできます。 | ||||||||
| FileId | LONGLONG | in | 処理対象のプレースホルダーファイル/ディレクトリを表す、ファイルシステムが管理するボリューム全体で一意な 64 ビットの ID。TransferKey と同様に、CF_CALLBACK_TYPE_FETCH_DATA などのコールバックの CF_CALLBACK_INFO で返されるため、プロバイダーが再取得する必要はありません。 | ||||||||
| InfoClass | CF_PLACEHOLDER_RANGE_INFO_CLASS | in | プレースホルダーデータの範囲の種類。次のいずれかの値を指定できます。
| ||||||||
| StartingOffset | LONGLONG | in | データ範囲の開始位置のオフセット。StartingOffset と RangeLength により、InfoClass パラメーターで指定した情報を要求する、プレースホルダーファイル内の範囲を指定します。 | ||||||||
| RangeLength | LONGLONG | in | データ範囲の長さ。RangeLength に CF_EOF を指定すると、情報を要求する範囲が StartingOffset からファイルの末尾までであることを示します。 | ||||||||
| InfoBuffer | void* | out | データを受け取るバッファーへのポインター。このバッファーは CF_FILE_RANGE 構造体の配列であり、各要素は要求された範囲を表すオフセットと長さの組です。 | ||||||||
| InfoBufferSize | DWORD | in | InfoBuffer の長さ (バイト単位)。 | ||||||||
| InfoBufferWritten | DWORD* | outoptional | InfoBuffer に返されたバイト数を受け取ります。 |
戻り値の型: HRESULT
公式ドキュメント
ConnectionKey、TransferKey、FileId を識別子として使用し、プレースホルダーファイルまたはフォルダーの範囲情報を取得します。
戻り値
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。代表的なエラーコードを次の表に示します。
| エラーコード | 意味 |
|---|---|
| HRESULT_FROM_WIN32( ERROR_HANDLE_EOF ) | StartingOffset がファイルの末尾の位置以上であることを示します。 |
| HRESULT_FROM_WIN32( ERROR_MORE_DATA ) | 次の CF_FILE_RANGE エントリが、指定されたバッファーに収まらないことを示します。呼び出し元は、返された InfoBufferWritten の値を使用して、エントリを受け取ったかどうかを確認する必要があります。 |
解説(Remarks)
プレースホルダーのハイドレート済みファイル範囲を照会する API は既に存在しますが、プラットフォームの信頼性を向上させるために新しい API が必要になりました。
既存の API である CfGetPlaceholderRangeInfo は、ファイルに対して開かれたハンドルを必要とし、そのハンドルを使用して FSCTL_HSM_CONTROL をトリガーします。プロバイダーや同期エンジンは通常、IO を満たすためにフィルターがファイルをハイドレートする目的で呼び出した CF_CALLBACK_TYPE_FETCH_DATA コールバックのコンテキストで、ファイルのどの部分がハイドレートされていないかを判断するためにこの API を使用します。
プロバイダーや同期エンジンが CfGetPlaceholderRangeInfo にパラメーターとして渡すファイルのハンドルを開こうとしたときに、IO スタック内のミニフィルターがそのファイルに対してデータスキャンを発行する可能性があります。あるいは、ミニフィルターが CfGetPlaceholderRangeInfo が内部的にトリガーする FSCTL_HSM_CONTROL をブロックする可能性もあります。
cldflt フィルターは、ファイルをハイドレートするために必要なファイル範囲ごとに CF_CALLBACK_TYPE_FETCH_DATA コールバックを 1 回だけ呼び出すように設計されています。上記のいずれかのケースが発生すると、データスキャンが元の CF_CALLBACK_TYPE_FETCH_DATA の完了待ちになるか、CF_CALLBACK_TYPE_FETCH_DATA がブロックされた FSCTL の完了待ちになります。その結果、ハイドレーションのパスでデッドロックが発生します。
そのため、この API が必要になります。この API は CfGetPlaceholderRangeInfo と同じ機能を提供しますが、中間の IO スタックをバイパスし、フィルターメッセージポートを使用してフィルターと直接通信します。したがって、中間のミニフィルターが CreateFile や FSCTL_HSM_CONTROL を妨げることはありません。
呼び出し元は、CfConnectSyncRoot で取得した ConnectionKey を常に保持している点に注意してください。TransferKey は CfGetTransferKey で取得でき、FileId は GetFileInformationByHandle で取得できます。ただし、この方法ではファイルへのハンドルを開く必要があるため、CfGetPlaceholderRangeInfo を使用する場合と変わりません。
まとめると、CF_CALLBACK_TYPE_FETCH_DATA コールバックのコンテキストで範囲情報が必要な場合は、この API を使用してください。フィルターから要求されていない状態でプロバイダーがファイルをハイドレートする場合を含め、それ以外のすべてのケースでは CfGetPlaceholderRangeInfo を使用してください。プラットフォームは特定のコンテキストでどちらの API が呼び出されたかを認識できないため、適切に使い分ける責任はプロバイダーや同期エンジンにあります。
Examples
次に示すのは、一度に 1 つの CF_FILE_RANGE エントリのみを取得できるだけの InfoBuffer を渡す簡単な例です。実際には、呼び出し元は API の 1 回の呼び出しで複数の CF_FILE_RANGE エントリに対応できる InfoBuffer を渡すことができます。必要に応じて、エラーコード HRESULT_FROM_WIN32( ERROR_MORE_DATA ) を手がかりに、より大きなバッファーを渡すこともできます。
#include <cfapi.h>
// ******************************************************************************************************
// CF_CALLBACK_TYPE_FETCH_DATA コールバック内で、プロバイダーは g_PlatformInfo.IntegrationNumber を使用して
// 新しい API がサポートされているかどうかを確認できます。サポートされている場合、プロバイダーは
// ConnectionKey、TransferKey、FileId をその他のパラメーターと共に渡して、既にハイドレートされている
// ファイル範囲に関する情報を取得できます。
// *******************************************************************************************************
// プロバイダーは、次のようにしてハイドレート済みのファイル範囲を取得できます。
std::vector<CF_FILE_RANGE> hydratedRanges = GetFileRangesFromCallback( CallbackInfo->ConnectionKey,
CallbackInfo->TransferKey,
CallbackInfo->FileId,
CF_PLACEHOLDER_RANGE_INFO_ONDISK
0,
CF_EOF);
// これらの hydratedRanges に基づいて、プロバイダーはディスク上に存在しない範囲だけをハイドレートすることを選択できます。
// ******************************************************************************************************
// 最終的にこの API を呼び出す関数の実装。
// ******************************************************************************************************
typedef HRESULT( __stdcall* t_CfGetPlaceholderRangeInfoForHydration )(
CF_CONNECTION_KEY ConnectionKey,
CF_TRANSFER_KEY TransferKey,
LARGE_INTEGER FileId,
CF_PLACEHOLDER_RANGE_INFO_CLASS InfoClass,
LARGE_INTEGER StartingOffset,
LARGE_INTEGER RangeLength,
PVOID InfoBuffer,
DWORD InfoBufferSize,
PDWORD InfoBufferWritten );
t_CfGetPlaceholderRangeInfoForHydration _CfGetPlaceholderRangeInfoForHydration = nullptr;
std::vector<CF_FILE_RANGE>
GetFileRangesFromCallback( CF_CONNECTION_KEY ConnectionKey,
CF_TRANSFER_KEY TransferKey,
LARGE_INTEGER FileId,
CF_PLACEHOLDER_RANGE_INFO_CLASS RangeInfoClass,
long long StartOffset,
long long Length,
PBOOLEAN UseOldAPI )
{
long long StartOffset = 0;
CF_FILE_RANGE fileRange;
long long Length = 0;
LARGE_INTEGER queryOffset = ll2li( StartOffset );
LARGE_INTEGER queryLength = ll2li( Length );
DWORD inforBufferWritten = 0;
// 関数が成功した場合、ここにファイル内のハイドレート済みの範囲がすべて格納されます。
std::vector<CF_FILE_RANGE> ranges;
bool stop = false;
CF_PLATFORM_INFO platformInfo;
hr = (CfGetPlatformInfo( &platformInfo ));
if(FAILED(hr)) {
*UseOldAPI = TRUE;
return ranges; //空。
}
if (platformInfo.IntegrationNumber < 600) {
*UseOldAPI = TRUE;
return ranges; //空。
}
wil::unique_hmodule CloudFilesApi( LoadLibrary( L"cldapi.dll" ) );
THROW_LAST_ERROR_IF_NULL( CloudFilesApi );
_CfGetPlaceholderRangeInfoForHydration = reinterpret_cast<t_CfGetPlaceholderRangeInfoForHydration>(
GetProcAddress( CloudFilesApi.get(), "CfGetPlaceholderRangeInfoForHydration" ) );
THROW_LAST_ERROR_IF_NULL( _CfGetPlaceholderRangeInfoForHydration );
while ( !stop ) {
hr = _CfGetPlaceholderRangeInfoForHydration ( ConnectionKey,
TransferKey,
FileId,
RangeInfoClass,
queryOffset,
queryLength,
&fileRange,
sizeof( fileRange ),
&infoBufferWritten );
if ( hr == HRESULT_FROM_WIN32( ERROR_HANDLE_EOF ) ||
hr == HRESULT_FROM_WIN32( ERROR_MORE_DATA ) ) {
// データがこれ以上ない場合にのみループを抜ける必要があります。
if ( hr == HRESULT_FROM_WIN32( ERROR_HANDLE_EOF ) ) {
stop = true;
}
hr = S_OK;
}
if ( FAILED( hr ) || infoBufferWritten == 0 ) {
return ranges;
}
ranges.push_back( fileRange );
queryOffset.QuadPart = fileRange.StartingOffset.QuadPart + fileRange.Length.QuadPart;
if ( Length != CF_EOF && queryOffset.QuadPart >= ( StartOffset + Length ) ) {
stop = true;
} else if ( Length != CF_EOF) {
// 新しいクエリの長さを更新します
queryLength.QuadPart = StartOffset + Length - queryOffset.QuadPart
if ( queryLength.QuadPart <= 0 ) {
stop = true;
}
}
}
return ranges;
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// cldapi.dll
#include <windows.h>
HRESULT CfGetPlaceholderRangeInfoForHydration(
CF_CONNECTION_KEY ConnectionKey,
LONGLONG TransferKey,
LONGLONG FileId,
CF_PLACEHOLDER_RANGE_INFO_CLASS InfoClass,
LONGLONG StartingOffset,
LONGLONG RangeLength,
void* InfoBuffer,
DWORD InfoBufferSize,
DWORD* InfoBufferWritten // optional
);[DllImport("cldapi.dll", ExactSpelling = true)]
static extern int CfGetPlaceholderRangeInfoForHydration(
long ConnectionKey, // CF_CONNECTION_KEY
long TransferKey, // LONGLONG
long FileId, // LONGLONG
int InfoClass, // CF_PLACEHOLDER_RANGE_INFO_CLASS
long StartingOffset, // LONGLONG
long RangeLength, // LONGLONG
IntPtr InfoBuffer, // void* out
uint InfoBufferSize, // DWORD
IntPtr InfoBufferWritten // DWORD* optional, out
);<DllImport("cldapi.dll", ExactSpelling:=True)>
Public Shared Function CfGetPlaceholderRangeInfoForHydration(
ConnectionKey As Long, ' CF_CONNECTION_KEY
TransferKey As Long, ' LONGLONG
FileId As Long, ' LONGLONG
InfoClass As Integer, ' CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset As Long, ' LONGLONG
RangeLength As Long, ' LONGLONG
InfoBuffer As IntPtr, ' void* out
InfoBufferSize As UInteger, ' DWORD
InfoBufferWritten As IntPtr ' DWORD* optional, out
) As Integer
End Function' ConnectionKey : CF_CONNECTION_KEY
' TransferKey : LONGLONG
' FileId : LONGLONG
' InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS
' StartingOffset : LONGLONG
' RangeLength : LONGLONG
' InfoBuffer : void* out
' InfoBufferSize : DWORD
' InfoBufferWritten : DWORD* optional, out
Declare PtrSafe Function CfGetPlaceholderRangeInfoForHydration Lib "cldapi" ( _
ByVal ConnectionKey As LongLong, _
ByVal TransferKey As LongLong, _
ByVal FileId As LongLong, _
ByVal InfoClass As Long, _
ByVal StartingOffset As LongLong, _
ByVal RangeLength As LongLong, _
ByVal InfoBuffer As LongPtr, _
ByVal InfoBufferSize As Long, _
ByVal InfoBufferWritten As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CfGetPlaceholderRangeInfoForHydration = ctypes.windll.cldapi.CfGetPlaceholderRangeInfoForHydration
CfGetPlaceholderRangeInfoForHydration.restype = ctypes.c_int
CfGetPlaceholderRangeInfoForHydration.argtypes = [
ctypes.c_longlong, # ConnectionKey : CF_CONNECTION_KEY
ctypes.c_longlong, # TransferKey : LONGLONG
ctypes.c_longlong, # FileId : LONGLONG
ctypes.c_int, # InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS
ctypes.c_longlong, # StartingOffset : LONGLONG
ctypes.c_longlong, # RangeLength : LONGLONG
ctypes.POINTER(None), # InfoBuffer : void* out
wintypes.DWORD, # InfoBufferSize : DWORD
ctypes.POINTER(wintypes.DWORD), # InfoBufferWritten : DWORD* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('cldapi.dll')
CfGetPlaceholderRangeInfoForHydration = Fiddle::Function.new(
lib['CfGetPlaceholderRangeInfoForHydration'],
[
Fiddle::TYPE_LONG_LONG, # ConnectionKey : CF_CONNECTION_KEY
Fiddle::TYPE_LONG_LONG, # TransferKey : LONGLONG
Fiddle::TYPE_LONG_LONG, # FileId : LONGLONG
Fiddle::TYPE_INT, # InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS
Fiddle::TYPE_LONG_LONG, # StartingOffset : LONGLONG
Fiddle::TYPE_LONG_LONG, # RangeLength : LONGLONG
Fiddle::TYPE_VOIDP, # InfoBuffer : void* out
-Fiddle::TYPE_INT, # InfoBufferSize : DWORD
Fiddle::TYPE_VOIDP, # InfoBufferWritten : DWORD* optional, out
],
Fiddle::TYPE_INT)#[link(name = "cldapi")]
extern "system" {
fn CfGetPlaceholderRangeInfoForHydration(
ConnectionKey: i64, // CF_CONNECTION_KEY
TransferKey: i64, // LONGLONG
FileId: i64, // LONGLONG
InfoClass: i32, // CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset: i64, // LONGLONG
RangeLength: i64, // LONGLONG
InfoBuffer: *mut (), // void* out
InfoBufferSize: u32, // DWORD
InfoBufferWritten: *mut u32 // DWORD* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("cldapi.dll")]
public static extern int CfGetPlaceholderRangeInfoForHydration(long ConnectionKey, long TransferKey, long FileId, int InfoClass, long StartingOffset, long RangeLength, IntPtr InfoBuffer, uint InfoBufferSize, IntPtr InfoBufferWritten);
"@
$api = Add-Type -MemberDefinition $sig -Name 'cldapi_CfGetPlaceholderRangeInfoForHydration' -Namespace Win32 -PassThru
# $api::CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)#uselib "cldapi.dll"
#func global CfGetPlaceholderRangeInfoForHydration "CfGetPlaceholderRangeInfoForHydration" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CfGetPlaceholderRangeInfoForHydration ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, varptr(InfoBufferWritten) ; 戻り値は stat
; ConnectionKey : CF_CONNECTION_KEY -> "sptr"
; TransferKey : LONGLONG -> "sptr"
; FileId : LONGLONG -> "sptr"
; InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "sptr"
; StartingOffset : LONGLONG -> "sptr"
; RangeLength : LONGLONG -> "sptr"
; InfoBuffer : void* out -> "sptr"
; InfoBufferSize : DWORD -> "sptr"
; InfoBufferWritten : DWORD* optional, out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "cldapi.dll" #cfunc global CfGetPlaceholderRangeInfoForHydration "CfGetPlaceholderRangeInfoForHydration" int64, int64, int64, int, int64, int64, sptr, int, var ; res = CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten) ; ConnectionKey : CF_CONNECTION_KEY -> "int64" ; TransferKey : LONGLONG -> "int64" ; FileId : LONGLONG -> "int64" ; InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "int" ; StartingOffset : LONGLONG -> "int64" ; RangeLength : LONGLONG -> "int64" ; InfoBuffer : void* out -> "sptr" ; InfoBufferSize : DWORD -> "int" ; InfoBufferWritten : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "cldapi.dll" #cfunc global CfGetPlaceholderRangeInfoForHydration "CfGetPlaceholderRangeInfoForHydration" int64, int64, int64, int, int64, int64, sptr, int, sptr ; res = CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, varptr(InfoBufferWritten)) ; ConnectionKey : CF_CONNECTION_KEY -> "int64" ; TransferKey : LONGLONG -> "int64" ; FileId : LONGLONG -> "int64" ; InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "int" ; StartingOffset : LONGLONG -> "int64" ; RangeLength : LONGLONG -> "int64" ; InfoBuffer : void* out -> "sptr" ; InfoBufferSize : DWORD -> "int" ; InfoBufferWritten : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; HRESULT CfGetPlaceholderRangeInfoForHydration(CF_CONNECTION_KEY ConnectionKey, LONGLONG TransferKey, LONGLONG FileId, CF_PLACEHOLDER_RANGE_INFO_CLASS InfoClass, LONGLONG StartingOffset, LONGLONG RangeLength, void* InfoBuffer, DWORD InfoBufferSize, DWORD* InfoBufferWritten) #uselib "cldapi.dll" #cfunc global CfGetPlaceholderRangeInfoForHydration "CfGetPlaceholderRangeInfoForHydration" int64, int64, int64, int, int64, int64, intptr, int, var ; res = CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten) ; ConnectionKey : CF_CONNECTION_KEY -> "int64" ; TransferKey : LONGLONG -> "int64" ; FileId : LONGLONG -> "int64" ; InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "int" ; StartingOffset : LONGLONG -> "int64" ; RangeLength : LONGLONG -> "int64" ; InfoBuffer : void* out -> "intptr" ; InfoBufferSize : DWORD -> "int" ; InfoBufferWritten : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT CfGetPlaceholderRangeInfoForHydration(CF_CONNECTION_KEY ConnectionKey, LONGLONG TransferKey, LONGLONG FileId, CF_PLACEHOLDER_RANGE_INFO_CLASS InfoClass, LONGLONG StartingOffset, LONGLONG RangeLength, void* InfoBuffer, DWORD InfoBufferSize, DWORD* InfoBufferWritten) #uselib "cldapi.dll" #cfunc global CfGetPlaceholderRangeInfoForHydration "CfGetPlaceholderRangeInfoForHydration" int64, int64, int64, int, int64, int64, intptr, int, intptr ; res = CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, varptr(InfoBufferWritten)) ; ConnectionKey : CF_CONNECTION_KEY -> "int64" ; TransferKey : LONGLONG -> "int64" ; FileId : LONGLONG -> "int64" ; InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "int" ; StartingOffset : LONGLONG -> "int64" ; RangeLength : LONGLONG -> "int64" ; InfoBuffer : void* out -> "intptr" ; InfoBufferSize : DWORD -> "int" ; InfoBufferWritten : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cldapi = windows.NewLazySystemDLL("cldapi.dll")
procCfGetPlaceholderRangeInfoForHydration = cldapi.NewProc("CfGetPlaceholderRangeInfoForHydration")
)
// ConnectionKey (CF_CONNECTION_KEY), TransferKey (LONGLONG), FileId (LONGLONG), InfoClass (CF_PLACEHOLDER_RANGE_INFO_CLASS), StartingOffset (LONGLONG), RangeLength (LONGLONG), InfoBuffer (void* out), InfoBufferSize (DWORD), InfoBufferWritten (DWORD* optional, out)
r1, _, err := procCfGetPlaceholderRangeInfoForHydration.Call(
uintptr(ConnectionKey),
uintptr(TransferKey),
uintptr(FileId),
uintptr(InfoClass),
uintptr(StartingOffset),
uintptr(RangeLength),
uintptr(InfoBuffer),
uintptr(InfoBufferSize),
uintptr(InfoBufferWritten),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CfGetPlaceholderRangeInfoForHydration(
ConnectionKey: Int64; // CF_CONNECTION_KEY
TransferKey: Int64; // LONGLONG
FileId: Int64; // LONGLONG
InfoClass: Integer; // CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset: Int64; // LONGLONG
RangeLength: Int64; // LONGLONG
InfoBuffer: Pointer; // void* out
InfoBufferSize: DWORD; // DWORD
InfoBufferWritten: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'cldapi.dll' name 'CfGetPlaceholderRangeInfoForHydration';result := DllCall("cldapi\CfGetPlaceholderRangeInfoForHydration"
, "Int64", ConnectionKey ; CF_CONNECTION_KEY
, "Int64", TransferKey ; LONGLONG
, "Int64", FileId ; LONGLONG
, "Int", InfoClass ; CF_PLACEHOLDER_RANGE_INFO_CLASS
, "Int64", StartingOffset ; LONGLONG
, "Int64", RangeLength ; LONGLONG
, "Ptr", InfoBuffer ; void* out
, "UInt", InfoBufferSize ; DWORD
, "Ptr", InfoBufferWritten ; DWORD* optional, out
, "Int") ; return: HRESULT●CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten) = DLL("cldapi.dll", "int CfGetPlaceholderRangeInfoForHydration(int64, int64, int64, int, int64, int64, void*, dword, void*)")
# 呼び出し: CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)
# ConnectionKey : CF_CONNECTION_KEY -> "int64"
# TransferKey : LONGLONG -> "int64"
# FileId : LONGLONG -> "int64"
# InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "int"
# StartingOffset : LONGLONG -> "int64"
# RangeLength : LONGLONG -> "int64"
# InfoBuffer : void* out -> "void*"
# InfoBufferSize : DWORD -> "dword"
# InfoBufferWritten : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "cldapi" fn CfGetPlaceholderRangeInfoForHydration(
ConnectionKey: i64, // CF_CONNECTION_KEY
TransferKey: i64, // LONGLONG
FileId: i64, // LONGLONG
InfoClass: i32, // CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset: i64, // LONGLONG
RangeLength: i64, // LONGLONG
InfoBuffer: ?*anyopaque, // void* out
InfoBufferSize: u32, // DWORD
InfoBufferWritten: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc CfGetPlaceholderRangeInfoForHydration(
ConnectionKey: int64, # CF_CONNECTION_KEY
TransferKey: int64, # LONGLONG
FileId: int64, # LONGLONG
InfoClass: int32, # CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset: int64, # LONGLONG
RangeLength: int64, # LONGLONG
InfoBuffer: pointer, # void* out
InfoBufferSize: uint32, # DWORD
InfoBufferWritten: ptr uint32 # DWORD* optional, out
): int32 {.importc: "CfGetPlaceholderRangeInfoForHydration", stdcall, dynlib: "cldapi.dll".}pragma(lib, "cldapi");
extern(Windows)
int CfGetPlaceholderRangeInfoForHydration(
long ConnectionKey, // CF_CONNECTION_KEY
long TransferKey, // LONGLONG
long FileId, // LONGLONG
int InfoClass, // CF_PLACEHOLDER_RANGE_INFO_CLASS
long StartingOffset, // LONGLONG
long RangeLength, // LONGLONG
void* InfoBuffer, // void* out
uint InfoBufferSize, // DWORD
uint* InfoBufferWritten // DWORD* optional, out
);ccall((:CfGetPlaceholderRangeInfoForHydration, "cldapi.dll"), stdcall, Int32,
(Int64, Int64, Int64, Int32, Int64, Int64, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)
# ConnectionKey : CF_CONNECTION_KEY -> Int64
# TransferKey : LONGLONG -> Int64
# FileId : LONGLONG -> Int64
# InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> Int32
# StartingOffset : LONGLONG -> Int64
# RangeLength : LONGLONG -> Int64
# InfoBuffer : void* out -> Ptr{Cvoid}
# InfoBufferSize : DWORD -> UInt32
# InfoBufferWritten : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CfGetPlaceholderRangeInfoForHydration(
int64_t ConnectionKey,
int64_t TransferKey,
int64_t FileId,
int32_t InfoClass,
int64_t StartingOffset,
int64_t RangeLength,
void* InfoBuffer,
uint32_t InfoBufferSize,
uint32_t* InfoBufferWritten);
]]
local cldapi = ffi.load("cldapi")
-- cldapi.CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)
-- ConnectionKey : CF_CONNECTION_KEY
-- TransferKey : LONGLONG
-- FileId : LONGLONG
-- InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS
-- StartingOffset : LONGLONG
-- RangeLength : LONGLONG
-- InfoBuffer : void* out
-- InfoBufferSize : DWORD
-- InfoBufferWritten : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('cldapi.dll');
const CfGetPlaceholderRangeInfoForHydration = lib.func('__stdcall', 'CfGetPlaceholderRangeInfoForHydration', 'int32_t', ['int64_t', 'int64_t', 'int64_t', 'int32_t', 'int64_t', 'int64_t', 'void *', 'uint32_t', 'uint32_t *']);
// CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)
// ConnectionKey : CF_CONNECTION_KEY -> 'int64_t'
// TransferKey : LONGLONG -> 'int64_t'
// FileId : LONGLONG -> 'int64_t'
// InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> 'int32_t'
// StartingOffset : LONGLONG -> 'int64_t'
// RangeLength : LONGLONG -> 'int64_t'
// InfoBuffer : void* out -> 'void *'
// InfoBufferSize : DWORD -> 'uint32_t'
// InfoBufferWritten : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("cldapi.dll", {
CfGetPlaceholderRangeInfoForHydration: { parameters: ["i64", "i64", "i64", "i32", "i64", "i64", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten)
// ConnectionKey : CF_CONNECTION_KEY -> "i64"
// TransferKey : LONGLONG -> "i64"
// FileId : LONGLONG -> "i64"
// InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> "i32"
// StartingOffset : LONGLONG -> "i64"
// RangeLength : LONGLONG -> "i64"
// InfoBuffer : void* out -> "pointer"
// InfoBufferSize : DWORD -> "u32"
// InfoBufferWritten : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CfGetPlaceholderRangeInfoForHydration(
int64_t ConnectionKey,
int64_t TransferKey,
int64_t FileId,
int32_t InfoClass,
int64_t StartingOffset,
int64_t RangeLength,
void* InfoBuffer,
uint32_t InfoBufferSize,
uint32_t* InfoBufferWritten);
C, "cldapi.dll");
// $ffi->CfGetPlaceholderRangeInfoForHydration(ConnectionKey, TransferKey, FileId, InfoClass, StartingOffset, RangeLength, InfoBuffer, InfoBufferSize, InfoBufferWritten);
// ConnectionKey : CF_CONNECTION_KEY
// TransferKey : LONGLONG
// FileId : LONGLONG
// InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS
// StartingOffset : LONGLONG
// RangeLength : LONGLONG
// InfoBuffer : void* out
// InfoBufferSize : DWORD
// InfoBufferWritten : DWORD* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Cldapi extends StdCallLibrary {
Cldapi INSTANCE = Native.load("cldapi", Cldapi.class);
int CfGetPlaceholderRangeInfoForHydration(
long ConnectionKey, // CF_CONNECTION_KEY
long TransferKey, // LONGLONG
long FileId, // LONGLONG
int InfoClass, // CF_PLACEHOLDER_RANGE_INFO_CLASS
long StartingOffset, // LONGLONG
long RangeLength, // LONGLONG
Pointer InfoBuffer, // void* out
int InfoBufferSize, // DWORD
IntByReference InfoBufferWritten // DWORD* optional, out
);
}@[Link("cldapi")]
lib Libcldapi
fun CfGetPlaceholderRangeInfoForHydration = CfGetPlaceholderRangeInfoForHydration(
ConnectionKey : Int64, # CF_CONNECTION_KEY
TransferKey : Int64, # LONGLONG
FileId : Int64, # LONGLONG
InfoClass : Int32, # CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset : Int64, # LONGLONG
RangeLength : Int64, # LONGLONG
InfoBuffer : Void*, # void* out
InfoBufferSize : UInt32, # DWORD
InfoBufferWritten : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CfGetPlaceholderRangeInfoForHydrationNative = Int32 Function(Int64, Int64, Int64, Int32, Int64, Int64, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef CfGetPlaceholderRangeInfoForHydrationDart = int Function(int, int, int, int, int, int, Pointer<Void>, int, Pointer<Uint32>);
final CfGetPlaceholderRangeInfoForHydration = DynamicLibrary.open('cldapi.dll')
.lookupFunction<CfGetPlaceholderRangeInfoForHydrationNative, CfGetPlaceholderRangeInfoForHydrationDart>('CfGetPlaceholderRangeInfoForHydration');
// ConnectionKey : CF_CONNECTION_KEY -> Int64
// TransferKey : LONGLONG -> Int64
// FileId : LONGLONG -> Int64
// InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> Int32
// StartingOffset : LONGLONG -> Int64
// RangeLength : LONGLONG -> Int64
// InfoBuffer : void* out -> Pointer<Void>
// InfoBufferSize : DWORD -> Uint32
// InfoBufferWritten : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CfGetPlaceholderRangeInfoForHydration(
ConnectionKey: Int64; // CF_CONNECTION_KEY
TransferKey: Int64; // LONGLONG
FileId: Int64; // LONGLONG
InfoClass: Integer; // CF_PLACEHOLDER_RANGE_INFO_CLASS
StartingOffset: Int64; // LONGLONG
RangeLength: Int64; // LONGLONG
InfoBuffer: Pointer; // void* out
InfoBufferSize: DWORD; // DWORD
InfoBufferWritten: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'cldapi.dll' name 'CfGetPlaceholderRangeInfoForHydration';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CfGetPlaceholderRangeInfoForHydration"
c_CfGetPlaceholderRangeInfoForHydration :: Int64 -> Int64 -> Int64 -> Int32 -> Int64 -> Int64 -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- ConnectionKey : CF_CONNECTION_KEY -> Int64
-- TransferKey : LONGLONG -> Int64
-- FileId : LONGLONG -> Int64
-- InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> Int32
-- StartingOffset : LONGLONG -> Int64
-- RangeLength : LONGLONG -> Int64
-- InfoBuffer : void* out -> Ptr ()
-- InfoBufferSize : DWORD -> Word32
-- InfoBufferWritten : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cfgetplaceholderrangeinfoforhydration =
foreign "CfGetPlaceholderRangeInfoForHydration"
(int64_t @-> int64_t @-> int64_t @-> int32_t @-> int64_t @-> int64_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* ConnectionKey : CF_CONNECTION_KEY -> int64_t *)
(* TransferKey : LONGLONG -> int64_t *)
(* FileId : LONGLONG -> int64_t *)
(* InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> int32_t *)
(* StartingOffset : LONGLONG -> int64_t *)
(* RangeLength : LONGLONG -> int64_t *)
(* InfoBuffer : void* out -> (ptr void) *)
(* InfoBufferSize : DWORD -> uint32_t *)
(* InfoBufferWritten : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library cldapi (t "cldapi.dll"))
(cffi:use-foreign-library cldapi)
(cffi:defcfun ("CfGetPlaceholderRangeInfoForHydration" cf-get-placeholder-range-info-for-hydration :convention :stdcall) :int32
(connection-key :int64) ; CF_CONNECTION_KEY
(transfer-key :int64) ; LONGLONG
(file-id :int64) ; LONGLONG
(info-class :int32) ; CF_PLACEHOLDER_RANGE_INFO_CLASS
(starting-offset :int64) ; LONGLONG
(range-length :int64) ; LONGLONG
(info-buffer :pointer) ; void* out
(info-buffer-size :uint32) ; DWORD
(info-buffer-written :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CfGetPlaceholderRangeInfoForHydration = Win32::API::More->new('cldapi',
'int CfGetPlaceholderRangeInfoForHydration(INT64 ConnectionKey, INT64 TransferKey, INT64 FileId, int InfoClass, INT64 StartingOffset, INT64 RangeLength, LPVOID InfoBuffer, DWORD InfoBufferSize, LPVOID InfoBufferWritten)');
# my $ret = $CfGetPlaceholderRangeInfoForHydration->Call($ConnectionKey, $TransferKey, $FileId, $InfoClass, $StartingOffset, $RangeLength, $InfoBuffer, $InfoBufferSize, $InfoBufferWritten);
# ConnectionKey : CF_CONNECTION_KEY -> INT64
# TransferKey : LONGLONG -> INT64
# FileId : LONGLONG -> INT64
# InfoClass : CF_PLACEHOLDER_RANGE_INFO_CLASS -> int
# StartingOffset : LONGLONG -> INT64
# RangeLength : LONGLONG -> INT64
# InfoBuffer : void* out -> LPVOID
# InfoBufferSize : DWORD -> DWORD
# InfoBufferWritten : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。