Win32 API 日本語リファレンス
ホームData.RightsManagement › DRMAddLicense

DRMAddLicense

関数
ライセンス保存領域にライセンスを追加する。
DLLmsdrm.dll呼出規約winapi

シグネチャ

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

HRESULT DRMAddLicense(
    DWORD hLicenseStorage,
    DWORD uFlags,
    LPWSTR wszLicense
);

パラメーター

名前方向説明
hLicenseStorageDWORDin対象のライセンスストレージセッションハンドル。
uFlagsDWORDinライセンス追加動作を制御するフラグ。
wszLicenseLPWSTRin追加するライセンスを示すUnicode文字列。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

DRMAddLicense = ctypes.windll.msdrm.DRMAddLicense
DRMAddLicense.restype = ctypes.c_int
DRMAddLicense.argtypes = [
    wintypes.DWORD,  # hLicenseStorage : DWORD
    wintypes.DWORD,  # uFlags : DWORD
    wintypes.LPCWSTR,  # wszLicense : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msdrm = windows.NewLazySystemDLL("msdrm.dll")
	procDRMAddLicense = msdrm.NewProc("DRMAddLicense")
)

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

extern "msdrm" fn DRMAddLicense(
    hLicenseStorage: u32, // DWORD
    uFlags: u32, // DWORD
    wszLicense: [*c]const u16 // LPWSTR
) callconv(std.os.windows.WINAPI) i32;
proc DRMAddLicense(
    hLicenseStorage: uint32,  # DWORD
    uFlags: uint32,  # DWORD
    wszLicense: WideCString  # LPWSTR
): int32 {.importc: "DRMAddLicense", stdcall, dynlib: "msdrm.dll".}
pragma(lib, "msdrm");
extern(Windows)
int DRMAddLicense(
    uint hLicenseStorage,   // DWORD
    uint uFlags,   // DWORD
    const(wchar)* wszLicense   // LPWSTR
);
ccall((:DRMAddLicense, "msdrm.dll"), stdcall, Int32,
      (UInt32, UInt32, Cwstring),
      hLicenseStorage, uFlags, wszLicense)
# hLicenseStorage : DWORD -> UInt32
# uFlags : DWORD -> UInt32
# wszLicense : LPWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DRMAddLicense(
    uint32_t hLicenseStorage,
    uint32_t uFlags,
    const uint16_t* wszLicense);
]]
local msdrm = ffi.load("msdrm")
-- msdrm.DRMAddLicense(hLicenseStorage, uFlags, wszLicense)
-- hLicenseStorage : DWORD
-- uFlags : DWORD
-- wszLicense : LPWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msdrm.dll');
const DRMAddLicense = lib.func('__stdcall', 'DRMAddLicense', 'int32_t', ['uint32_t', 'uint32_t', 'str16']);
// DRMAddLicense(hLicenseStorage, uFlags, wszLicense)
// hLicenseStorage : DWORD -> 'uint32_t'
// uFlags : DWORD -> 'uint32_t'
// wszLicense : LPWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msdrm.dll", {
  DRMAddLicense: { parameters: ["u32", "u32", "buffer"], result: "i32" },
});
// lib.symbols.DRMAddLicense(hLicenseStorage, uFlags, wszLicense)
// hLicenseStorage : DWORD -> "u32"
// uFlags : DWORD -> "u32"
// wszLicense : LPWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DRMAddLicense(
    uint32_t hLicenseStorage,
    uint32_t uFlags,
    const uint16_t* wszLicense);
C, "msdrm.dll");
// $ffi->DRMAddLicense(hLicenseStorage, uFlags, wszLicense);
// hLicenseStorage : DWORD
// uFlags : DWORD
// wszLicense : 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 Msdrm extends StdCallLibrary {
    Msdrm INSTANCE = Native.load("msdrm", Msdrm.class);
    int DRMAddLicense(
        int hLicenseStorage,   // DWORD
        int uFlags,   // DWORD
        WString wszLicense   // LPWSTR
    );
}
@[Link("msdrm")]
lib Libmsdrm
  fun DRMAddLicense = DRMAddLicense(
    hLicenseStorage : UInt32,   # DWORD
    uFlags : UInt32,   # DWORD
    wszLicense : 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 DRMAddLicenseNative = Int32 Function(Uint32, Uint32, Pointer<Utf16>);
typedef DRMAddLicenseDart = int Function(int, int, Pointer<Utf16>);
final DRMAddLicense = DynamicLibrary.open('msdrm.dll')
    .lookupFunction<DRMAddLicenseNative, DRMAddLicenseDart>('DRMAddLicense');
// hLicenseStorage : DWORD -> Uint32
// uFlags : DWORD -> Uint32
// wszLicense : LPWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DRMAddLicense(
  hLicenseStorage: DWORD;   // DWORD
  uFlags: DWORD;   // DWORD
  wszLicense: PWideChar   // LPWSTR
): Integer; stdcall;
  external 'msdrm.dll' name 'DRMAddLicense';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DRMAddLicense"
  c_DRMAddLicense :: Word32 -> Word32 -> CWString -> IO Int32
-- hLicenseStorage : DWORD -> Word32
-- uFlags : DWORD -> Word32
-- wszLicense : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drmaddlicense =
  foreign "DRMAddLicense"
    (uint32_t @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* hLicenseStorage : DWORD -> uint32_t *)
(* uFlags : DWORD -> uint32_t *)
(* wszLicense : LPWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msdrm (t "msdrm.dll"))
(cffi:use-foreign-library msdrm)

(cffi:defcfun ("DRMAddLicense" drmadd-license :convention :stdcall) :int32
  (h-license-storage :uint32)   ; DWORD
  (u-flags :uint32)   ; DWORD
  (wsz-license (:string :encoding :utf-16le)))   ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DRMAddLicense = Win32::API::More->new('msdrm',
    'int DRMAddLicense(DWORD hLicenseStorage, DWORD uFlags, LPCWSTR wszLicense)');
# my $ret = $DRMAddLicense->Call($hLicenseStorage, $uFlags, $wszLicense);
# hLicenseStorage : DWORD -> DWORD
# uFlags : DWORD -> DWORD
# wszLicense : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。