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

GetTypeByNameW

関数
サービス名から対応するサービス種別GUIDを取得する。
DLLMSWSOCK.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// MSWSOCK.dll  (Unicode / -W)
#include <windows.h>

INT GetTypeByNameW(
    LPWSTR lpServiceName,
    GUID* lpServiceType
);

パラメーター

名前方向
lpServiceNameLPWSTRin
lpServiceTypeGUID*inout

戻り値の型: INT

各言語での呼び出し定義

// MSWSOCK.dll  (Unicode / -W)
#include <windows.h>

INT GetTypeByNameW(
    LPWSTR lpServiceName,
    GUID* lpServiceType
);
[DllImport("MSWSOCK.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetTypeByNameW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpServiceName,   // LPWSTR
    ref Guid lpServiceType   // GUID* in/out
);
<DllImport("MSWSOCK.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetTypeByNameW(
    <MarshalAs(UnmanagedType.LPWStr)> lpServiceName As String,   ' LPWSTR
    ByRef lpServiceType As Guid   ' GUID* in/out
) As Integer
End Function
' lpServiceName : LPWSTR
' lpServiceType : GUID* in/out
Declare PtrSafe Function GetTypeByNameW Lib "mswsock" ( _
    ByVal lpServiceName As LongPtr, _
    ByVal lpServiceType As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetTypeByNameW = ctypes.windll.mswsock.GetTypeByNameW
GetTypeByNameW.restype = ctypes.c_int
GetTypeByNameW.argtypes = [
    wintypes.LPCWSTR,  # lpServiceName : LPWSTR
    ctypes.c_void_p,  # lpServiceType : GUID* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MSWSOCK.dll')
GetTypeByNameW = Fiddle::Function.new(
  lib['GetTypeByNameW'],
  [
    Fiddle::TYPE_VOIDP,  # lpServiceName : LPWSTR
    Fiddle::TYPE_VOIDP,  # lpServiceType : GUID* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "mswsock")]
extern "system" {
    fn GetTypeByNameW(
        lpServiceName: *mut u16,  // LPWSTR
        lpServiceType: *mut GUID  // GUID* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MSWSOCK.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetTypeByNameW([MarshalAs(UnmanagedType.LPWStr)] string lpServiceName, ref Guid lpServiceType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSWSOCK_GetTypeByNameW' -Namespace Win32 -PassThru
# $api::GetTypeByNameW(lpServiceName, lpServiceType)
#uselib "MSWSOCK.dll"
#func global GetTypeByNameW "GetTypeByNameW" wptr, wptr
; GetTypeByNameW lpServiceName, varptr(lpServiceType)   ; 戻り値は stat
; lpServiceName : LPWSTR -> "wptr"
; lpServiceType : GUID* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MSWSOCK.dll"
#cfunc global GetTypeByNameW "GetTypeByNameW" wstr, var
; res = GetTypeByNameW(lpServiceName, lpServiceType)
; lpServiceName : LPWSTR -> "wstr"
; lpServiceType : GUID* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetTypeByNameW(LPWSTR lpServiceName, GUID* lpServiceType)
#uselib "MSWSOCK.dll"
#cfunc global GetTypeByNameW "GetTypeByNameW" wstr, var
; res = GetTypeByNameW(lpServiceName, lpServiceType)
; lpServiceName : LPWSTR -> "wstr"
; lpServiceType : GUID* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mswsock = windows.NewLazySystemDLL("MSWSOCK.dll")
	procGetTypeByNameW = mswsock.NewProc("GetTypeByNameW")
)

// lpServiceName (LPWSTR), lpServiceType (GUID* in/out)
r1, _, err := procGetTypeByNameW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpServiceName))),
	uintptr(lpServiceType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetTypeByNameW(
  lpServiceName: PWideChar;   // LPWSTR
  lpServiceType: PGUID   // GUID* in/out
): Integer; stdcall;
  external 'MSWSOCK.dll' name 'GetTypeByNameW';
result := DllCall("MSWSOCK\GetTypeByNameW"
    , "WStr", lpServiceName   ; LPWSTR
    , "Ptr", lpServiceType   ; GUID* in/out
    , "Int")   ; return: INT
●GetTypeByNameW(lpServiceName, lpServiceType) = DLL("MSWSOCK.dll", "int GetTypeByNameW(char*, void*)")
# 呼び出し: GetTypeByNameW(lpServiceName, lpServiceType)
# lpServiceName : LPWSTR -> "char*"
# lpServiceType : GUID* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。