关于取得打印机名称,和端口的问题,本地打印没问题,但是网络打印机就出错(100分)

  • 主题发起人 主题发起人 seasnake
  • 开始时间 开始时间
S

seasnake

Unregistered / Unconfirmed
GUEST, unregistred user!
用的是这段程序:
procedure TprintSelForm.GetPrinterInfo;
var
pDevice: pChar;
pDriver: pChar;
pPort: pChar;
hDMode: THandle;
begin
GetMem(pDevice, cchDeviceName);
GetMem(pDriver, MAX_PATH);
GetMem(pPort, MAX_PATH);
try
Printer.GetPrinter(pDevice, pDriver, pPort, hDMode);
// label1.Caption := '打印机:' + StrPas(pDevice);
if lStrLen(pDriver) = 0 then
begin
GetProfileString('Devices', pDevice, '', pDriver, MAX_PATH);
pDriver[pos(',', pDriver) - 1] := #0;
end;
if lStrLen(pPort) = 0 then
label2.Caption := '端 口:' + GetPortName(StrPas(pDevice))
// GetProfileString('Devices', pDevice, '', pPort, MAX_PATH);
// lStrCpy(pPort, @pPort[lStrLen(pPort) + 2]);
else
label2.Caption := '端 口:' + StrPas(pPort);
//label2.Caption := 'Driver := ' + StrPas(pDriver);
except
label1.Caption := '打印机:没有安装打印机';
label2.Caption := '端 口:没有安装打钱机';
end;
FreeMem(pDevice, cchDeviceName);
FreeMem(pDriver, MAX_PATH);
FreeMem(pPort, MAX_PATH);
end;
是取出的pDevice有问题!
 
大家帮帮心啊,替我看看啊?还有什么另外的方法?
 
我也看看
 
procedure TForm1.Button2Click(Sender: TObject);
var
pDevice : pChar;
pDriver : pChar;
pPort : pChar;
hDMode : THandle;
begin
if PrintDialog1.Execute then
begin
GetMem(pDevice, cchDeviceName);
GetMem(pDriver, MAX_PATH);
GetMem(pPort, MAX_PATH);
Printer.GetPrinter(pDevice, pDriver, pPort, hDMode);
if lStrLen(pDriver) = 0 then
begin
GetProfileString('Devices', pDevice, '', pDriver, MAX_PATH);
pDriver[pos(',', pDriver) - 1] := #0;
end;
if lStrLen(pPort) = 0 then
begin
GetProfileString('Devices', pDevice, '', pPort, MAX_PATH);
lStrCpy(pPort, @pPort[lStrLen(pPort)+2]);
end;
Memo1.Lines.Add('Device := ' + StrPas(pDevice));
Memo1.Lines.Add('Driver := ' + StrPas(pDriver));
Memo1.Lines.Add('Port := ' + StrPas(pPort));
FreeMem(pDevice, cchDeviceName);
FreeMem(pDriver, MAX_PATH);
FreeMem(pPort, MAX_PATH);
 
后退
顶部