После обновления OS WINDOWS 10 до версии 1709 перестал работать вызов свойств принтера. Код обработки работал еще со времен XP. Win7, Win 8 и даже Win 10 до версии 1709. Права открытия принтера менял на разные PRINTER_READ/WRITE. Ничего не помогает. Выдает ошибку Get Printer Data Size Error. В чем может быть еще проблема?
function TWinPrinter.UpdateProperties(ShowDialog: boolean): boolean;
var
bFlag: boolean;
lFlag: DWord;
DataSize: DWord;
pDefaults: _PRINTER_DEFAULTSW;
pDevMode: PDeviceModeW;
begin
pDefaults.pDatatype := nil;
pDefaults.pDevMode := nil;
pDefaults.DesiredAccess := PRINTER_ALL_ACCESS;
bFlag := OpenPrinter(PChar(FPrinterName), FPrinterHandle, PPrinterDefaultsW(@pDefaults));
if bFlag = false then
begin
raise Exception.Create('OpenPrinter error: ' + IntToStr(GetLastError));
exit;
end;
bFlag := GetPrinter(FPrinterHandle, 2, PPrinterInfo2W(FPrinterInfo2W), DataSize, @DataSize);
if ((bFlag = false) and (DataSize = 0)) then
begin
raise Exception.Create('GetPrinter data size error: ' + IntToStr(GetLastError));
exit;
end
else
begin
GetMem(FPrinterInfo2W, DataSize);
bFlag := GetPrinter(FPrinterHandle, 2, PPrinterInfo2W(FPrinterInfo2W), DataSize, @DataSize);
if (bFlag = false) then
begin
raise Exception.Create('GetPrinter info error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
exit;
end;
end;
lFlag := DocumentProperties(0, FPrinterHandle, PChar(FPrinterName), nil, nil, 0);
if Integer(lFlag) < 0 then
begin
raise Exception.Create('UpdateProperties error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
exit;
end
else
begin
GetMem(pDevMode, lFlag);
end;
case ShowDialog of
true: lFlag := DocumentProperties(FParentWindow, FPrinterHandle, PChar(FPrinterName), pDevMode^, PPrinterInfo2W(FPrinterInfo2W).pDevMode^, DM_IN_PROMPT or DM_OUT_BUFFER or DM_IN_BUFFER);
false: lFlag := DocumentProperties(0, FPrinterHandle, PChar(FPrinterName), pDevMode^, PPrinterInfo2W(FPrinterInfo2W).pDevMode^, DM_OUT_BUFFER or DM_IN_BUFFER);
end;
if Integer(lFlag) < 0 then
begin
raise Exception.Create('UpdateProperties error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
FreeMem(pDevMode);
exit;
end;
if ((lFlag = ID_Ok) and (ShowDialog = true)) then
begin
FPaperOrientation := pDevMode^.dmOrientation;
FCopies := pDevMode^.dmCopies;
end;
if lFlag = ID_Ok then
begin
pDevMode^.dmOrientation := FPaperOrientation;
pDevMode^.dmCopies := FCopies;
pDevMode^.dmFields := pDevMode^.dmFields or DM_ORIENTATION;
pDevMode^.dmFields := pDevMode^.dmFields or DM_COPIES;
end;
lFlag := DocumentProperties(0, FPrinterHandle, PChar(FPrinterName), pDevMode^, pDevMode^, DM_OUT_BUFFER or DM_IN_BUFFER);
if Integer(lFlag) < 0 then
begin
raise Exception.Create('UpdateProperties error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
FreeMem(pDevMode);
exit;
end;
PPrinterInfo2W(FPrinterInfo2W).pDevMode^ := pDevMode^;
bFlag := SetPrinter(FPrinterHandle, 2, PPrinterInfo2W(FPrinterInfo2W), 0);
if bFlag = false then
begin
raise Exception.Create('SetPrinter error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
FreeMem(pDevMode);
exit;
end;
FDevMode^ := pDevMode^;
if pDevMode <> nil then FreeMem(pDevMode);
FPaperOrientation := FDevMode.dmOrientation;
FCopies := FDevMode.dmCopies;
UpdatePhysInfo;
bFlag := ClosePrinter(FPrinterHandle);
if bFlag = false then
begin
raise Exception.Create('ClosePrinter error: ' + IntToStr(GetLastError));
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
FreeMem(pDevMode);
exit;
end;
FreeMem(FPrinterInfo2W);
FPrinterInfo2W := nil;
Result := true;
end;