我在下面收集了我打印的PDF文档属性的以下功能。 由于某些原因,在Delphi 7(运行XP)中,这很好...但是,当我尝试使用Windows 7重新编译Delphi XE时,该函数总是似乎退出失败... dwRet = IDOK
!PDevMode和DocumentProperties。在Delphi 7 + XE之间迁移时出错
我注意到我在Delphi 7中的dwNeeded
对象是7332
,而在XE中它是4294967295
!!
任何想法如何快速解决这个问题?
Function TPrintPDF.GetPrinterDevMode (pDevice: PChar): PDevMode;
Var
pDevModeVar : PDevMode;
pDevModeVar2 : PDevMode;
dwNeeded : DWord;
dwRet : DWord;
Begin
{ Start by opening the printer }
If (Not OpenPrinter (pDevice, PrinterHandle, Nil))
Then Result := Nil;
{ Step 1: Allocate a buffer of the correct size }
dwNeeded := DocumentProperties (0,
PrinterHandle, { Handle to our printer }
pDevice, { Name of the printer }
pDevModevar^, { Asking for size, so these are not used }
pDevModeVar^,
0); { Zero returns buffer size }
GetMem (pDevModeVar, dwNeeded);
{ Step 2: Get the default DevMode for the printer }
dwRet := DocumentProperties (0,
PrinterHandle,
pDevice,
pDevModeVar^, { The address of the buffer to fill }
pDevModeVar2^, { Not using the input buffer }
DM_OUT_BUFFER); { Have the output buffer filled }
{ If failure, cleanup and return failure }
If (dwRet <> IDOK) Then Begin
FreeMem (pDevModeVar);
ClosePrinter (PrinterHandle);
Result := Nil;
End;
{ Finished with the printer }
ClosePrinter (PrinterHandle);
{ Return the DevMode structure }
Result := pDevModeVar;
End; { GetPrinterDevMode Function }
'dwNeeded'应声明为'LONG'。它已签署。负值意味着功能失败。这正是你发生的事情。当您调用“DocumentProperties”时不检查错误。 'DocumentProperties'的Delphi头文件翻译很可能是虚假的。 – 2012-07-31 18:35:29
所以我可以使用Int64而不是dwNeeded的DWord? – 2012-07-31 19:04:51
不,就像我说的那样,它应该被声明为'LONG'。我还想知道把垃圾传给第四和第五参数是否明智。 – 2012-07-31 19:06:41