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

SHGetUnreadMailCountW

関数
指定アカウントの未読メール件数を取得する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SHGetUnreadMailCountW(
    HKEY hKeyUser,   // optional
    LPCWSTR pszMailAddress,   // optional
    DWORD* pdwCount,   // optional
    FILETIME* pFileTime,   // optional
    LPWSTR pszShellExecuteCommand,   // optional
    INT cchShellExecuteCommand
);

パラメーター

名前方向
hKeyUserHKEYinoptional
pszMailAddressLPCWSTRinoptional
pdwCountDWORD*outoptional
pFileTimeFILETIME*outoptional
pszShellExecuteCommandLPWSTRoutoptional
cchShellExecuteCommandINTin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SHGetUnreadMailCountW(
    HKEY hKeyUser,   // optional
    LPCWSTR pszMailAddress,   // optional
    DWORD* pdwCount,   // optional
    FILETIME* pFileTime,   // optional
    LPWSTR pszShellExecuteCommand,   // optional
    INT cchShellExecuteCommand
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHGetUnreadMailCountW(
    IntPtr hKeyUser,   // HKEY optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszMailAddress,   // LPCWSTR optional
    IntPtr pdwCount,   // DWORD* optional, out
    IntPtr pFileTime,   // FILETIME* optional, out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszShellExecuteCommand,   // LPWSTR optional, out
    int cchShellExecuteCommand   // INT
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHGetUnreadMailCountW(
    hKeyUser As IntPtr,   ' HKEY optional
    <MarshalAs(UnmanagedType.LPWStr)> pszMailAddress As String,   ' LPCWSTR optional
    pdwCount As IntPtr,   ' DWORD* optional, out
    pFileTime As IntPtr,   ' FILETIME* optional, out
    <MarshalAs(UnmanagedType.LPWStr)> pszShellExecuteCommand As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchShellExecuteCommand As Integer   ' INT
) As Integer
End Function
' hKeyUser : HKEY optional
' pszMailAddress : LPCWSTR optional
' pdwCount : DWORD* optional, out
' pFileTime : FILETIME* optional, out
' pszShellExecuteCommand : LPWSTR optional, out
' cchShellExecuteCommand : INT
Declare PtrSafe Function SHGetUnreadMailCountW Lib "shell32" ( _
    ByVal hKeyUser As LongPtr, _
    ByVal pszMailAddress As LongPtr, _
    ByVal pdwCount As LongPtr, _
    ByVal pFileTime As LongPtr, _
    ByVal pszShellExecuteCommand As LongPtr, _
    ByVal cchShellExecuteCommand As Long) 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

SHGetUnreadMailCountW = ctypes.windll.shell32.SHGetUnreadMailCountW
SHGetUnreadMailCountW.restype = ctypes.c_int
SHGetUnreadMailCountW.argtypes = [
    wintypes.HANDLE,  # hKeyUser : HKEY optional
    wintypes.LPCWSTR,  # pszMailAddress : LPCWSTR optional
    ctypes.POINTER(wintypes.DWORD),  # pdwCount : DWORD* optional, out
    ctypes.c_void_p,  # pFileTime : FILETIME* optional, out
    wintypes.LPWSTR,  # pszShellExecuteCommand : LPWSTR optional, out
    ctypes.c_int,  # cchShellExecuteCommand : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHGetUnreadMailCountW = Fiddle::Function.new(
  lib['SHGetUnreadMailCountW'],
  [
    Fiddle::TYPE_VOIDP,  # hKeyUser : HKEY optional
    Fiddle::TYPE_VOIDP,  # pszMailAddress : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pdwCount : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # pFileTime : FILETIME* optional, out
    Fiddle::TYPE_VOIDP,  # pszShellExecuteCommand : LPWSTR optional, out
    Fiddle::TYPE_INT,  # cchShellExecuteCommand : INT
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn SHGetUnreadMailCountW(
        hKeyUser: *mut core::ffi::c_void,  // HKEY optional
        pszMailAddress: *const u16,  // LPCWSTR optional
        pdwCount: *mut u32,  // DWORD* optional, out
        pFileTime: *mut FILETIME,  // FILETIME* optional, out
        pszShellExecuteCommand: *mut u16,  // LPWSTR optional, out
        cchShellExecuteCommand: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int SHGetUnreadMailCountW(IntPtr hKeyUser, [MarshalAs(UnmanagedType.LPWStr)] string pszMailAddress, IntPtr pdwCount, IntPtr pFileTime, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszShellExecuteCommand, int cchShellExecuteCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHGetUnreadMailCountW' -Namespace Win32 -PassThru
# $api::SHGetUnreadMailCountW(hKeyUser, pszMailAddress, pdwCount, pFileTime, pszShellExecuteCommand, cchShellExecuteCommand)
#uselib "SHELL32.dll"
#func global SHGetUnreadMailCountW "SHGetUnreadMailCountW" wptr, wptr, wptr, wptr, wptr, wptr
; SHGetUnreadMailCountW hKeyUser, pszMailAddress, varptr(pdwCount), varptr(pFileTime), varptr(pszShellExecuteCommand), cchShellExecuteCommand   ; 戻り値は stat
; hKeyUser : HKEY optional -> "wptr"
; pszMailAddress : LPCWSTR optional -> "wptr"
; pdwCount : DWORD* optional, out -> "wptr"
; pFileTime : FILETIME* optional, out -> "wptr"
; pszShellExecuteCommand : LPWSTR optional, out -> "wptr"
; cchShellExecuteCommand : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global SHGetUnreadMailCountW "SHGetUnreadMailCountW" sptr, wstr, var, var, var, int
; res = SHGetUnreadMailCountW(hKeyUser, pszMailAddress, pdwCount, pFileTime, pszShellExecuteCommand, cchShellExecuteCommand)
; hKeyUser : HKEY optional -> "sptr"
; pszMailAddress : LPCWSTR optional -> "wstr"
; pdwCount : DWORD* optional, out -> "var"
; pFileTime : FILETIME* optional, out -> "var"
; pszShellExecuteCommand : LPWSTR optional, out -> "var"
; cchShellExecuteCommand : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SHGetUnreadMailCountW(HKEY hKeyUser, LPCWSTR pszMailAddress, DWORD* pdwCount, FILETIME* pFileTime, LPWSTR pszShellExecuteCommand, INT cchShellExecuteCommand)
#uselib "SHELL32.dll"
#cfunc global SHGetUnreadMailCountW "SHGetUnreadMailCountW" intptr, wstr, var, var, var, int
; res = SHGetUnreadMailCountW(hKeyUser, pszMailAddress, pdwCount, pFileTime, pszShellExecuteCommand, cchShellExecuteCommand)
; hKeyUser : HKEY optional -> "intptr"
; pszMailAddress : LPCWSTR optional -> "wstr"
; pdwCount : DWORD* optional, out -> "var"
; pFileTime : FILETIME* optional, out -> "var"
; pszShellExecuteCommand : LPWSTR optional, out -> "var"
; cchShellExecuteCommand : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHGetUnreadMailCountW = shell32.NewProc("SHGetUnreadMailCountW")
)

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