Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › LoadMenuW

LoadMenuW

関数
リソースからメニューを読み込みハンドルを返す(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HMENU LoadMenuW(
    HINSTANCE hInstance,   // optional
    LPCWSTR lpMenuName
);

パラメーター

名前方向
hInstanceHINSTANCEinoptional
lpMenuNameLPCWSTRin

戻り値の型: HMENU

各言語での呼び出し定義

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

HMENU LoadMenuW(
    HINSTANCE hInstance,   // optional
    LPCWSTR lpMenuName
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr LoadMenuW(
    IntPtr hInstance,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpMenuName   // LPCWSTR
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadMenuW(
    hInstance As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> lpMenuName As String   ' LPCWSTR
) As IntPtr
End Function
' hInstance : HINSTANCE optional
' lpMenuName : LPCWSTR
Declare PtrSafe Function LoadMenuW Lib "user32" ( _
    ByVal hInstance As LongPtr, _
    ByVal lpMenuName As LongPtr) As LongPtr
' 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

LoadMenuW = ctypes.windll.user32.LoadMenuW
LoadMenuW.restype = ctypes.c_void_p
LoadMenuW.argtypes = [
    wintypes.HANDLE,  # hInstance : HINSTANCE optional
    wintypes.LPCWSTR,  # lpMenuName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
LoadMenuW = Fiddle::Function.new(
  lib['LoadMenuW'],
  [
    Fiddle::TYPE_VOIDP,  # hInstance : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # lpMenuName : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn LoadMenuW(
        hInstance: *mut core::ffi::c_void,  // HINSTANCE optional
        lpMenuName: *const u16  // LPCWSTR
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadMenuW(IntPtr hInstance, [MarshalAs(UnmanagedType.LPWStr)] string lpMenuName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_LoadMenuW' -Namespace Win32 -PassThru
# $api::LoadMenuW(hInstance, lpMenuName)
#uselib "USER32.dll"
#func global LoadMenuW "LoadMenuW" wptr, wptr
; LoadMenuW hInstance, lpMenuName   ; 戻り値は stat
; hInstance : HINSTANCE optional -> "wptr"
; lpMenuName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global LoadMenuW "LoadMenuW" sptr, wstr
; res = LoadMenuW(hInstance, lpMenuName)
; hInstance : HINSTANCE optional -> "sptr"
; lpMenuName : LPCWSTR -> "wstr"
; HMENU LoadMenuW(HINSTANCE hInstance, LPCWSTR lpMenuName)
#uselib "USER32.dll"
#cfunc global LoadMenuW "LoadMenuW" intptr, wstr
; res = LoadMenuW(hInstance, lpMenuName)
; hInstance : HINSTANCE optional -> "intptr"
; lpMenuName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procLoadMenuW = user32.NewProc("LoadMenuW")
)

// hInstance (HINSTANCE optional), lpMenuName (LPCWSTR)
r1, _, err := procLoadMenuW.Call(
	uintptr(hInstance),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpMenuName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HMENU
function LoadMenuW(
  hInstance: THandle;   // HINSTANCE optional
  lpMenuName: PWideChar   // LPCWSTR
): THandle; stdcall;
  external 'USER32.dll' name 'LoadMenuW';
result := DllCall("USER32\LoadMenuW"
    , "Ptr", hInstance   ; HINSTANCE optional
    , "WStr", lpMenuName   ; LPCWSTR
    , "Ptr")   ; return: HMENU
●LoadMenuW(hInstance, lpMenuName) = DLL("USER32.dll", "void* LoadMenuW(void*, char*)")
# 呼び出し: LoadMenuW(hInstance, lpMenuName)
# hInstance : HINSTANCE optional -> "void*"
# lpMenuName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。