Page 1 of 1

Onenote print

Posted: Tue Sep 26, 2023 7:10 am
by sigbert
I accidentally specified Onenote as the printer here. The result is an Access Violation, somewhere in the RV sources. Of course, nobody uses that. But the AV is unattractive. Any ideas?

Image

Prevent printing to Onenote:

Code: Select all

RV_GetPrinterDC.....

if LowerCase( Printer.Printers[Printer.PrinterIndex])=LowerCase('OneNote') then
  begin
  raise Exception.Create('Can''t print to OneNote');
  Exit;
  end;

Re: Onenote print

Posted: Tue Sep 26, 2023 7:50 am
by Sergey Tkachenko
Can you tell me which line of TRichView code raises an exception?
I have "OneNote for Windows 10" and "OneNote (Desktop)" printers, both seems to be ok.
Printing to OneNote should not be different from printing to any other printer.

Re: Onenote print

Posted: Tue Sep 26, 2023 9:03 am
by sigbert
I only have “Onnote” as the driver.
It appears that adding any line of code to RV_GetPrinterDC resolves the error.

Code: Select all

Printer.Printers[Printer.PrinterIndex];
or everything
encapsulate in

Code: Select all

 Try except
A

Code: Select all

Sleep(X)
does nothing.

The error will probably lie somewhere else.
I don't think we'll waste any more time on this.
No errors are thrown with my report builder.

Re: Onenote print

Posted: Tue Sep 26, 2023 9:46 am
by sigbert
Apparently a bit of CPU work helps for me

Code: Select all

 Dummy :=''; while Length(Dummy)<10 do  Dummy:=Dummy+' ';

Re: Onenote print

Posted: Tue Sep 26, 2023 10:34 am
by Sergey Tkachenko
But it's sweeping the problem under the rug.
If an exception happens in the same line of code every time, knowing this line may help to solve the problem.

Re: Onenote print

Posted: Tue Sep 26, 2023 11:05 am
by sigbert
Yes, you are right, but it pops immediately after exiting RV_GetPrinterDC.

Code: Select all

function TPrintableRVData.InitPrinterCanvas: TCanvas;
var HDC: THandle;
begin
   HDC := RV_GetPrinterDC;
//error here
   if HDC=0 then
......

Code: Select all

RV_GetPrinterDC
......
end. //no error yet

Re: Onenote print

Posted: Tue Sep 26, 2023 11:59 am
by Sergey Tkachenko
Can you debug RV_GetPrinterDC?
After calling Printer.GetPrinter, what values are written to ADevice, ADriver, APort?
(only characters before the first #0 matter).

For example, for me:
ADevice = 'OneNote (Desktop)'
ADriver = ''
APort = 'nul:'

Re: Onenote print

Posted: Tue Sep 26, 2023 1:50 pm
by sigbert
Found!
My Richview to old ? Sorry.

Microsoft.Office.OneNote_16001.12026.20112.0_x64__8wekyb3d8bbwe_microsoft.onenoteim_S-1-5-21-3759952986-2211634303-2982840940-1001

Code: Select all

function RV_GetPrinterDC: HDC;
var ADevice, ADriver, APort:array[0..1023] of Char;//old array[0..79] of Char;

Re: Onenote print

Posted: Tue Sep 26, 2023 1:59 pm
by Sergey Tkachenko
Wow, I suspected it, but I never thought that such long names are possible.
I'll increase array sizes in the next update.

Re: Onenote print

Posted: Tue Sep 26, 2023 2:52 pm
by sigbert
probably after the next windows update:

Code: Select all

array[0..infinite]

Re: Onenote print

Posted: Sat Sep 30, 2023 1:10 pm
by Sergey Tkachenko
I increased the buffer limit ro 1024 characters in TRichView 21.7.1.

The problem is in using VCL's TPrinter.GetPrinter method that copies strings to PChar buffers
I posted a request to Embarcadero for implementation of a safe version of this method, with String instead of PChar, https://quality.embarcadero.com/browse/RSP-42404