Onenote print

General TRichView support forum. Please post your questions here
Post Reply
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Onenote print

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Onenote print

Post 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.
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Re: Onenote print

Post 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.
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Re: Onenote print

Post by sigbert »

Apparently a bit of CPU work helps for me

Code: Select all

 Dummy :=''; while Length(Dummy)<10 do  Dummy:=Dummy+' ';
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Onenote print

Post 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.
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Re: Onenote print

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Onenote print

Post 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:'
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Re: Onenote print

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Onenote print

Post 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.
sigbert
Posts: 87
Joined: Fri Sep 02, 2005 4:47 am

Re: Onenote print

Post by sigbert »

probably after the next windows update:

Code: Select all

array[0..infinite]
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Onenote print

Post 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
Post Reply