一个打印相关API的问题,会这不难。(20分)

  • 主题发起人 主题发起人 vickymade
  • 开始时间 开始时间
V

vickymade

Unregistered / Unconfirmed
GUEST, unregistred user!
程序代码如下<br><br>procedure AltGetPrinter (ADevice, ADriver, APort: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var ADeviceMode: THandle);<br>{$IFDEF Win32}<br>var<br>&nbsp; pHandle: THandle;<br>&nbsp; pBuffer: PChar;<br>{$IFDEF Ver120}<br>&nbsp; pCount: DWord;<br>{$ELSE}<br>&nbsp; pCount: Integer;<br>{$ENDIF}<br>{$ENDIF}<br>begin<br>&nbsp; Printer.GetPrinter(ADevice, ADriver, APort, ADeviceMode);<br>{$IFDEF Win32}<br>&nbsp; if OpenPrinter(ADevice, pHandle, nil) then<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; GetPrinterDriver(pHandle, '', 2, nil, 0, pCount);<br>&nbsp; &nbsp; &nbsp; if pCount&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetMem(pBuffer, pCount);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetPrinterDriver(pHandle, '', 2, PByte(pBuffer), pCount, pCount) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ADriver := @(ChangeFileExt(ExtractFileName(StrPas(PDriverInfo2(pBuffer)^.pDriverPath)),'')+#0)[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeMem(pBuffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; ClosePrinter(pHandle);<br>&nbsp; &nbsp; end;<br>{$ENDIF}<br>end;<br><br><br>在执行GetPrintDriver()的时候报错,错误信息为:<br>Types of actual and formal var parameters must be identical<br>那位大虾能给我把这个问题讲明白喽啊。我现在一碰到这些API就晕乎。
 
谁能给我详细讲讲啊。
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, WinSpool, Printers, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure AltGetPrinter(ADevice, ADriver, APort: PChar;<br>&nbsp; var ADeviceMode: THandle);<br>var<br>&nbsp; pHandle: THandle;<br>&nbsp; pBuffer: PChar;<br>&nbsp; pCount: DWord;<br><br>begin<br>&nbsp; Printer.GetPrinter(ADevice, ADriver, APort, ADeviceMode);<br>&nbsp; if OpenPrinter(ADevice, pHandle, nil) then<br>&nbsp; try<br>&nbsp; &nbsp; GetPrinterDriver(pHandle, '', 2, nil, 0, pCount);<br>&nbsp; &nbsp; if pCount &gt; 0 then<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; GetMem(pBuffer, pCount);<br>&nbsp; &nbsp; &nbsp; if GetPrinterDriver(pHandle, '', 2, PByte(pBuffer), pCount, pCount) then<br>&nbsp; &nbsp; &nbsp; &nbsp; ADriver := @(ChangeFileExt(ExtractFileName(StrPas(PDriverInfo2(pBuffer)^.pDriverPath)), '') + #0)[1];<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; FreeMem(pBuffer);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; ClosePrinter(pHandle);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ADevice, ADriver, APort: PChar;<br>&nbsp; ADeviceMode: THandle;<br>begin<br>&nbsp; GetMem(ADevice, 255);<br>&nbsp; GetMem(ADriver, 255);<br>&nbsp; GetMem(APort, 255);<br>&nbsp; fillchar(ADevice, 0, 255);<br>&nbsp; fillchar(ADriver, 0, 255);<br>&nbsp; fillchar(APort, 0, 255);<br><br>&nbsp; AltGetPrinter(ADevice, ADriver, APort, ADeviceMode);<br>&nbsp; showmessage(ADevice);<br>end;<br><br>end.<br><br>
 
我不想引用Printer中的东东,想全部用API实现。
 
后退
顶部