Win32 API 日本語リファレンス
ホームStorage.OfflineFiles › OfflineFilesEnable

OfflineFilesEnable

関数
オフラインファイル機能の有効・無効を切り替える。
DLLCSCAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// CSCAPI.dll
#include <windows.h>

DWORD OfflineFilesEnable(
    BOOL bEnable,
    BOOL* pbRebootRequired
);

パラメーター

名前方向説明
bEnableBOOLinオフラインファイル機能を有効化するならTRUE、無効化するならFALSE。
pbRebootRequiredBOOL*out設定反映に再起動が必要かを示すBOOLを受け取る出力ポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

// CSCAPI.dll
#include <windows.h>

DWORD OfflineFilesEnable(
    BOOL bEnable,
    BOOL* pbRebootRequired
);
[DllImport("CSCAPI.dll", ExactSpelling = true)]
static extern uint OfflineFilesEnable(
    bool bEnable,   // BOOL
    out bool pbRebootRequired   // BOOL* out
);
<DllImport("CSCAPI.dll", ExactSpelling:=True)>
Public Shared Function OfflineFilesEnable(
    bEnable As Boolean,   ' BOOL
    <Out> ByRef pbRebootRequired As Boolean   ' BOOL* out
) As UInteger
End Function
' bEnable : BOOL
' pbRebootRequired : BOOL* out
Declare PtrSafe Function OfflineFilesEnable Lib "cscapi" ( _
    ByVal bEnable As Long, _
    ByRef pbRebootRequired As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

OfflineFilesEnable = ctypes.windll.cscapi.OfflineFilesEnable
OfflineFilesEnable.restype = wintypes.DWORD
OfflineFilesEnable.argtypes = [
    wintypes.BOOL,  # bEnable : BOOL
    ctypes.c_void_p,  # pbRebootRequired : BOOL* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CSCAPI.dll')
OfflineFilesEnable = Fiddle::Function.new(
  lib['OfflineFilesEnable'],
  [
    Fiddle::TYPE_INT,  # bEnable : BOOL
    Fiddle::TYPE_VOIDP,  # pbRebootRequired : BOOL* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "cscapi")]
extern "system" {
    fn OfflineFilesEnable(
        bEnable: i32,  // BOOL
        pbRebootRequired: *mut i32  // BOOL* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CSCAPI.dll")]
public static extern uint OfflineFilesEnable(bool bEnable, out bool pbRebootRequired);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CSCAPI_OfflineFilesEnable' -Namespace Win32 -PassThru
# $api::OfflineFilesEnable(bEnable, pbRebootRequired)
#uselib "CSCAPI.dll"
#func global OfflineFilesEnable "OfflineFilesEnable" sptr, sptr
; OfflineFilesEnable bEnable, varptr(pbRebootRequired)   ; 戻り値は stat
; bEnable : BOOL -> "sptr"
; pbRebootRequired : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CSCAPI.dll"
#cfunc global OfflineFilesEnable "OfflineFilesEnable" int, var
; res = OfflineFilesEnable(bEnable, pbRebootRequired)
; bEnable : BOOL -> "int"
; pbRebootRequired : BOOL* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD OfflineFilesEnable(BOOL bEnable, BOOL* pbRebootRequired)
#uselib "CSCAPI.dll"
#cfunc global OfflineFilesEnable "OfflineFilesEnable" int, var
; res = OfflineFilesEnable(bEnable, pbRebootRequired)
; bEnable : BOOL -> "int"
; pbRebootRequired : BOOL* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cscapi = windows.NewLazySystemDLL("CSCAPI.dll")
	procOfflineFilesEnable = cscapi.NewProc("OfflineFilesEnable")
)

// bEnable (BOOL), pbRebootRequired (BOOL* out)
r1, _, err := procOfflineFilesEnable.Call(
	uintptr(bEnable),
	uintptr(pbRebootRequired),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function OfflineFilesEnable(
  bEnable: BOOL;   // BOOL
  pbRebootRequired: Pointer   // BOOL* out
): DWORD; stdcall;
  external 'CSCAPI.dll' name 'OfflineFilesEnable';
result := DllCall("CSCAPI\OfflineFilesEnable"
    , "Int", bEnable   ; BOOL
    , "Ptr", pbRebootRequired   ; BOOL* out
    , "UInt")   ; return: DWORD
●OfflineFilesEnable(bEnable, pbRebootRequired) = DLL("CSCAPI.dll", "dword OfflineFilesEnable(bool, void*)")
# 呼び出し: OfflineFilesEnable(bEnable, pbRebootRequired)
# bEnable : BOOL -> "bool"
# pbRebootRequired : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "cscapi" fn OfflineFilesEnable(
    bEnable: i32, // BOOL
    pbRebootRequired: [*c]i32 // BOOL* out
) callconv(std.os.windows.WINAPI) u32;
proc OfflineFilesEnable(
    bEnable: int32,  # BOOL
    pbRebootRequired: ptr int32  # BOOL* out
): uint32 {.importc: "OfflineFilesEnable", stdcall, dynlib: "CSCAPI.dll".}
pragma(lib, "cscapi");
extern(Windows)
uint OfflineFilesEnable(
    int bEnable,   // BOOL
    int* pbRebootRequired   // BOOL* out
);
ccall((:OfflineFilesEnable, "CSCAPI.dll"), stdcall, UInt32,
      (Int32, Ptr{Int32}),
      bEnable, pbRebootRequired)
# bEnable : BOOL -> Int32
# pbRebootRequired : BOOL* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t OfflineFilesEnable(
    int32_t bEnable,
    int32_t* pbRebootRequired);
]]
local cscapi = ffi.load("cscapi")
-- cscapi.OfflineFilesEnable(bEnable, pbRebootRequired)
-- bEnable : BOOL
-- pbRebootRequired : BOOL* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CSCAPI.dll');
const OfflineFilesEnable = lib.func('__stdcall', 'OfflineFilesEnable', 'uint32_t', ['int32_t', 'int32_t *']);
// OfflineFilesEnable(bEnable, pbRebootRequired)
// bEnable : BOOL -> 'int32_t'
// pbRebootRequired : BOOL* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CSCAPI.dll", {
  OfflineFilesEnable: { parameters: ["i32", "pointer"], result: "u32" },
});
// lib.symbols.OfflineFilesEnable(bEnable, pbRebootRequired)
// bEnable : BOOL -> "i32"
// pbRebootRequired : BOOL* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t OfflineFilesEnable(
    int32_t bEnable,
    int32_t* pbRebootRequired);
C, "CSCAPI.dll");
// $ffi->OfflineFilesEnable(bEnable, pbRebootRequired);
// bEnable : BOOL
// pbRebootRequired : BOOL* 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 Cscapi extends StdCallLibrary {
    Cscapi INSTANCE = Native.load("cscapi", Cscapi.class);
    int OfflineFilesEnable(
        boolean bEnable,   // BOOL
        IntByReference pbRebootRequired   // BOOL* out
    );
}
@[Link("cscapi")]
lib LibCSCAPI
  fun OfflineFilesEnable = OfflineFilesEnable(
    bEnable : Int32,   # BOOL
    pbRebootRequired : Int32*   # BOOL* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef OfflineFilesEnableNative = Uint32 Function(Int32, Pointer<Int32>);
typedef OfflineFilesEnableDart = int Function(int, Pointer<Int32>);
final OfflineFilesEnable = DynamicLibrary.open('CSCAPI.dll')
    .lookupFunction<OfflineFilesEnableNative, OfflineFilesEnableDart>('OfflineFilesEnable');
// bEnable : BOOL -> Int32
// pbRebootRequired : BOOL* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function OfflineFilesEnable(
  bEnable: BOOL;   // BOOL
  pbRebootRequired: Pointer   // BOOL* out
): DWORD; stdcall;
  external 'CSCAPI.dll' name 'OfflineFilesEnable';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "OfflineFilesEnable"
  c_OfflineFilesEnable :: CInt -> Ptr CInt -> IO Word32
-- bEnable : BOOL -> CInt
-- pbRebootRequired : BOOL* out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let offlinefilesenable =
  foreign "OfflineFilesEnable"
    (int32_t @-> (ptr int32_t) @-> returning uint32_t)
(* bEnable : BOOL -> int32_t *)
(* pbRebootRequired : BOOL* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library cscapi (t "CSCAPI.dll"))
(cffi:use-foreign-library cscapi)

(cffi:defcfun ("OfflineFilesEnable" offline-files-enable :convention :stdcall) :uint32
  (b-enable :int32)   ; BOOL
  (pb-reboot-required :pointer))   ; BOOL* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $OfflineFilesEnable = Win32::API::More->new('CSCAPI',
    'DWORD OfflineFilesEnable(BOOL bEnable, LPVOID pbRebootRequired)');
# my $ret = $OfflineFilesEnable->Call($bEnable, $pbRebootRequired);
# bEnable : BOOL -> BOOL
# pbRebootRequired : BOOL* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。