Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › OutputDebugStringW

OutputDebugStringW

関数
Unicode文字列をデバッガの出力に送信する。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

void OutputDebugStringW(
    LPCWSTR lpOutputString   // optional
);

パラメーター

名前方向
lpOutputStringLPCWSTRinoptional

戻り値の型: void

各言語での呼び出し定義

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

void OutputDebugStringW(
    LPCWSTR lpOutputString   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void OutputDebugStringW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpOutputString   // LPCWSTR optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub OutputDebugStringW(
    <MarshalAs(UnmanagedType.LPWStr)> lpOutputString As String   ' LPCWSTR optional
)
End Sub
' lpOutputString : LPCWSTR optional
Declare PtrSafe Sub OutputDebugStringW Lib "kernel32" ( _
    ByVal lpOutputString 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

OutputDebugStringW = ctypes.windll.kernel32.OutputDebugStringW
OutputDebugStringW.restype = None
OutputDebugStringW.argtypes = [
    wintypes.LPCWSTR,  # lpOutputString : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
OutputDebugStringW = Fiddle::Function.new(
  lib['OutputDebugStringW'],
  [
    Fiddle::TYPE_VOIDP,  # lpOutputString : LPCWSTR optional
  ],
  Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn OutputDebugStringW(
        lpOutputString: *const u16  // LPCWSTR optional
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern void OutputDebugStringW([MarshalAs(UnmanagedType.LPWStr)] string lpOutputString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_OutputDebugStringW' -Namespace Win32 -PassThru
# $api::OutputDebugStringW(lpOutputString)
#uselib "KERNEL32.dll"
#func global OutputDebugStringW "OutputDebugStringW" wptr
; OutputDebugStringW lpOutputString
; lpOutputString : LPCWSTR optional -> "wptr"
#uselib "KERNEL32.dll"
#func global OutputDebugStringW "OutputDebugStringW" wstr
; OutputDebugStringW lpOutputString
; lpOutputString : LPCWSTR optional -> "wstr"
; void OutputDebugStringW(LPCWSTR lpOutputString)
#uselib "KERNEL32.dll"
#func global OutputDebugStringW "OutputDebugStringW" wstr
; OutputDebugStringW lpOutputString
; lpOutputString : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procOutputDebugStringW = kernel32.NewProc("OutputDebugStringW")
)

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