Win32 API 日本語リファレンス
ホームSystem.Ole › LoadTypeLib

LoadTypeLib

関数
ファイルからタイプライブラリを読み込む。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT LoadTypeLib(
    LPCWSTR szFile,
    ITypeLib** pptlib
);

パラメーター

名前方向
szFileLPCWSTRin
pptlibITypeLib**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT LoadTypeLib(
    LPCWSTR szFile,
    ITypeLib** pptlib
);
[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int LoadTypeLib(
    [MarshalAs(UnmanagedType.LPWStr)] string szFile,   // LPCWSTR
    IntPtr pptlib   // ITypeLib** out
);
<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function LoadTypeLib(
    <MarshalAs(UnmanagedType.LPWStr)> szFile As String,   ' LPCWSTR
    pptlib As IntPtr   ' ITypeLib** out
) As Integer
End Function
' szFile : LPCWSTR
' pptlib : ITypeLib** out
Declare PtrSafe Function LoadTypeLib Lib "oleaut32" ( _
    ByVal szFile As LongPtr, _
    ByVal pptlib As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadTypeLib = ctypes.windll.oleaut32.LoadTypeLib
LoadTypeLib.restype = ctypes.c_int
LoadTypeLib.argtypes = [
    wintypes.LPCWSTR,  # szFile : LPCWSTR
    ctypes.c_void_p,  # pptlib : ITypeLib** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLEAUT32.dll')
LoadTypeLib = Fiddle::Function.new(
  lib['LoadTypeLib'],
  [
    Fiddle::TYPE_VOIDP,  # szFile : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pptlib : ITypeLib** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "oleaut32")]
extern "system" {
    fn LoadTypeLib(
        szFile: *const u16,  // LPCWSTR
        pptlib: *mut *mut core::ffi::c_void  // ITypeLib** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int LoadTypeLib([MarshalAs(UnmanagedType.LPWStr)] string szFile, IntPtr pptlib);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_LoadTypeLib' -Namespace Win32 -PassThru
# $api::LoadTypeLib(szFile, pptlib)
#uselib "OLEAUT32.dll"
#func global LoadTypeLib "LoadTypeLib" sptr, sptr
; LoadTypeLib szFile, pptlib   ; 戻り値は stat
; szFile : LPCWSTR -> "sptr"
; pptlib : ITypeLib** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLEAUT32.dll"
#cfunc global LoadTypeLib "LoadTypeLib" wstr, sptr
; res = LoadTypeLib(szFile, pptlib)
; szFile : LPCWSTR -> "wstr"
; pptlib : ITypeLib** out -> "sptr"
; HRESULT LoadTypeLib(LPCWSTR szFile, ITypeLib** pptlib)
#uselib "OLEAUT32.dll"
#cfunc global LoadTypeLib "LoadTypeLib" wstr, intptr
; res = LoadTypeLib(szFile, pptlib)
; szFile : LPCWSTR -> "wstr"
; pptlib : ITypeLib** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procLoadTypeLib = oleaut32.NewProc("LoadTypeLib")
)

// szFile (LPCWSTR), pptlib (ITypeLib** out)
r1, _, err := procLoadTypeLib.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFile))),
	uintptr(pptlib),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function LoadTypeLib(
  szFile: PWideChar;   // LPCWSTR
  pptlib: Pointer   // ITypeLib** out
): Integer; stdcall;
  external 'OLEAUT32.dll' name 'LoadTypeLib';
result := DllCall("OLEAUT32\LoadTypeLib"
    , "WStr", szFile   ; LPCWSTR
    , "Ptr", pptlib   ; ITypeLib** out
    , "Int")   ; return: HRESULT
●LoadTypeLib(szFile, pptlib) = DLL("OLEAUT32.dll", "int LoadTypeLib(char*, void*)")
# 呼び出し: LoadTypeLib(szFile, pptlib)
# szFile : LPCWSTR -> "char*"
# pptlib : ITypeLib** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。