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

GetTypeByNameA

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

シグネチャ

// MSWSOCK.dll  (ANSI / -A)
#include <windows.h>

INT GetTypeByNameA(
    LPSTR lpServiceName,
    GUID* lpServiceType
);

パラメーター

名前方向
lpServiceNameLPSTRin
lpServiceTypeGUID*inout

戻り値の型: INT

各言語での呼び出し定義

// MSWSOCK.dll  (ANSI / -A)
#include <windows.h>

INT GetTypeByNameA(
    LPSTR lpServiceName,
    GUID* lpServiceType
);
[DllImport("MSWSOCK.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int GetTypeByNameA(
    [MarshalAs(UnmanagedType.LPStr)] string lpServiceName,   // LPSTR
    ref Guid lpServiceType   // GUID* in/out
);
<DllImport("MSWSOCK.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetTypeByNameA(
    <MarshalAs(UnmanagedType.LPStr)> lpServiceName As String,   ' LPSTR
    ByRef lpServiceType As Guid   ' GUID* in/out
) As Integer
End Function
' lpServiceName : LPSTR
' lpServiceType : GUID* in/out
Declare PtrSafe Function GetTypeByNameA Lib "mswsock" ( _
    ByVal lpServiceName As String, _
    ByVal lpServiceType As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetTypeByNameA = ctypes.windll.mswsock.GetTypeByNameA
GetTypeByNameA.restype = ctypes.c_int
GetTypeByNameA.argtypes = [
    wintypes.LPCSTR,  # lpServiceName : LPSTR
    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')
GetTypeByNameA = Fiddle::Function.new(
  lib['GetTypeByNameA'],
  [
    Fiddle::TYPE_VOIDP,  # lpServiceName : LPSTR
    Fiddle::TYPE_VOIDP,  # lpServiceType : GUID* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mswsock")]
extern "system" {
    fn GetTypeByNameA(
        lpServiceName: *mut u8,  // LPSTR
        lpServiceType: *mut GUID  // GUID* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MSWSOCK.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int GetTypeByNameA([MarshalAs(UnmanagedType.LPStr)] string lpServiceName, ref Guid lpServiceType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSWSOCK_GetTypeByNameA' -Namespace Win32 -PassThru
# $api::GetTypeByNameA(lpServiceName, lpServiceType)
#uselib "MSWSOCK.dll"
#func global GetTypeByNameA "GetTypeByNameA" sptr, sptr
; GetTypeByNameA lpServiceName, varptr(lpServiceType)   ; 戻り値は stat
; lpServiceName : LPSTR -> "sptr"
; lpServiceType : GUID* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MSWSOCK.dll"
#cfunc global GetTypeByNameA "GetTypeByNameA" str, var
; res = GetTypeByNameA(lpServiceName, lpServiceType)
; lpServiceName : LPSTR -> "str"
; lpServiceType : GUID* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetTypeByNameA(LPSTR lpServiceName, GUID* lpServiceType)
#uselib "MSWSOCK.dll"
#cfunc global GetTypeByNameA "GetTypeByNameA" str, var
; res = GetTypeByNameA(lpServiceName, lpServiceType)
; lpServiceName : LPSTR -> "str"
; lpServiceType : GUID* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mswsock = windows.NewLazySystemDLL("MSWSOCK.dll")
	procGetTypeByNameA = mswsock.NewProc("GetTypeByNameA")
)

// lpServiceName (LPSTR), lpServiceType (GUID* in/out)
r1, _, err := procGetTypeByNameA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpServiceName))),
	uintptr(lpServiceType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetTypeByNameA(
  lpServiceName: PAnsiChar;   // LPSTR
  lpServiceType: PGUID   // GUID* in/out
): Integer; stdcall;
  external 'MSWSOCK.dll' name 'GetTypeByNameA';
result := DllCall("MSWSOCK\GetTypeByNameA"
    , "AStr", lpServiceName   ; LPSTR
    , "Ptr", lpServiceType   ; GUID* in/out
    , "Int")   ; return: INT
●GetTypeByNameA(lpServiceName, lpServiceType) = DLL("MSWSOCK.dll", "int GetTypeByNameA(char*, void*)")
# 呼び出し: GetTypeByNameA(lpServiceName, lpServiceType)
# lpServiceName : LPSTR -> "char*"
# lpServiceType : GUID* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。