Win32 API 日本語リファレンス
ホームStorage.Imapi › OpenIMsgSession

OpenIMsgSession

関数
IMessage操作用のメッセージセッションを開く。
DLLMAPI32.dll呼出規約winapi

シグネチャ

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

INT OpenIMsgSession(
    IMalloc* lpMalloc,
    DWORD ulFlags,
    LPMSGSESS* lppMsgSess
);

パラメーター

名前方向説明
lpMallocIMalloc*inメモリ確保に用いるIMallocインターフェイスへのポインタ。
ulFlagsDWORDinセッション動作を制御するフラグ。通常は0を指定する。
lppMsgSessLPMSGSESS*inout開かれたメッセージセッションのハンドルを受け取るLPMSGSESSへのポインタ。

戻り値の型: INT

各言語での呼び出し定義

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

INT OpenIMsgSession(
    IMalloc* lpMalloc,
    DWORD ulFlags,
    LPMSGSESS* lppMsgSess
);
[DllImport("MAPI32.dll", ExactSpelling = true)]
static extern int OpenIMsgSession(
    IntPtr lpMalloc,   // IMalloc*
    uint ulFlags,   // DWORD
    ref IntPtr lppMsgSess   // LPMSGSESS* in/out
);
<DllImport("MAPI32.dll", ExactSpelling:=True)>
Public Shared Function OpenIMsgSession(
    lpMalloc As IntPtr,   ' IMalloc*
    ulFlags As UInteger,   ' DWORD
    ByRef lppMsgSess As IntPtr   ' LPMSGSESS* in/out
) As Integer
End Function
' lpMalloc : IMalloc*
' ulFlags : DWORD
' lppMsgSess : LPMSGSESS* in/out
Declare PtrSafe Function OpenIMsgSession Lib "mapi32" ( _
    ByVal lpMalloc As LongPtr, _
    ByVal ulFlags As Long, _
    ByRef lppMsgSess As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

OpenIMsgSession = ctypes.windll.mapi32.OpenIMsgSession
OpenIMsgSession.restype = ctypes.c_int
OpenIMsgSession.argtypes = [
    ctypes.c_void_p,  # lpMalloc : IMalloc*
    wintypes.DWORD,  # ulFlags : DWORD
    ctypes.c_void_p,  # lppMsgSess : LPMSGSESS* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MAPI32.dll')
OpenIMsgSession = Fiddle::Function.new(
  lib['OpenIMsgSession'],
  [
    Fiddle::TYPE_VOIDP,  # lpMalloc : IMalloc*
    -Fiddle::TYPE_INT,  # ulFlags : DWORD
    Fiddle::TYPE_VOIDP,  # lppMsgSess : LPMSGSESS* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mapi32")]
extern "system" {
    fn OpenIMsgSession(
        lpMalloc: *mut core::ffi::c_void,  // IMalloc*
        ulFlags: u32,  // DWORD
        lppMsgSess: *mut isize  // LPMSGSESS* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MAPI32.dll")]
public static extern int OpenIMsgSession(IntPtr lpMalloc, uint ulFlags, ref IntPtr lppMsgSess);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MAPI32_OpenIMsgSession' -Namespace Win32 -PassThru
# $api::OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
#uselib "MAPI32.dll"
#func global OpenIMsgSession "OpenIMsgSession" sptr, sptr, sptr
; OpenIMsgSession lpMalloc, ulFlags, varptr(lppMsgSess)   ; 戻り値は stat
; lpMalloc : IMalloc* -> "sptr"
; ulFlags : DWORD -> "sptr"
; lppMsgSess : LPMSGSESS* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MAPI32.dll"
#cfunc global OpenIMsgSession "OpenIMsgSession" sptr, int, var
; res = OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
; lpMalloc : IMalloc* -> "sptr"
; ulFlags : DWORD -> "int"
; lppMsgSess : LPMSGSESS* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT OpenIMsgSession(IMalloc* lpMalloc, DWORD ulFlags, LPMSGSESS* lppMsgSess)
#uselib "MAPI32.dll"
#cfunc global OpenIMsgSession "OpenIMsgSession" intptr, int, var
; res = OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
; lpMalloc : IMalloc* -> "intptr"
; ulFlags : DWORD -> "int"
; lppMsgSess : LPMSGSESS* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mapi32 = windows.NewLazySystemDLL("MAPI32.dll")
	procOpenIMsgSession = mapi32.NewProc("OpenIMsgSession")
)

// lpMalloc (IMalloc*), ulFlags (DWORD), lppMsgSess (LPMSGSESS* in/out)
r1, _, err := procOpenIMsgSession.Call(
	uintptr(lpMalloc),
	uintptr(ulFlags),
	uintptr(lppMsgSess),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function OpenIMsgSession(
  lpMalloc: Pointer;   // IMalloc*
  ulFlags: DWORD;   // DWORD
  lppMsgSess: Pointer   // LPMSGSESS* in/out
): Integer; stdcall;
  external 'MAPI32.dll' name 'OpenIMsgSession';
result := DllCall("MAPI32\OpenIMsgSession"
    , "Ptr", lpMalloc   ; IMalloc*
    , "UInt", ulFlags   ; DWORD
    , "Ptr", lppMsgSess   ; LPMSGSESS* in/out
    , "Int")   ; return: INT
●OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess) = DLL("MAPI32.dll", "int OpenIMsgSession(void*, dword, void*)")
# 呼び出し: OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
# lpMalloc : IMalloc* -> "void*"
# ulFlags : DWORD -> "dword"
# lppMsgSess : LPMSGSESS* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mapi32" fn OpenIMsgSession(
    lpMalloc: ?*anyopaque, // IMalloc*
    ulFlags: u32, // DWORD
    lppMsgSess: [*c]isize // LPMSGSESS* in/out
) callconv(std.os.windows.WINAPI) i32;
proc OpenIMsgSession(
    lpMalloc: pointer,  # IMalloc*
    ulFlags: uint32,  # DWORD
    lppMsgSess: ptr int  # LPMSGSESS* in/out
): int32 {.importc: "OpenIMsgSession", stdcall, dynlib: "MAPI32.dll".}
pragma(lib, "mapi32");
extern(Windows)
int OpenIMsgSession(
    void* lpMalloc,   // IMalloc*
    uint ulFlags,   // DWORD
    ptrdiff_t* lppMsgSess   // LPMSGSESS* in/out
);
ccall((:OpenIMsgSession, "MAPI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{Int}),
      lpMalloc, ulFlags, lppMsgSess)
# lpMalloc : IMalloc* -> Ptr{Cvoid}
# ulFlags : DWORD -> UInt32
# lppMsgSess : LPMSGSESS* in/out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t OpenIMsgSession(
    void* lpMalloc,
    uint32_t ulFlags,
    intptr_t* lppMsgSess);
]]
local mapi32 = ffi.load("mapi32")
-- mapi32.OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
-- lpMalloc : IMalloc*
-- ulFlags : DWORD
-- lppMsgSess : LPMSGSESS* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MAPI32.dll');
const OpenIMsgSession = lib.func('__stdcall', 'OpenIMsgSession', 'int32_t', ['void *', 'uint32_t', 'intptr_t *']);
// OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
// lpMalloc : IMalloc* -> 'void *'
// ulFlags : DWORD -> 'uint32_t'
// lppMsgSess : LPMSGSESS* in/out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MAPI32.dll", {
  OpenIMsgSession: { parameters: ["pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess)
// lpMalloc : IMalloc* -> "pointer"
// ulFlags : DWORD -> "u32"
// lppMsgSess : LPMSGSESS* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t OpenIMsgSession(
    void* lpMalloc,
    uint32_t ulFlags,
    intptr_t* lppMsgSess);
C, "MAPI32.dll");
// $ffi->OpenIMsgSession(lpMalloc, ulFlags, lppMsgSess);
// lpMalloc : IMalloc*
// ulFlags : DWORD
// lppMsgSess : LPMSGSESS* in/out
// 構造体/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 Mapi32 extends StdCallLibrary {
    Mapi32 INSTANCE = Native.load("mapi32", Mapi32.class);
    int OpenIMsgSession(
        Pointer lpMalloc,   // IMalloc*
        int ulFlags,   // DWORD
        LongByReference lppMsgSess   // LPMSGSESS* in/out
    );
}
@[Link("mapi32")]
lib LibMAPI32
  fun OpenIMsgSession = OpenIMsgSession(
    lpMalloc : Void*,   # IMalloc*
    ulFlags : UInt32,   # DWORD
    lppMsgSess : LibC::SSizeT*   # LPMSGSESS* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef OpenIMsgSessionNative = Int32 Function(Pointer<Void>, Uint32, Pointer<IntPtr>);
typedef OpenIMsgSessionDart = int Function(Pointer<Void>, int, Pointer<IntPtr>);
final OpenIMsgSession = DynamicLibrary.open('MAPI32.dll')
    .lookupFunction<OpenIMsgSessionNative, OpenIMsgSessionDart>('OpenIMsgSession');
// lpMalloc : IMalloc* -> Pointer<Void>
// ulFlags : DWORD -> Uint32
// lppMsgSess : LPMSGSESS* in/out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function OpenIMsgSession(
  lpMalloc: Pointer;   // IMalloc*
  ulFlags: DWORD;   // DWORD
  lppMsgSess: Pointer   // LPMSGSESS* in/out
): Integer; stdcall;
  external 'MAPI32.dll' name 'OpenIMsgSession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "OpenIMsgSession"
  c_OpenIMsgSession :: Ptr () -> Word32 -> Ptr CIntPtr -> IO Int32
-- lpMalloc : IMalloc* -> Ptr ()
-- ulFlags : DWORD -> Word32
-- lppMsgSess : LPMSGSESS* in/out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let openimsgsession =
  foreign "OpenIMsgSession"
    ((ptr void) @-> uint32_t @-> (ptr intptr_t) @-> returning int32_t)
(* lpMalloc : IMalloc* -> (ptr void) *)
(* ulFlags : DWORD -> uint32_t *)
(* lppMsgSess : LPMSGSESS* in/out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mapi32 (t "MAPI32.dll"))
(cffi:use-foreign-library mapi32)

(cffi:defcfun ("OpenIMsgSession" open-imsg-session :convention :stdcall) :int32
  (lp-malloc :pointer)   ; IMalloc*
  (ul-flags :uint32)   ; DWORD
  (lpp-msg-sess :pointer))   ; LPMSGSESS* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $OpenIMsgSession = Win32::API::More->new('MAPI32',
    'int OpenIMsgSession(LPVOID lpMalloc, DWORD ulFlags, LPVOID lppMsgSess)');
# my $ret = $OpenIMsgSession->Call($lpMalloc, $ulFlags, $lppMsgSess);
# lpMalloc : IMalloc* -> LPVOID
# ulFlags : DWORD -> DWORD
# lppMsgSess : LPMSGSESS* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型