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

SymGetSymbolFile

関数
イメージに対応するシンボルファイルを検索取得する。
DLLdbghelp.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり

シグネチャ

// dbghelp.dll  (ANSI / -A)
#include <windows.h>

BOOL SymGetSymbolFile(
    HANDLE hProcess,   // optional
    LPCSTR SymPath,   // optional
    LPCSTR ImageFile,
    DWORD Type,
    LPSTR SymbolFile,
    UINT_PTR cSymbolFile,
    LPSTR DbgFile,
    UINT_PTR cDbgFile
);

パラメーター

名前方向説明
hProcessHANDLEinoptional

元々 SymInitialize 関数に渡されたプロセスのハンドル。

このハンドルが 0 の場合、SymPathNULL にすることはできません。SymInitializeSymCleanup を呼び出さずにシンボルファイルを読み込むには、このオプションを使用します。

SymPathLPCSTRinoptionalシンボルパス。このパラメーターが NULL または空の文字列の場合、関数は SymInitialize または SymSetSearchPath 関数で設定されたシンボルパスを使用します。
ImageFileLPCSTRinイメージファイルの名前。
TypeDWORDin

シンボルファイルの種類。このパラメーターには次のいずれかの値を指定できます。

意味
sfImage
0
.exe または .dll ファイル。
sfDbg
1
.dbg ファイル。
sfPdb
2
.pdb ファイル。
sfMpd
3
予約済み。
SymbolFileLPSTRoutシンボルファイルの名前を受け取る、null で終わる文字列へのポインター。
cSymbolFileUINT_PTRinSymbolFile バッファーのサイズ (文字数単位)。
DbgFileLPSTRoutシンボルファイルへの完全修飾パスを受け取るバッファーへのポインター。このバッファーは少なくとも MAX_PATH 文字分の大きさが必要です。
cDbgFileUINT_PTRinDbgFile バッファーのサイズ (文字数単位)。

戻り値の型: BOOL

公式ドキュメント

SymGetSymbolFile 関数 (dbghelp.h) は、指定されたシンボルパス内のシンボルファイルを検索します。

戻り値

サーバーが有効なシンボルファイルを検出した場合は TRUE を返します。それ以外の場合は FALSE を返し、 GetLastError がシンボルファイルが返されなかった理由を示す値を返します。

解説(Remarks)

この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損を引き起こす可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。

この関数の Unicode バージョンを呼び出すには、DBGHELP_TRANSLATE_TCHAR を定義します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// dbghelp.dll  (ANSI / -A)
#include <windows.h>

BOOL SymGetSymbolFile(
    HANDLE hProcess,   // optional
    LPCSTR SymPath,   // optional
    LPCSTR ImageFile,
    DWORD Type,
    LPSTR SymbolFile,
    UINT_PTR cSymbolFile,
    LPSTR DbgFile,
    UINT_PTR cDbgFile
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SymGetSymbolFile(
    IntPtr hProcess,   // HANDLE optional
    [MarshalAs(UnmanagedType.LPStr)] string SymPath,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string ImageFile,   // LPCSTR
    uint Type,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder SymbolFile,   // LPSTR out
    UIntPtr cSymbolFile,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DbgFile,   // LPSTR out
    UIntPtr cDbgFile   // UINT_PTR
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymGetSymbolFile(
    hProcess As IntPtr,   ' HANDLE optional
    <MarshalAs(UnmanagedType.LPStr)> SymPath As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> ImageFile As String,   ' LPCSTR
    Type As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> SymbolFile As System.Text.StringBuilder,   ' LPSTR out
    cSymbolFile As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPStr)> DbgFile As System.Text.StringBuilder,   ' LPSTR out
    cDbgFile As UIntPtr   ' UINT_PTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hProcess : HANDLE optional
' SymPath : LPCSTR optional
' ImageFile : LPCSTR
' Type : DWORD
' SymbolFile : LPSTR out
' cSymbolFile : UINT_PTR
' DbgFile : LPSTR out
' cDbgFile : UINT_PTR
Declare PtrSafe Function SymGetSymbolFile Lib "dbghelp" ( _
    ByVal hProcess As LongPtr, _
    ByVal SymPath As String, _
    ByVal ImageFile As String, _
    ByVal Type As Long, _
    ByVal SymbolFile As String, _
    ByVal cSymbolFile As LongPtr, _
    ByVal DbgFile As String, _
    ByVal cDbgFile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SymGetSymbolFile = ctypes.windll.dbghelp.SymGetSymbolFile
SymGetSymbolFile.restype = wintypes.BOOL
SymGetSymbolFile.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE optional
    wintypes.LPCSTR,  # SymPath : LPCSTR optional
    wintypes.LPCSTR,  # ImageFile : LPCSTR
    wintypes.DWORD,  # Type : DWORD
    wintypes.LPSTR,  # SymbolFile : LPSTR out
    ctypes.c_size_t,  # cSymbolFile : UINT_PTR
    wintypes.LPSTR,  # DbgFile : LPSTR out
    ctypes.c_size_t,  # cDbgFile : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SymGetSymbolFile = Fiddle::Function.new(
  lib['SymGetSymbolFile'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE optional
    Fiddle::TYPE_VOIDP,  # SymPath : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # ImageFile : LPCSTR
    -Fiddle::TYPE_INT,  # Type : DWORD
    Fiddle::TYPE_VOIDP,  # SymbolFile : LPSTR out
    Fiddle::TYPE_UINTPTR_T,  # cSymbolFile : UINT_PTR
    Fiddle::TYPE_VOIDP,  # DbgFile : LPSTR out
    Fiddle::TYPE_UINTPTR_T,  # cDbgFile : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "dbghelp")]
extern "system" {
    fn SymGetSymbolFile(
        hProcess: *mut core::ffi::c_void,  // HANDLE optional
        SymPath: *const u8,  // LPCSTR optional
        ImageFile: *const u8,  // LPCSTR
        Type: u32,  // DWORD
        SymbolFile: *mut u8,  // LPSTR out
        cSymbolFile: usize,  // UINT_PTR
        DbgFile: *mut u8,  // LPSTR out
        cDbgFile: usize  // UINT_PTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SymGetSymbolFile(IntPtr hProcess, [MarshalAs(UnmanagedType.LPStr)] string SymPath, [MarshalAs(UnmanagedType.LPStr)] string ImageFile, uint Type, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder SymbolFile, UIntPtr cSymbolFile, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DbgFile, UIntPtr cDbgFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymGetSymbolFile' -Namespace Win32 -PassThru
# $api::SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
#uselib "dbghelp.dll"
#func global SymGetSymbolFile "SymGetSymbolFile" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SymGetSymbolFile hProcess, SymPath, ImageFile, Type, varptr(SymbolFile), cSymbolFile, varptr(DbgFile), cDbgFile   ; 戻り値は stat
; hProcess : HANDLE optional -> "sptr"
; SymPath : LPCSTR optional -> "sptr"
; ImageFile : LPCSTR -> "sptr"
; Type : DWORD -> "sptr"
; SymbolFile : LPSTR out -> "sptr"
; cSymbolFile : UINT_PTR -> "sptr"
; DbgFile : LPSTR out -> "sptr"
; cDbgFile : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dbghelp.dll"
#cfunc global SymGetSymbolFile "SymGetSymbolFile" sptr, str, str, int, var, sptr, var, sptr
; res = SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
; hProcess : HANDLE optional -> "sptr"
; SymPath : LPCSTR optional -> "str"
; ImageFile : LPCSTR -> "str"
; Type : DWORD -> "int"
; SymbolFile : LPSTR out -> "var"
; cSymbolFile : UINT_PTR -> "sptr"
; DbgFile : LPSTR out -> "var"
; cDbgFile : UINT_PTR -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SymGetSymbolFile(HANDLE hProcess, LPCSTR SymPath, LPCSTR ImageFile, DWORD Type, LPSTR SymbolFile, UINT_PTR cSymbolFile, LPSTR DbgFile, UINT_PTR cDbgFile)
#uselib "dbghelp.dll"
#cfunc global SymGetSymbolFile "SymGetSymbolFile" intptr, str, str, int, var, intptr, var, intptr
; res = SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
; hProcess : HANDLE optional -> "intptr"
; SymPath : LPCSTR optional -> "str"
; ImageFile : LPCSTR -> "str"
; Type : DWORD -> "int"
; SymbolFile : LPSTR out -> "var"
; cSymbolFile : UINT_PTR -> "intptr"
; DbgFile : LPSTR out -> "var"
; cDbgFile : UINT_PTR -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSymGetSymbolFile = dbghelp.NewProc("SymGetSymbolFile")
)

// hProcess (HANDLE optional), SymPath (LPCSTR optional), ImageFile (LPCSTR), Type (DWORD), SymbolFile (LPSTR out), cSymbolFile (UINT_PTR), DbgFile (LPSTR out), cDbgFile (UINT_PTR)
r1, _, err := procSymGetSymbolFile.Call(
	uintptr(hProcess),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SymPath))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ImageFile))),
	uintptr(Type),
	uintptr(SymbolFile),
	uintptr(cSymbolFile),
	uintptr(DbgFile),
	uintptr(cDbgFile),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SymGetSymbolFile(
  hProcess: THandle;   // HANDLE optional
  SymPath: PAnsiChar;   // LPCSTR optional
  ImageFile: PAnsiChar;   // LPCSTR
  Type: DWORD;   // DWORD
  SymbolFile: PAnsiChar;   // LPSTR out
  cSymbolFile: NativeUInt;   // UINT_PTR
  DbgFile: PAnsiChar;   // LPSTR out
  cDbgFile: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SymGetSymbolFile';
result := DllCall("dbghelp\SymGetSymbolFile"
    , "Ptr", hProcess   ; HANDLE optional
    , "AStr", SymPath   ; LPCSTR optional
    , "AStr", ImageFile   ; LPCSTR
    , "UInt", Type   ; DWORD
    , "Ptr", SymbolFile   ; LPSTR out
    , "UPtr", cSymbolFile   ; UINT_PTR
    , "Ptr", DbgFile   ; LPSTR out
    , "UPtr", cDbgFile   ; UINT_PTR
    , "Int")   ; return: BOOL
●SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile) = DLL("dbghelp.dll", "bool SymGetSymbolFile(void*, char*, char*, dword, char*, int, char*, int)")
# 呼び出し: SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
# hProcess : HANDLE optional -> "void*"
# SymPath : LPCSTR optional -> "char*"
# ImageFile : LPCSTR -> "char*"
# Type : DWORD -> "dword"
# SymbolFile : LPSTR out -> "char*"
# cSymbolFile : UINT_PTR -> "int"
# DbgFile : LPSTR out -> "char*"
# cDbgFile : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "dbghelp" fn SymGetSymbolFile(
    hProcess: ?*anyopaque, // HANDLE optional
    SymPath: [*c]const u8, // LPCSTR optional
    ImageFile: [*c]const u8, // LPCSTR
    Type: u32, // DWORD
    SymbolFile: [*c]u8, // LPSTR out
    cSymbolFile: usize, // UINT_PTR
    DbgFile: [*c]u8, // LPSTR out
    cDbgFile: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;
proc SymGetSymbolFile(
    hProcess: pointer,  # HANDLE optional
    SymPath: cstring,  # LPCSTR optional
    ImageFile: cstring,  # LPCSTR
    Type: uint32,  # DWORD
    SymbolFile: ptr char,  # LPSTR out
    cSymbolFile: uint,  # UINT_PTR
    DbgFile: ptr char,  # LPSTR out
    cDbgFile: uint  # UINT_PTR
): int32 {.importc: "SymGetSymbolFile", stdcall, dynlib: "dbghelp.dll".}
pragma(lib, "dbghelp");
extern(Windows)
int SymGetSymbolFile(
    void* hProcess,   // HANDLE optional
    const(char)* SymPath,   // LPCSTR optional
    const(char)* ImageFile,   // LPCSTR
    uint Type,   // DWORD
    char* SymbolFile,   // LPSTR out
    size_t cSymbolFile,   // UINT_PTR
    char* DbgFile,   // LPSTR out
    size_t cDbgFile   // UINT_PTR
);
ccall((:SymGetSymbolFile, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, Cstring, UInt32, Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t),
      hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
# hProcess : HANDLE optional -> Ptr{Cvoid}
# SymPath : LPCSTR optional -> Cstring
# ImageFile : LPCSTR -> Cstring
# Type : DWORD -> UInt32
# SymbolFile : LPSTR out -> Ptr{UInt8}
# cSymbolFile : UINT_PTR -> Csize_t
# DbgFile : LPSTR out -> Ptr{UInt8}
# cDbgFile : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SymGetSymbolFile(
    void* hProcess,
    const char* SymPath,
    const char* ImageFile,
    uint32_t Type,
    char* SymbolFile,
    uintptr_t cSymbolFile,
    char* DbgFile,
    uintptr_t cDbgFile);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
-- hProcess : HANDLE optional
-- SymPath : LPCSTR optional
-- ImageFile : LPCSTR
-- Type : DWORD
-- SymbolFile : LPSTR out
-- cSymbolFile : UINT_PTR
-- DbgFile : LPSTR out
-- cDbgFile : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const SymGetSymbolFile = lib.func('__stdcall', 'SymGetSymbolFile', 'int32_t', ['void *', 'str', 'str', 'uint32_t', 'char *', 'uintptr_t', 'char *', 'uintptr_t']);
// SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
// hProcess : HANDLE optional -> 'void *'
// SymPath : LPCSTR optional -> 'str'
// ImageFile : LPCSTR -> 'str'
// Type : DWORD -> 'uint32_t'
// SymbolFile : LPSTR out -> 'char *'
// cSymbolFile : UINT_PTR -> 'uintptr_t'
// DbgFile : LPSTR out -> 'char *'
// cDbgFile : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  SymGetSymbolFile: { parameters: ["pointer", "buffer", "buffer", "u32", "buffer", "usize", "buffer", "usize"], result: "i32" },
});
// lib.symbols.SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile)
// hProcess : HANDLE optional -> "pointer"
// SymPath : LPCSTR optional -> "buffer"
// ImageFile : LPCSTR -> "buffer"
// Type : DWORD -> "u32"
// SymbolFile : LPSTR out -> "buffer"
// cSymbolFile : UINT_PTR -> "usize"
// DbgFile : LPSTR out -> "buffer"
// cDbgFile : UINT_PTR -> "usize"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SymGetSymbolFile(
    void* hProcess,
    const char* SymPath,
    const char* ImageFile,
    uint32_t Type,
    char* SymbolFile,
    size_t cSymbolFile,
    char* DbgFile,
    size_t cDbgFile);
C, "dbghelp.dll");
// $ffi->SymGetSymbolFile(hProcess, SymPath, ImageFile, Type, SymbolFile, cSymbolFile, DbgFile, cDbgFile);
// hProcess : HANDLE optional
// SymPath : LPCSTR optional
// ImageFile : LPCSTR
// Type : DWORD
// SymbolFile : LPSTR out
// cSymbolFile : UINT_PTR
// DbgFile : LPSTR out
// cDbgFile : UINT_PTR
// 構造体/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 Dbghelp extends StdCallLibrary {
    Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class, W32APIOptions.ASCII_OPTIONS);
    boolean SymGetSymbolFile(
        Pointer hProcess,   // HANDLE optional
        String SymPath,   // LPCSTR optional
        String ImageFile,   // LPCSTR
        int Type,   // DWORD
        byte[] SymbolFile,   // LPSTR out
        long cSymbolFile,   // UINT_PTR
        byte[] DbgFile,   // LPSTR out
        long cDbgFile   // UINT_PTR
    );
}
@[Link("dbghelp")]
lib Libdbghelp
  fun SymGetSymbolFile = SymGetSymbolFile(
    hProcess : Void*,   # HANDLE optional
    SymPath : UInt8*,   # LPCSTR optional
    ImageFile : UInt8*,   # LPCSTR
    Type : UInt32,   # DWORD
    SymbolFile : UInt8*,   # LPSTR out
    cSymbolFile : LibC::SizeT,   # UINT_PTR
    DbgFile : UInt8*,   # LPSTR out
    cDbgFile : LibC::SizeT   # UINT_PTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SymGetSymbolFileNative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Utf8>, UintPtr, Pointer<Utf8>, UintPtr);
typedef SymGetSymbolFileDart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
final SymGetSymbolFile = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<SymGetSymbolFileNative, SymGetSymbolFileDart>('SymGetSymbolFile');
// hProcess : HANDLE optional -> Pointer<Void>
// SymPath : LPCSTR optional -> Pointer<Utf8>
// ImageFile : LPCSTR -> Pointer<Utf8>
// Type : DWORD -> Uint32
// SymbolFile : LPSTR out -> Pointer<Utf8>
// cSymbolFile : UINT_PTR -> UintPtr
// DbgFile : LPSTR out -> Pointer<Utf8>
// cDbgFile : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SymGetSymbolFile(
  hProcess: THandle;   // HANDLE optional
  SymPath: PAnsiChar;   // LPCSTR optional
  ImageFile: PAnsiChar;   // LPCSTR
  Type: DWORD;   // DWORD
  SymbolFile: PAnsiChar;   // LPSTR out
  cSymbolFile: NativeUInt;   // UINT_PTR
  DbgFile: PAnsiChar;   // LPSTR out
  cDbgFile: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SymGetSymbolFile';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SymGetSymbolFile"
  c_SymGetSymbolFile :: Ptr () -> CString -> CString -> Word32 -> CString -> CUIntPtr -> CString -> CUIntPtr -> IO CInt
-- hProcess : HANDLE optional -> Ptr ()
-- SymPath : LPCSTR optional -> CString
-- ImageFile : LPCSTR -> CString
-- Type : DWORD -> Word32
-- SymbolFile : LPSTR out -> CString
-- cSymbolFile : UINT_PTR -> CUIntPtr
-- DbgFile : LPSTR out -> CString
-- cDbgFile : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let symgetsymbolfile =
  foreign "SymGetSymbolFile"
    ((ptr void) @-> string @-> string @-> uint32_t @-> string @-> size_t @-> string @-> size_t @-> returning int32_t)
(* hProcess : HANDLE optional -> (ptr void) *)
(* SymPath : LPCSTR optional -> string *)
(* ImageFile : LPCSTR -> string *)
(* Type : DWORD -> uint32_t *)
(* SymbolFile : LPSTR out -> string *)
(* cSymbolFile : UINT_PTR -> size_t *)
(* DbgFile : LPSTR out -> string *)
(* cDbgFile : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("SymGetSymbolFile" sym-get-symbol-file :convention :stdcall) :int32
  (h-process :pointer)   ; HANDLE optional
  (sym-path :string)   ; LPCSTR optional
  (image-file :string)   ; LPCSTR
  (type :uint32)   ; DWORD
  (symbol-file :pointer)   ; LPSTR out
  (c-symbol-file :uint64)   ; UINT_PTR
  (dbg-file :pointer)   ; LPSTR out
  (c-dbg-file :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SymGetSymbolFile = Win32::API::More->new('dbghelp',
    'BOOL SymGetSymbolFile(HANDLE hProcess, LPCSTR SymPath, LPCSTR ImageFile, DWORD Type, LPSTR SymbolFile, WPARAM cSymbolFile, LPSTR DbgFile, WPARAM cDbgFile)');
# my $ret = $SymGetSymbolFile->Call($hProcess, $SymPath, $ImageFile, $Type, $SymbolFile, $cSymbolFile, $DbgFile, $cDbgFile);
# hProcess : HANDLE optional -> HANDLE
# SymPath : LPCSTR optional -> LPCSTR
# ImageFile : LPCSTR -> LPCSTR
# Type : DWORD -> DWORD
# SymbolFile : LPSTR out -> LPSTR
# cSymbolFile : UINT_PTR -> WPARAM
# DbgFile : LPSTR out -> LPSTR
# cDbgFile : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目