SHSetUnreadMailCountW
関数指定アカウントの未読メール件数を設定する。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HRESULT SHSetUnreadMailCountW(
LPCWSTR pszMailAddress,
DWORD dwCount,
LPCWSTR pszShellExecuteCommand
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszMailAddress | LPCWSTR | in | 現在のユーザーの完全な電子メールアドレスを含む Unicode 文字列へのポインター。 |
| dwCount | DWORD | in | 未読メッセージの数。 |
| pszShellExecuteCommand | LPCWSTR | in | ShellExecute に渡すことができるコマンドの完全なテキストを含む Unicode 文字列へのポインター。このコマンドは、pszMailAddress で参照されるアカウントを所有する電子メールアプリケーションを起動するものである必要があります。 |
戻り値の型: HRESULT
公式ドキュメント
指定された電子メールアカウントについて、現在のユーザーの未読メッセージ数をレジストリに格納します。(Unicode)
戻り値
型: HRESULT
HRESULT。次の値を返す可能性があります。
| 戻り値コード | 説明 |
|---|---|
| 呼び出しが正常に完了しました。 | |
| 使用可能なメモリが不足しています。 | |
| pszMailAddress または pszShellExecuteCommand パラメーターのいずれかに無効な文字列引数が指定されています。 |
解説(Remarks)
この関数がレジストリを更新すると、新しいレジストリエントリには現在の時刻と日付が自動的に記録されます。
この関数が、同じ電子メール名を指定する複数の独立系ソフトウェアベンダー (ISV) によって呼び出された場合、最後の呼び出しのみが保存されます。つまり、この関数を呼び出すと、同じ電子メールアドレスに対して以前に保存された値は、たとえ異なる ISV による呼び出しであっても上書きされます。
未読メッセージ数は、ユーザーアカウントのメインの受信トレイに対してのみ設定することをお勧めします。下書きや削除済みアイテムなどのサブフォルダー内のメールは無視してください。
電子メールクライアントは、アプリケーション終了時に未読メッセージ数を 0 に設定しないことが重要です。これを行うと、未読メッセージ数が誤って 0 と報告される原因になります。
この関数は HKEY_CURRENT_USER を使用するため、ユーザーを偽装するシステムプロセスから呼び出すべきではありません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HRESULT SHSetUnreadMailCountW(
LPCWSTR pszMailAddress,
DWORD dwCount,
LPCWSTR pszShellExecuteCommand
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHSetUnreadMailCountW(
[MarshalAs(UnmanagedType.LPWStr)] string pszMailAddress, // LPCWSTR
uint dwCount, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pszShellExecuteCommand // LPCWSTR
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHSetUnreadMailCountW(
<MarshalAs(UnmanagedType.LPWStr)> pszMailAddress As String, ' LPCWSTR
dwCount As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszShellExecuteCommand As String ' LPCWSTR
) As Integer
End Function' pszMailAddress : LPCWSTR
' dwCount : DWORD
' pszShellExecuteCommand : LPCWSTR
Declare PtrSafe Function SHSetUnreadMailCountW Lib "shell32" ( _
ByVal pszMailAddress As LongPtr, _
ByVal dwCount As Long, _
ByVal pszShellExecuteCommand 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
SHSetUnreadMailCountW = ctypes.windll.shell32.SHSetUnreadMailCountW
SHSetUnreadMailCountW.restype = ctypes.c_int
SHSetUnreadMailCountW.argtypes = [
wintypes.LPCWSTR, # pszMailAddress : LPCWSTR
wintypes.DWORD, # dwCount : DWORD
wintypes.LPCWSTR, # pszShellExecuteCommand : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHSetUnreadMailCountW = Fiddle::Function.new(
lib['SHSetUnreadMailCountW'],
[
Fiddle::TYPE_VOIDP, # pszMailAddress : LPCWSTR
-Fiddle::TYPE_INT, # dwCount : DWORD
Fiddle::TYPE_VOIDP, # pszShellExecuteCommand : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn SHSetUnreadMailCountW(
pszMailAddress: *const u16, // LPCWSTR
dwCount: u32, // DWORD
pszShellExecuteCommand: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int SHSetUnreadMailCountW([MarshalAs(UnmanagedType.LPWStr)] string pszMailAddress, uint dwCount, [MarshalAs(UnmanagedType.LPWStr)] string pszShellExecuteCommand);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHSetUnreadMailCountW' -Namespace Win32 -PassThru
# $api::SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)#uselib "SHELL32.dll"
#func global SHSetUnreadMailCountW "SHSetUnreadMailCountW" wptr, wptr, wptr
; SHSetUnreadMailCountW pszMailAddress, dwCount, pszShellExecuteCommand ; 戻り値は stat
; pszMailAddress : LPCWSTR -> "wptr"
; dwCount : DWORD -> "wptr"
; pszShellExecuteCommand : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global SHSetUnreadMailCountW "SHSetUnreadMailCountW" wstr, int, wstr
; res = SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
; pszMailAddress : LPCWSTR -> "wstr"
; dwCount : DWORD -> "int"
; pszShellExecuteCommand : LPCWSTR -> "wstr"; HRESULT SHSetUnreadMailCountW(LPCWSTR pszMailAddress, DWORD dwCount, LPCWSTR pszShellExecuteCommand)
#uselib "SHELL32.dll"
#cfunc global SHSetUnreadMailCountW "SHSetUnreadMailCountW" wstr, int, wstr
; res = SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
; pszMailAddress : LPCWSTR -> "wstr"
; dwCount : DWORD -> "int"
; pszShellExecuteCommand : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHSetUnreadMailCountW = shell32.NewProc("SHSetUnreadMailCountW")
)
// pszMailAddress (LPCWSTR), dwCount (DWORD), pszShellExecuteCommand (LPCWSTR)
r1, _, err := procSHSetUnreadMailCountW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszMailAddress))),
uintptr(dwCount),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszShellExecuteCommand))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHSetUnreadMailCountW(
pszMailAddress: PWideChar; // LPCWSTR
dwCount: DWORD; // DWORD
pszShellExecuteCommand: PWideChar // LPCWSTR
): Integer; stdcall;
external 'SHELL32.dll' name 'SHSetUnreadMailCountW';result := DllCall("SHELL32\SHSetUnreadMailCountW"
, "WStr", pszMailAddress ; LPCWSTR
, "UInt", dwCount ; DWORD
, "WStr", pszShellExecuteCommand ; LPCWSTR
, "Int") ; return: HRESULT●SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand) = DLL("SHELL32.dll", "int SHSetUnreadMailCountW(char*, dword, char*)")
# 呼び出し: SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
# pszMailAddress : LPCWSTR -> "char*"
# dwCount : DWORD -> "dword"
# pszShellExecuteCommand : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "shell32" fn SHSetUnreadMailCountW(
pszMailAddress: [*c]const u16, // LPCWSTR
dwCount: u32, // DWORD
pszShellExecuteCommand: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SHSetUnreadMailCountW(
pszMailAddress: WideCString, # LPCWSTR
dwCount: uint32, # DWORD
pszShellExecuteCommand: WideCString # LPCWSTR
): int32 {.importc: "SHSetUnreadMailCountW", stdcall, dynlib: "SHELL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "shell32");
extern(Windows)
int SHSetUnreadMailCountW(
const(wchar)* pszMailAddress, // LPCWSTR
uint dwCount, // DWORD
const(wchar)* pszShellExecuteCommand // LPCWSTR
);ccall((:SHSetUnreadMailCountW, "SHELL32.dll"), stdcall, Int32,
(Cwstring, UInt32, Cwstring),
pszMailAddress, dwCount, pszShellExecuteCommand)
# pszMailAddress : LPCWSTR -> Cwstring
# dwCount : DWORD -> UInt32
# pszShellExecuteCommand : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SHSetUnreadMailCountW(
const uint16_t* pszMailAddress,
uint32_t dwCount,
const uint16_t* pszShellExecuteCommand);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
-- pszMailAddress : LPCWSTR
-- dwCount : DWORD
-- pszShellExecuteCommand : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHSetUnreadMailCountW = lib.func('__stdcall', 'SHSetUnreadMailCountW', 'int32_t', ['str16', 'uint32_t', 'str16']);
// SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
// pszMailAddress : LPCWSTR -> 'str16'
// dwCount : DWORD -> 'uint32_t'
// pszShellExecuteCommand : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHSetUnreadMailCountW: { parameters: ["buffer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand)
// pszMailAddress : LPCWSTR -> "buffer"
// dwCount : DWORD -> "u32"
// pszShellExecuteCommand : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHSetUnreadMailCountW(
const uint16_t* pszMailAddress,
uint32_t dwCount,
const uint16_t* pszShellExecuteCommand);
C, "SHELL32.dll");
// $ffi->SHSetUnreadMailCountW(pszMailAddress, dwCount, pszShellExecuteCommand);
// pszMailAddress : LPCWSTR
// dwCount : DWORD
// pszShellExecuteCommand : LPCWSTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class, W32APIOptions.UNICODE_OPTIONS);
int SHSetUnreadMailCountW(
WString pszMailAddress, // LPCWSTR
int dwCount, // DWORD
WString pszShellExecuteCommand // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("shell32")]
lib LibSHELL32
fun SHSetUnreadMailCountW = SHSetUnreadMailCountW(
pszMailAddress : UInt16*, # LPCWSTR
dwCount : UInt32, # DWORD
pszShellExecuteCommand : UInt16* # LPCWSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHSetUnreadMailCountWNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>);
typedef SHSetUnreadMailCountWDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>);
final SHSetUnreadMailCountW = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHSetUnreadMailCountWNative, SHSetUnreadMailCountWDart>('SHSetUnreadMailCountW');
// pszMailAddress : LPCWSTR -> Pointer<Utf16>
// dwCount : DWORD -> Uint32
// pszShellExecuteCommand : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHSetUnreadMailCountW(
pszMailAddress: PWideChar; // LPCWSTR
dwCount: DWORD; // DWORD
pszShellExecuteCommand: PWideChar // LPCWSTR
): Integer; stdcall;
external 'SHELL32.dll' name 'SHSetUnreadMailCountW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHSetUnreadMailCountW"
c_SHSetUnreadMailCountW :: CWString -> Word32 -> CWString -> IO Int32
-- pszMailAddress : LPCWSTR -> CWString
-- dwCount : DWORD -> Word32
-- pszShellExecuteCommand : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shsetunreadmailcountw =
foreign "SHSetUnreadMailCountW"
((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* pszMailAddress : LPCWSTR -> (ptr uint16_t) *)
(* dwCount : DWORD -> uint32_t *)
(* pszShellExecuteCommand : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHSetUnreadMailCountW" shset-unread-mail-count-w :convention :stdcall) :int32
(psz-mail-address (:string :encoding :utf-16le)) ; LPCWSTR
(dw-count :uint32) ; DWORD
(psz-shell-execute-command (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHSetUnreadMailCountW = Win32::API::More->new('SHELL32',
'int SHSetUnreadMailCountW(LPCWSTR pszMailAddress, DWORD dwCount, LPCWSTR pszShellExecuteCommand)');
# my $ret = $SHSetUnreadMailCountW->Call($pszMailAddress, $dwCount, $pszShellExecuteCommand);
# pszMailAddress : LPCWSTR -> LPCWSTR
# dwCount : DWORD -> DWORD
# pszShellExecuteCommand : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。