Click here to Skip to main content
14,606,461 members
Rate this:
Please Sign up or sign in to vote.
See more:
This program developed under Borland C++ (V4) running on Win XP. The program was developed to work on Win XP, Vista, 7 & 10. It runs with full 'privaleges' enabled and has been working fine for years. I sometimes add enhancements.

The latest is to display the name of the default system printer. It works fine on XP (not tried Vista) but crashes on Win 7 & 10. Illegal access to memory 0000 004C.

Here is the offending code:

AnsiString s_Bfr

  s_Bfr = Printer()->Printers[Printer()->PrinterIndex ].GetText();


Any thoughts as to why?

The program does print reports, I wanted let the user know what printer is being used.

What I have tried:

The single instruction is the cause. If I comment it out, no crash.
Posted
Updated 1-Jun-20 0:04am
v2
Comments
KarstenK 1-Jun-20 13:12pm
   
separate this statement in 5 (fixe) statements with zero check, to ensure that it doesnt crash. This also helps to debug it.
Rate this:
Please Sign up or sign in to vote.

Solution 1

At a guess, Win7 and 10 return different values to XP, and either Printer() or Printers[Printer()->PrinterIndex ]is returning null.

Break the line up into individual parts as separate lines, and use the debugger to isolate exactly what is being returned: Try it on XP and Win 7 / 10 and you should see differences.
I can't check it at all - I don't have XP any more and Borland 4 is ... um ... rather out of date. Like it's older than about 50% of our members here! :laugh:
   
Comments
Tachyonx 1-Jun-20 6:43am
   
This is a bit off-topic, but I "still" use a Fujitsu Siemens offline laptop with Windows 2000 to collect/play music tracks :-), this rather by coincidence, or a habit ... BR
Rate this:
Please Sign up or sign in to vote.

Solution 2

I will try what you have suggested. It may take some time as I'm older the Borland. I will be 70 next year.

Thanks for your input
AGB
   
Comments
OriginalGriff 1-Jun-20 6:50am
   
That's OK - I'm 61!

Don't post comments as solutions: only the OP - you - get notified that you did, which means the answerer doesn't know you wanted to talk further. Instead, use the "Have a question of comment?" button below each solution (the Reply widget for comments) and the poster gets an email.

I can strongly suggest moving from Borland to Visual Studio - it's a lot better once you get used to the modern frameworks, and the Community Edition is free direct from Microsoft. 27 year old software does tend to have ... problems ... interfacing with modern OSes.
Richard MacCutchan 1-Jun-20 7:41am
   
You young people ... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100