Win32 API 日本語リファレンス
ホームSystem.GroupPolicy › ImportRSoPData

ImportRSoPData

関数
RSoPデータをWMI名前空間にインポートする。
DLLGPEDIT.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT ImportRSoPData(
    LPWSTR lpNameSpace,
    LPWSTR lpFileName
);

パラメーター

名前方向説明
lpNameSpaceLPWSTRinインポート先のWMI名前空間。NULL可で既定の名前空間を使う。
lpFileNameLPWSTRinインポート元のRSoPデータファイルのパス。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ImportRSoPData(
    LPWSTR lpNameSpace,
    LPWSTR lpFileName
);
[DllImport("GPEDIT.dll", ExactSpelling = true)]
static extern int ImportRSoPData(
    [MarshalAs(UnmanagedType.LPWStr)] string lpNameSpace,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName   // LPWSTR
);
<DllImport("GPEDIT.dll", ExactSpelling:=True)>
Public Shared Function ImportRSoPData(
    <MarshalAs(UnmanagedType.LPWStr)> lpNameSpace As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String   ' LPWSTR
) As Integer
End Function
' lpNameSpace : LPWSTR
' lpFileName : LPWSTR
Declare PtrSafe Function ImportRSoPData Lib "gpedit" ( _
    ByVal lpNameSpace As LongPtr, _
    ByVal lpFileName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ImportRSoPData = ctypes.windll.gpedit.ImportRSoPData
ImportRSoPData.restype = ctypes.c_int
ImportRSoPData.argtypes = [
    wintypes.LPCWSTR,  # lpNameSpace : LPWSTR
    wintypes.LPCWSTR,  # lpFileName : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gpedit = windows.NewLazySystemDLL("GPEDIT.dll")
	procImportRSoPData = gpedit.NewProc("ImportRSoPData")
)

// lpNameSpace (LPWSTR), lpFileName (LPWSTR)
r1, _, err := procImportRSoPData.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpNameSpace))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ImportRSoPData(
  lpNameSpace: PWideChar;   // LPWSTR
  lpFileName: PWideChar   // LPWSTR
): Integer; stdcall;
  external 'GPEDIT.dll' name 'ImportRSoPData';
result := DllCall("GPEDIT\ImportRSoPData"
    , "WStr", lpNameSpace   ; LPWSTR
    , "WStr", lpFileName   ; LPWSTR
    , "Int")   ; return: HRESULT
●ImportRSoPData(lpNameSpace, lpFileName) = DLL("GPEDIT.dll", "int ImportRSoPData(char*, char*)")
# 呼び出し: ImportRSoPData(lpNameSpace, lpFileName)
# lpNameSpace : LPWSTR -> "char*"
# lpFileName : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ImportRSoPDataNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef ImportRSoPDataDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final ImportRSoPData = DynamicLibrary.open('GPEDIT.dll')
    .lookupFunction<ImportRSoPDataNative, ImportRSoPDataDart>('ImportRSoPData');
// lpNameSpace : LPWSTR -> Pointer<Utf16>
// lpFileName : LPWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ImportRSoPData(
  lpNameSpace: PWideChar;   // LPWSTR
  lpFileName: PWideChar   // LPWSTR
): Integer; stdcall;
  external 'GPEDIT.dll' name 'ImportRSoPData';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ImportRSoPData"
  c_ImportRSoPData :: CWString -> CWString -> IO Int32
-- lpNameSpace : LPWSTR -> CWString
-- lpFileName : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let importrsopdata =
  foreign "ImportRSoPData"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* lpNameSpace : LPWSTR -> (ptr uint16_t) *)
(* lpFileName : LPWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gpedit (t "GPEDIT.dll"))
(cffi:use-foreign-library gpedit)

(cffi:defcfun ("ImportRSoPData" import-rso-pdata :convention :stdcall) :int32
  (lp-name-space (:string :encoding :utf-16le))   ; LPWSTR
  (lp-file-name (:string :encoding :utf-16le)))   ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ImportRSoPData = Win32::API::More->new('GPEDIT',
    'int ImportRSoPData(LPCWSTR lpNameSpace, LPCWSTR lpFileName)');
# my $ret = $ImportRSoPData->Call($lpNameSpace, $lpFileName);
# lpNameSpace : LPWSTR -> LPCWSTR
# lpFileName : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。