Win32 API 日本語リファレンス
ホームNetworking.WinSock › WSCSetApplicationCategory

WSCSetApplicationCategory

関数
アプリケーションのLSPカテゴリ許可を設定する。
DLLWS2_32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

INT WSCSetApplicationCategory(
    LPCWSTR Path,
    DWORD PathLength,
    LPCWSTR Extra,   // optional
    DWORD ExtraLength,
    DWORD PermittedLspCategories,
    DWORD* pPrevPermLspCat,   // optional
    INT* lpErrno
);

パラメーター

名前方向
PathLPCWSTRin
PathLengthDWORDin
ExtraLPCWSTRinoptional
ExtraLengthDWORDin
PermittedLspCategoriesDWORDin
pPrevPermLspCatDWORD*outoptional
lpErrnoINT*out

戻り値の型: INT

各言語での呼び出し定義

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

INT WSCSetApplicationCategory(
    LPCWSTR Path,
    DWORD PathLength,
    LPCWSTR Extra,   // optional
    DWORD ExtraLength,
    DWORD PermittedLspCategories,
    DWORD* pPrevPermLspCat,   // optional
    INT* lpErrno
);
[DllImport("WS2_32.dll", ExactSpelling = true)]
static extern int WSCSetApplicationCategory(
    [MarshalAs(UnmanagedType.LPWStr)] string Path,   // LPCWSTR
    uint PathLength,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string Extra,   // LPCWSTR optional
    uint ExtraLength,   // DWORD
    uint PermittedLspCategories,   // DWORD
    IntPtr pPrevPermLspCat,   // DWORD* optional, out
    out int lpErrno   // INT* out
);
<DllImport("WS2_32.dll", ExactSpelling:=True)>
Public Shared Function WSCSetApplicationCategory(
    <MarshalAs(UnmanagedType.LPWStr)> Path As String,   ' LPCWSTR
    PathLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> Extra As String,   ' LPCWSTR optional
    ExtraLength As UInteger,   ' DWORD
    PermittedLspCategories As UInteger,   ' DWORD
    pPrevPermLspCat As IntPtr,   ' DWORD* optional, out
    <Out> ByRef lpErrno As Integer   ' INT* out
) As Integer
End Function
' Path : LPCWSTR
' PathLength : DWORD
' Extra : LPCWSTR optional
' ExtraLength : DWORD
' PermittedLspCategories : DWORD
' pPrevPermLspCat : DWORD* optional, out
' lpErrno : INT* out
Declare PtrSafe Function WSCSetApplicationCategory Lib "ws2_32" ( _
    ByVal Path As LongPtr, _
    ByVal PathLength As Long, _
    ByVal Extra As LongPtr, _
    ByVal ExtraLength As Long, _
    ByVal PermittedLspCategories As Long, _
    ByVal pPrevPermLspCat As LongPtr, _
    ByRef lpErrno As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSCSetApplicationCategory = ctypes.windll.ws2_32.WSCSetApplicationCategory
WSCSetApplicationCategory.restype = ctypes.c_int
WSCSetApplicationCategory.argtypes = [
    wintypes.LPCWSTR,  # Path : LPCWSTR
    wintypes.DWORD,  # PathLength : DWORD
    wintypes.LPCWSTR,  # Extra : LPCWSTR optional
    wintypes.DWORD,  # ExtraLength : DWORD
    wintypes.DWORD,  # PermittedLspCategories : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pPrevPermLspCat : DWORD* optional, out
    ctypes.POINTER(ctypes.c_int),  # lpErrno : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSCSetApplicationCategory = Fiddle::Function.new(
  lib['WSCSetApplicationCategory'],
  [
    Fiddle::TYPE_VOIDP,  # Path : LPCWSTR
    -Fiddle::TYPE_INT,  # PathLength : DWORD
    Fiddle::TYPE_VOIDP,  # Extra : LPCWSTR optional
    -Fiddle::TYPE_INT,  # ExtraLength : DWORD
    -Fiddle::TYPE_INT,  # PermittedLspCategories : DWORD
    Fiddle::TYPE_VOIDP,  # pPrevPermLspCat : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # lpErrno : INT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSCSetApplicationCategory(
        Path: *const u16,  // LPCWSTR
        PathLength: u32,  // DWORD
        Extra: *const u16,  // LPCWSTR optional
        ExtraLength: u32,  // DWORD
        PermittedLspCategories: u32,  // DWORD
        pPrevPermLspCat: *mut u32,  // DWORD* optional, out
        lpErrno: *mut i32  // INT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll")]
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, IntPtr pPrevPermLspCat, out int lpErrno);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSCSetApplicationCategory' -Namespace Win32 -PassThru
# $api::WSCSetApplicationCategory(Path, PathLength, Extra, ExtraLength, PermittedLspCategories, pPrevPermLspCat, lpErrno)
#uselib "WS2_32.dll"
#func global WSCSetApplicationCategory "WSCSetApplicationCategory" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSCSetApplicationCategory Path, PathLength, Extra, ExtraLength, PermittedLspCategories, varptr(pPrevPermLspCat), varptr(lpErrno)   ; 戻り値は stat
; Path : LPCWSTR -> "sptr"
; PathLength : DWORD -> "sptr"
; Extra : LPCWSTR optional -> "sptr"
; ExtraLength : DWORD -> "sptr"
; PermittedLspCategories : DWORD -> "sptr"
; pPrevPermLspCat : DWORD* optional, out -> "sptr"
; lpErrno : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSCSetApplicationCategory "WSCSetApplicationCategory" wstr, int, wstr, int, int, var, var
; res = WSCSetApplicationCategory(Path, PathLength, Extra, ExtraLength, PermittedLspCategories, pPrevPermLspCat, lpErrno)
; Path : LPCWSTR -> "wstr"
; PathLength : DWORD -> "int"
; Extra : LPCWSTR optional -> "wstr"
; ExtraLength : DWORD -> "int"
; PermittedLspCategories : DWORD -> "int"
; pPrevPermLspCat : DWORD* optional, out -> "var"
; lpErrno : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSCSetApplicationCategory(LPCWSTR Path, DWORD PathLength, LPCWSTR Extra, DWORD ExtraLength, DWORD PermittedLspCategories, DWORD* pPrevPermLspCat, INT* lpErrno)
#uselib "WS2_32.dll"
#cfunc global WSCSetApplicationCategory "WSCSetApplicationCategory" wstr, int, wstr, int, int, var, var
; res = WSCSetApplicationCategory(Path, PathLength, Extra, ExtraLength, PermittedLspCategories, pPrevPermLspCat, lpErrno)
; Path : LPCWSTR -> "wstr"
; PathLength : DWORD -> "int"
; Extra : LPCWSTR optional -> "wstr"
; ExtraLength : DWORD -> "int"
; PermittedLspCategories : DWORD -> "int"
; pPrevPermLspCat : DWORD* optional, out -> "var"
; lpErrno : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSCSetApplicationCategory = ws2_32.NewProc("WSCSetApplicationCategory")
)

// Path (LPCWSTR), PathLength (DWORD), Extra (LPCWSTR optional), ExtraLength (DWORD), PermittedLspCategories (DWORD), pPrevPermLspCat (DWORD* optional, out), lpErrno (INT* out)
r1, _, err := procWSCSetApplicationCategory.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Path))),
	uintptr(PathLength),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Extra))),
	uintptr(ExtraLength),
	uintptr(PermittedLspCategories),
	uintptr(pPrevPermLspCat),
	uintptr(lpErrno),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSCSetApplicationCategory(
  Path: PWideChar;   // LPCWSTR
  PathLength: DWORD;   // DWORD
  Extra: PWideChar;   // LPCWSTR optional
  ExtraLength: DWORD;   // DWORD
  PermittedLspCategories: DWORD;   // DWORD
  pPrevPermLspCat: Pointer;   // DWORD* optional, out
  lpErrno: Pointer   // INT* out
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSCSetApplicationCategory';
result := DllCall("WS2_32\WSCSetApplicationCategory"
    , "WStr", Path   ; LPCWSTR
    , "UInt", PathLength   ; DWORD
    , "WStr", Extra   ; LPCWSTR optional
    , "UInt", ExtraLength   ; DWORD
    , "UInt", PermittedLspCategories   ; DWORD
    , "Ptr", pPrevPermLspCat   ; DWORD* optional, out
    , "Ptr", lpErrno   ; INT* out
    , "Int")   ; return: INT
●WSCSetApplicationCategory(Path, PathLength, Extra, ExtraLength, PermittedLspCategories, pPrevPermLspCat, lpErrno) = DLL("WS2_32.dll", "int WSCSetApplicationCategory(char*, dword, char*, dword, dword, void*, void*)")
# 呼び出し: WSCSetApplicationCategory(Path, PathLength, Extra, ExtraLength, PermittedLspCategories, pPrevPermLspCat, lpErrno)
# Path : LPCWSTR -> "char*"
# PathLength : DWORD -> "dword"
# Extra : LPCWSTR optional -> "char*"
# ExtraLength : DWORD -> "dword"
# PermittedLspCategories : DWORD -> "dword"
# pPrevPermLspCat : DWORD* optional, out -> "void*"
# lpErrno : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。