HlinkCreateShortcut
関数ハイパーリンクからショートカットファイルを作成する。
シグネチャ
// hlink.dll
#include <windows.h>
HRESULT HlinkCreateShortcut(
DWORD grfHLSHORTCUTF,
IHlink* pihl,
LPCWSTR pwzDir,
LPCWSTR pwzFileName,
LPWSTR* ppwzShortcutFile,
DWORD dwReserved
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| grfHLSHORTCUTF | DWORD | in |
| pihl | IHlink* | in |
| pwzDir | LPCWSTR | in |
| pwzFileName | LPCWSTR | in |
| ppwzShortcutFile | LPWSTR* | out |
| dwReserved | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// hlink.dll
#include <windows.h>
HRESULT HlinkCreateShortcut(
DWORD grfHLSHORTCUTF,
IHlink* pihl,
LPCWSTR pwzDir,
LPCWSTR pwzFileName,
LPWSTR* ppwzShortcutFile,
DWORD dwReserved
);[DllImport("hlink.dll", ExactSpelling = true)]
static extern int HlinkCreateShortcut(
uint grfHLSHORTCUTF, // DWORD
IntPtr pihl, // IHlink*
[MarshalAs(UnmanagedType.LPWStr)] string pwzDir, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pwzFileName, // LPCWSTR
IntPtr ppwzShortcutFile, // LPWSTR* out
uint dwReserved // DWORD
);<DllImport("hlink.dll", ExactSpelling:=True)>
Public Shared Function HlinkCreateShortcut(
grfHLSHORTCUTF As UInteger, ' DWORD
pihl As IntPtr, ' IHlink*
<MarshalAs(UnmanagedType.LPWStr)> pwzDir As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pwzFileName As String, ' LPCWSTR
ppwzShortcutFile As IntPtr, ' LPWSTR* out
dwReserved As UInteger ' DWORD
) As Integer
End Function' grfHLSHORTCUTF : DWORD
' pihl : IHlink*
' pwzDir : LPCWSTR
' pwzFileName : LPCWSTR
' ppwzShortcutFile : LPWSTR* out
' dwReserved : DWORD
Declare PtrSafe Function HlinkCreateShortcut Lib "hlink" ( _
ByVal grfHLSHORTCUTF As Long, _
ByVal pihl As LongPtr, _
ByVal pwzDir As LongPtr, _
ByVal pwzFileName As LongPtr, _
ByVal ppwzShortcutFile As LongPtr, _
ByVal dwReserved As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
HlinkCreateShortcut = ctypes.windll.hlink.HlinkCreateShortcut
HlinkCreateShortcut.restype = ctypes.c_int
HlinkCreateShortcut.argtypes = [
wintypes.DWORD, # grfHLSHORTCUTF : DWORD
ctypes.c_void_p, # pihl : IHlink*
wintypes.LPCWSTR, # pwzDir : LPCWSTR
wintypes.LPCWSTR, # pwzFileName : LPCWSTR
ctypes.c_void_p, # ppwzShortcutFile : LPWSTR* out
wintypes.DWORD, # dwReserved : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('hlink.dll')
HlinkCreateShortcut = Fiddle::Function.new(
lib['HlinkCreateShortcut'],
[
-Fiddle::TYPE_INT, # grfHLSHORTCUTF : DWORD
Fiddle::TYPE_VOIDP, # pihl : IHlink*
Fiddle::TYPE_VOIDP, # pwzDir : LPCWSTR
Fiddle::TYPE_VOIDP, # pwzFileName : LPCWSTR
Fiddle::TYPE_VOIDP, # ppwzShortcutFile : LPWSTR* out
-Fiddle::TYPE_INT, # dwReserved : DWORD
],
Fiddle::TYPE_INT)#[link(name = "hlink")]
extern "system" {
fn HlinkCreateShortcut(
grfHLSHORTCUTF: u32, // DWORD
pihl: *mut core::ffi::c_void, // IHlink*
pwzDir: *const u16, // LPCWSTR
pwzFileName: *const u16, // LPCWSTR
ppwzShortcutFile: *mut *mut u16, // LPWSTR* out
dwReserved: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("hlink.dll")]
public static extern int HlinkCreateShortcut(uint grfHLSHORTCUTF, IntPtr pihl, [MarshalAs(UnmanagedType.LPWStr)] string pwzDir, [MarshalAs(UnmanagedType.LPWStr)] string pwzFileName, IntPtr ppwzShortcutFile, uint dwReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'hlink_HlinkCreateShortcut' -Namespace Win32 -PassThru
# $api::HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, ppwzShortcutFile, dwReserved)#uselib "hlink.dll"
#func global HlinkCreateShortcut "HlinkCreateShortcut" sptr, sptr, sptr, sptr, sptr, sptr
; HlinkCreateShortcut grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, varptr(ppwzShortcutFile), dwReserved ; 戻り値は stat
; grfHLSHORTCUTF : DWORD -> "sptr"
; pihl : IHlink* -> "sptr"
; pwzDir : LPCWSTR -> "sptr"
; pwzFileName : LPCWSTR -> "sptr"
; ppwzShortcutFile : LPWSTR* out -> "sptr"
; dwReserved : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "hlink.dll" #cfunc global HlinkCreateShortcut "HlinkCreateShortcut" int, sptr, wstr, wstr, var, int ; res = HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, ppwzShortcutFile, dwReserved) ; grfHLSHORTCUTF : DWORD -> "int" ; pihl : IHlink* -> "sptr" ; pwzDir : LPCWSTR -> "wstr" ; pwzFileName : LPCWSTR -> "wstr" ; ppwzShortcutFile : LPWSTR* out -> "var" ; dwReserved : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "hlink.dll" #cfunc global HlinkCreateShortcut "HlinkCreateShortcut" int, sptr, wstr, wstr, sptr, int ; res = HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, varptr(ppwzShortcutFile), dwReserved) ; grfHLSHORTCUTF : DWORD -> "int" ; pihl : IHlink* -> "sptr" ; pwzDir : LPCWSTR -> "wstr" ; pwzFileName : LPCWSTR -> "wstr" ; ppwzShortcutFile : LPWSTR* out -> "sptr" ; dwReserved : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT HlinkCreateShortcut(DWORD grfHLSHORTCUTF, IHlink* pihl, LPCWSTR pwzDir, LPCWSTR pwzFileName, LPWSTR* ppwzShortcutFile, DWORD dwReserved) #uselib "hlink.dll" #cfunc global HlinkCreateShortcut "HlinkCreateShortcut" int, intptr, wstr, wstr, var, int ; res = HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, ppwzShortcutFile, dwReserved) ; grfHLSHORTCUTF : DWORD -> "int" ; pihl : IHlink* -> "intptr" ; pwzDir : LPCWSTR -> "wstr" ; pwzFileName : LPCWSTR -> "wstr" ; ppwzShortcutFile : LPWSTR* out -> "var" ; dwReserved : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT HlinkCreateShortcut(DWORD grfHLSHORTCUTF, IHlink* pihl, LPCWSTR pwzDir, LPCWSTR pwzFileName, LPWSTR* ppwzShortcutFile, DWORD dwReserved) #uselib "hlink.dll" #cfunc global HlinkCreateShortcut "HlinkCreateShortcut" int, intptr, wstr, wstr, intptr, int ; res = HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, varptr(ppwzShortcutFile), dwReserved) ; grfHLSHORTCUTF : DWORD -> "int" ; pihl : IHlink* -> "intptr" ; pwzDir : LPCWSTR -> "wstr" ; pwzFileName : LPCWSTR -> "wstr" ; ppwzShortcutFile : LPWSTR* out -> "intptr" ; dwReserved : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
hlink = windows.NewLazySystemDLL("hlink.dll")
procHlinkCreateShortcut = hlink.NewProc("HlinkCreateShortcut")
)
// grfHLSHORTCUTF (DWORD), pihl (IHlink*), pwzDir (LPCWSTR), pwzFileName (LPCWSTR), ppwzShortcutFile (LPWSTR* out), dwReserved (DWORD)
r1, _, err := procHlinkCreateShortcut.Call(
uintptr(grfHLSHORTCUTF),
uintptr(pihl),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzDir))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzFileName))),
uintptr(ppwzShortcutFile),
uintptr(dwReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction HlinkCreateShortcut(
grfHLSHORTCUTF: DWORD; // DWORD
pihl: Pointer; // IHlink*
pwzDir: PWideChar; // LPCWSTR
pwzFileName: PWideChar; // LPCWSTR
ppwzShortcutFile: PPWideChar; // LPWSTR* out
dwReserved: DWORD // DWORD
): Integer; stdcall;
external 'hlink.dll' name 'HlinkCreateShortcut';result := DllCall("hlink\HlinkCreateShortcut"
, "UInt", grfHLSHORTCUTF ; DWORD
, "Ptr", pihl ; IHlink*
, "WStr", pwzDir ; LPCWSTR
, "WStr", pwzFileName ; LPCWSTR
, "Ptr", ppwzShortcutFile ; LPWSTR* out
, "UInt", dwReserved ; DWORD
, "Int") ; return: HRESULT●HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, ppwzShortcutFile, dwReserved) = DLL("hlink.dll", "int HlinkCreateShortcut(dword, void*, char*, char*, void*, dword)")
# 呼び出し: HlinkCreateShortcut(grfHLSHORTCUTF, pihl, pwzDir, pwzFileName, ppwzShortcutFile, dwReserved)
# grfHLSHORTCUTF : DWORD -> "dword"
# pihl : IHlink* -> "void*"
# pwzDir : LPCWSTR -> "char*"
# pwzFileName : LPCWSTR -> "char*"
# ppwzShortcutFile : LPWSTR* out -> "void*"
# dwReserved : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。