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

戻り値の型: 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)。