OutputDebugStringA
関数シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
void OutputDebugStringA(
LPCSTR lpOutputString // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpOutputString | LPCSTR | inoptional | 表示する null 終端文字列です。 |
戻り値の型: void
公式ドキュメント
文字列をデバッガーに送信して表示させます。(ANSI)
解説(Remarks)
この関数を使用するには、アプリケーションに debugapi.h ではなく Windows.h ヘッダーをインクルードする必要があります。
以前、オペレーティングシステムは OutputDebugStringW を通じて Unicode 文字列を返しませんでした(代わりに ASCII 文字列が返されていました)。OutputDebugStringW に Unicode 文字列を返させるには、デバッガーは WaitForDebugEventEx 関数を呼び出して新しい動作をオプトインする必要があります。これにより、オペレーティングシステムはデバッガーが Unicode をサポートしており、Unicode 文字列の受信を明示的にオプトインしていることを認識します。
アプリケーションにデバッガーがアタッチされておらず、フィルターマスクが許可している場合は、システムデバッガーが文字列を表示します。文字列を表示するために、この関数は DbgPrint 関数を呼び出します。Windows Vista より前では、コンテンツはシステムデバッガーによってフィルター処理されませんでした。
アプリケーションにデバッガーがアタッチされておらず、システムデバッガーもアクティブでない場合、OutputDebugString は何も行いません。
OutputDebugStringW は、指定された文字列を現在のシステムロケール情報に基づいて変換し、表示のために OutputDebugStringA に渡します。その結果、一部の Unicode 文字が正しく表示されない場合があります。
アプリケーションは、ごく最小限のデバッグ出力を送信し、その使用をユーザーが有効または無効にできる手段を提供する必要があります。トレースの詳細については Event Tracing を参照してください。
Visual Studio は、そのリビジョン履歴を通じてこれらの文字列の表示方法を変更してきました。お使いのバージョンがこれをどのように扱うかについては、Visual Studio のドキュメントを参照してください。
debugapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして OutputDebugString を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致やコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
void OutputDebugStringA(
LPCSTR lpOutputString // optional
);[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern void OutputDebugStringA(
[MarshalAs(UnmanagedType.LPStr)] string lpOutputString // LPCSTR optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Sub OutputDebugStringA(
<MarshalAs(UnmanagedType.LPStr)> lpOutputString As String ' LPCSTR optional
)
End Sub' lpOutputString : LPCSTR optional
Declare PtrSafe Sub OutputDebugStringA Lib "kernel32" ( _
ByVal lpOutputString As String)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OutputDebugStringA = ctypes.windll.kernel32.OutputDebugStringA
OutputDebugStringA.restype = None
OutputDebugStringA.argtypes = [
wintypes.LPCSTR, # lpOutputString : LPCSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
OutputDebugStringA = Fiddle::Function.new(
lib['OutputDebugStringA'],
[
Fiddle::TYPE_VOIDP, # lpOutputString : LPCSTR optional
],
Fiddle::TYPE_VOID)#[link(name = "kernel32")]
extern "system" {
fn OutputDebugStringA(
lpOutputString: *const u8 // LPCSTR optional
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern void OutputDebugStringA([MarshalAs(UnmanagedType.LPStr)] string lpOutputString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_OutputDebugStringA' -Namespace Win32 -PassThru
# $api::OutputDebugStringA(lpOutputString)#uselib "KERNEL32.dll"
#func global OutputDebugStringA "OutputDebugStringA" sptr
; OutputDebugStringA lpOutputString
; lpOutputString : LPCSTR optional -> "sptr"#uselib "KERNEL32.dll"
#func global OutputDebugStringA "OutputDebugStringA" str
; OutputDebugStringA lpOutputString
; lpOutputString : LPCSTR optional -> "str"; void OutputDebugStringA(LPCSTR lpOutputString)
#uselib "KERNEL32.dll"
#func global OutputDebugStringA "OutputDebugStringA" str
; OutputDebugStringA lpOutputString
; lpOutputString : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procOutputDebugStringA = kernel32.NewProc("OutputDebugStringA")
)
// lpOutputString (LPCSTR optional)
r1, _, err := procOutputDebugStringA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpOutputString))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure OutputDebugStringA(
lpOutputString: PAnsiChar // LPCSTR optional
); stdcall;
external 'KERNEL32.dll' name 'OutputDebugStringA';result := DllCall("KERNEL32\OutputDebugStringA"
, "AStr", lpOutputString ; LPCSTR optional
, "Int") ; return: void●OutputDebugStringA(lpOutputString) = DLL("KERNEL32.dll", "int OutputDebugStringA(char*)")
# 呼び出し: OutputDebugStringA(lpOutputString)
# lpOutputString : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn OutputDebugStringA(
lpOutputString: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) void;proc OutputDebugStringA(
lpOutputString: cstring # LPCSTR optional
) {.importc: "OutputDebugStringA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
void OutputDebugStringA(
const(char)* lpOutputString // LPCSTR optional
);ccall((:OutputDebugStringA, "KERNEL32.dll"), stdcall, Cvoid,
(Cstring,),
lpOutputString)
# lpOutputString : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void OutputDebugStringA(
const char* lpOutputString);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.OutputDebugStringA(lpOutputString)
-- lpOutputString : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const OutputDebugStringA = lib.func('__stdcall', 'OutputDebugStringA', 'void', ['str']);
// OutputDebugStringA(lpOutputString)
// lpOutputString : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
OutputDebugStringA: { parameters: ["buffer"], result: "void" },
});
// lib.symbols.OutputDebugStringA(lpOutputString)
// lpOutputString : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void OutputDebugStringA(
const char* lpOutputString);
C, "KERNEL32.dll");
// $ffi->OutputDebugStringA(lpOutputString);
// lpOutputString : LPCSTR optional
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.ASCII_OPTIONS);
void OutputDebugStringA(
String lpOutputString // LPCSTR optional
);
}@[Link("kernel32")]
lib LibKERNEL32
fun OutputDebugStringA = OutputDebugStringA(
lpOutputString : UInt8* # LPCSTR optional
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OutputDebugStringANative = Void Function(Pointer<Utf8>);
typedef OutputDebugStringADart = void Function(Pointer<Utf8>);
final OutputDebugStringA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<OutputDebugStringANative, OutputDebugStringADart>('OutputDebugStringA');
// lpOutputString : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure OutputDebugStringA(
lpOutputString: PAnsiChar // LPCSTR optional
); stdcall;
external 'KERNEL32.dll' name 'OutputDebugStringA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OutputDebugStringA"
c_OutputDebugStringA :: CString -> IO ()
-- lpOutputString : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let outputdebugstringa =
foreign "OutputDebugStringA"
(string @-> returning void)
(* lpOutputString : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("OutputDebugStringA" output-debug-string-a :convention :stdcall) :void
(lp-output-string :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OutputDebugStringA = Win32::API::More->new('KERNEL32',
'void OutputDebugStringA(LPCSTR lpOutputString)');
# my $ret = $OutputDebugStringA->Call($lpOutputString);
# lpOutputString : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f OutputDebugStringW (Unicode版) — Unicode文字列をデバッガの出力に送信する。