Delphi 获取默认纸盒的名称?

Delphi 获取默认纸盒的名称?,delphi,winapi,printing,Delphi,Winapi,Printing,我使用WinAPI功能DM_BINNAMES获得了一个纸仓列表,我还使用DM_bins获得了一个有效源索引列表 但我想知道默认纸张来源的名称。我该怎么做 我当前的代码看起来像这样,但根本不起作用。dmDefaultSource的值为258,大于数组bin FPaperSourceIndex = -1; // default function GetDefaultPaperbinName: string; var pDevMode: PDeviceMode; bin: array[0..

我使用WinAPI功能DM_BINNAMES获得了一个纸仓列表,我还使用DM_bins获得了一个有效源索引列表

但我想知道默认纸张来源的名称。我该怎么做

我当前的代码看起来像这样,但根本不起作用。dmDefaultSource的值为258,大于数组bin

FPaperSourceIndex = -1; // default

function GetDefaultPaperbinName: string;
var
  pDevMode: PDeviceMode;
  bin: array[0..255,0..23] of char;
  i: DWORD;
  Res: DWORD;
  found: Boolean;
begin
  GetPrinter(ADevice,ADriver,APort,hDMode);
  pDevMode := nil;
  Res := DeviceCapabilities(ADevice,APort,DC_BINNAMES,PCHAR (@(bin[0][0])),pDevMode);

  if (FPaperSourceIndex <= integer(Res)) then
  begin
    if (hDMode <> 0) then
    begin
      pDevMode := GlobalLock(hDMode);
      if (pDevMode <> nil) then
      begin
        pDevMode^.dmFields := (DM_DEFAULTSOURCE or DM_PAPERSIZE);
        i :=  pDevMode^.dmDefaultSource;  // = 258
        result := bin[i]; // range Exception here
      end;
      GlobalUnlock(hDMode);
    end;
  end;
end;
从重点矿

dmDefaultSource

指定图纸源。要检索 打印机的可用纸张来源,请使用DeviceCapabilities 具有DC_BINS标志的函数

此成员可以是以下值之一,也可以是 设备特定值大于或等于DMBIN_用户

DMBIN_USER定义为256,这解释了为什么在示例中得到258

解决方案很简单,扩大阵列以考虑特定于设备的存储箱

bin: array[0..511,0..23] of char;
从重点矿

dmDefaultSource

指定图纸源。要检索 打印机的可用纸张来源,请使用DeviceCapabilities 具有DC_BINS标志的函数

此成员可以是以下值之一,也可以是 设备特定值大于或等于DMBIN_用户

DMBIN_USER定义为256,这解释了为什么在示例中得到258

解决方案很简单,扩大阵列以考虑特定于设备的存储箱

bin: array[0..511,0..23] of char;

你的数组太小了。用户定义的BIN从256==DMBIN\u用户开始您的数组太小。用户定义的BIN从256==DMBIN\U用户开始