Win32 API 日本語リファレンス
ホームUI.ColorSystem › WcsSetUsePerUserProfiles

WcsSetUsePerUserProfiles

関数
デバイスがユーザー別プロファイルを使うか設定する。
DLLmscms.dll呼出規約winapi

シグネチャ

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

BOOL WcsSetUsePerUserProfiles(
    LPCWSTR pDeviceName,
    DWORD dwDeviceClass,
    BOOL usePerUserProfiles
);

パラメーター

名前方向説明
pDeviceNameLPCWSTRin設定を変更する対象デバイス名を指すワイド文字列ポインタ。
dwDeviceClassDWORDin対象デバイスのクラス(モニタ・プリンタ等)を示す値。
usePerUserProfilesBOOLinユーザー単位プロファイルを有効にするかを指定するBOOL値。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WcsSetUsePerUserProfiles(
    LPCWSTR pDeviceName,
    DWORD dwDeviceClass,
    BOOL usePerUserProfiles
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll", ExactSpelling = true)]
static extern bool WcsSetUsePerUserProfiles(
    [MarshalAs(UnmanagedType.LPWStr)] string pDeviceName,   // LPCWSTR
    uint dwDeviceClass,   // DWORD
    bool usePerUserProfiles   // BOOL
);
<DllImport("mscms.dll", ExactSpelling:=True)>
Public Shared Function WcsSetUsePerUserProfiles(
    <MarshalAs(UnmanagedType.LPWStr)> pDeviceName As String,   ' LPCWSTR
    dwDeviceClass As UInteger,   ' DWORD
    usePerUserProfiles As Boolean   ' BOOL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pDeviceName : LPCWSTR
' dwDeviceClass : DWORD
' usePerUserProfiles : BOOL
Declare PtrSafe Function WcsSetUsePerUserProfiles Lib "mscms" ( _
    ByVal pDeviceName As LongPtr, _
    ByVal dwDeviceClass As Long, _
    ByVal usePerUserProfiles As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WcsSetUsePerUserProfiles = ctypes.windll.mscms.WcsSetUsePerUserProfiles
WcsSetUsePerUserProfiles.restype = wintypes.BOOL
WcsSetUsePerUserProfiles.argtypes = [
    wintypes.LPCWSTR,  # pDeviceName : LPCWSTR
    wintypes.DWORD,  # dwDeviceClass : DWORD
    wintypes.BOOL,  # usePerUserProfiles : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mscms.dll')
WcsSetUsePerUserProfiles = Fiddle::Function.new(
  lib['WcsSetUsePerUserProfiles'],
  [
    Fiddle::TYPE_VOIDP,  # pDeviceName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwDeviceClass : DWORD
    Fiddle::TYPE_INT,  # usePerUserProfiles : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "mscms")]
extern "system" {
    fn WcsSetUsePerUserProfiles(
        pDeviceName: *const u16,  // LPCWSTR
        dwDeviceClass: u32,  // DWORD
        usePerUserProfiles: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll")]
public static extern bool WcsSetUsePerUserProfiles([MarshalAs(UnmanagedType.LPWStr)] string pDeviceName, uint dwDeviceClass, bool usePerUserProfiles);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mscms_WcsSetUsePerUserProfiles' -Namespace Win32 -PassThru
# $api::WcsSetUsePerUserProfiles(pDeviceName, dwDeviceClass, usePerUserProfiles)
#uselib "mscms.dll"
#func global WcsSetUsePerUserProfiles "WcsSetUsePerUserProfiles" sptr, sptr, sptr
; WcsSetUsePerUserProfiles pDeviceName, dwDeviceClass, usePerUserProfiles   ; 戻り値は stat
; pDeviceName : LPCWSTR -> "sptr"
; dwDeviceClass : DWORD -> "sptr"
; usePerUserProfiles : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "mscms.dll"
#cfunc global WcsSetUsePerUserProfiles "WcsSetUsePerUserProfiles" wstr, int, int
; res = WcsSetUsePerUserProfiles(pDeviceName, dwDeviceClass, usePerUserProfiles)
; pDeviceName : LPCWSTR -> "wstr"
; dwDeviceClass : DWORD -> "int"
; usePerUserProfiles : BOOL -> "int"
; BOOL WcsSetUsePerUserProfiles(LPCWSTR pDeviceName, DWORD dwDeviceClass, BOOL usePerUserProfiles)
#uselib "mscms.dll"
#cfunc global WcsSetUsePerUserProfiles "WcsSetUsePerUserProfiles" wstr, int, int
; res = WcsSetUsePerUserProfiles(pDeviceName, dwDeviceClass, usePerUserProfiles)
; pDeviceName : LPCWSTR -> "wstr"
; dwDeviceClass : DWORD -> "int"
; usePerUserProfiles : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mscms = windows.NewLazySystemDLL("mscms.dll")
	procWcsSetUsePerUserProfiles = mscms.NewProc("WcsSetUsePerUserProfiles")
)

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

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

typedef WcsSetUsePerUserProfilesNative = Int32 Function(Pointer<Utf16>, Uint32, Int32);
typedef WcsSetUsePerUserProfilesDart = int Function(Pointer<Utf16>, int, int);
final WcsSetUsePerUserProfiles = DynamicLibrary.open('mscms.dll')
    .lookupFunction<WcsSetUsePerUserProfilesNative, WcsSetUsePerUserProfilesDart>('WcsSetUsePerUserProfiles');
// pDeviceName : LPCWSTR -> Pointer<Utf16>
// dwDeviceClass : DWORD -> Uint32
// usePerUserProfiles : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WcsSetUsePerUserProfiles(
  pDeviceName: PWideChar;   // LPCWSTR
  dwDeviceClass: DWORD;   // DWORD
  usePerUserProfiles: BOOL   // BOOL
): BOOL; stdcall;
  external 'mscms.dll' name 'WcsSetUsePerUserProfiles';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WcsSetUsePerUserProfiles"
  c_WcsSetUsePerUserProfiles :: CWString -> Word32 -> CInt -> IO CInt
-- pDeviceName : LPCWSTR -> CWString
-- dwDeviceClass : DWORD -> Word32
-- usePerUserProfiles : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wcssetuseperuserprofiles =
  foreign "WcsSetUsePerUserProfiles"
    ((ptr uint16_t) @-> uint32_t @-> int32_t @-> returning int32_t)
(* pDeviceName : LPCWSTR -> (ptr uint16_t) *)
(* dwDeviceClass : DWORD -> uint32_t *)
(* usePerUserProfiles : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mscms (t "mscms.dll"))
(cffi:use-foreign-library mscms)

(cffi:defcfun ("WcsSetUsePerUserProfiles" wcs-set-use-per-user-profiles :convention :stdcall) :int32
  (p-device-name (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-device-class :uint32)   ; DWORD
  (use-per-user-profiles :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WcsSetUsePerUserProfiles = Win32::API::More->new('mscms',
    'BOOL WcsSetUsePerUserProfiles(LPCWSTR pDeviceName, DWORD dwDeviceClass, BOOL usePerUserProfiles)');
# my $ret = $WcsSetUsePerUserProfiles->Call($pDeviceName, $dwDeviceClass, $usePerUserProfiles);
# pDeviceName : LPCWSTR -> LPCWSTR
# dwDeviceClass : DWORD -> DWORD
# usePerUserProfiles : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。