We help IT Professionals succeed at work.

Invoking a Visual Studio Printer Class within VFP

Microsoft have created a Printer Class described here

It gives the invocation syntax for C#, C++, F# and VB

Anyone know how to invoke it in VFP?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
VB mentioned in the article is VB.NET in fact so nothing similar to VFP like e.g. VB6...

You would need some .NET interoperability between VFP and .NET. You may find code samples here:
https://www.west-wind.com/presentations/wwDotnetBridgeComInterop.pdf
http://doughennig.com/papers/Pub/E-CALL.pdf

Sorry I have to say that but it is better to write it in C# or VB.NET than in VFP...

Author

Commented:
Greetings PCElba

I have a current Westwind licence so'll I'll take a good look at that. Coding outside VFP is not an option in this case.

I'll describe the problem I'm trying to address and perhaps you'll know another way around it.

One of my (long term) customers has been running his business using my software since 1996. Over that period we've generated a couple of thousand bespoke reports (so much so I've had to create a report management module just to keep track of them) and he alone probably prints a dozen a day.

He's acquired an HP OfficeJet printer which has developed a fault and, yes, we'll almost certainly fix the problem by replacing the printer. But in the process of attempting to troubleshoot it from my side, I suddenly realised that I had no way, from within VFP, to control sundry printer settings. The one which would have helped in this case would have been the ability to set a bottom margin but that doesn't really matter. It could have been any one of a couple of dozen useful parameters.

I could have sworn that this functionality was there a few years back (prior to Win 10 perhaps?) from within the system "page setup" screens;  but it's been so rare that I or my users have ever had to meddle with such niceties, that I simply hadn't noticed that we could no longer access those areas.  Equally surprising, I found that even with the device properties in the windows device manager, these controls were unavailable and, again, I could have sworn they used to be!

So I'm not really trying to solve a one off problem which we've already proved to be caused by a printer malfunction, I'm considering how to provide support for that kind of formatting functionality within my software more generally.

The perfect answer would be that some VFP genius has already done it. Failing that, I'm prepared to roll my own if it's likely to be a week's work rather than several months. So that microsoft api did look like an obvious starting point.
CERTIFIED EXPERT

Commented:
Yes, I would say the code exists and it has been published on www.news2news.com which is unavailable now. Some more hints are here: https://www.tek-tips.com/viewthread.cfm?qid=1281712

BUT you could also create a standalone application in .NET which is much easier than to control printers from VFP today and invoke it from your VFP application.

BTW, we are converting all VFP reports to .NET and it takes hours and hours...
Software Developer
CERTIFIED EXPERT
Commented:
The class you link to is a .NET class emulating the VB6 Printer class for easy migration of VB6 to VB.NET, so this is not intended for VB6 nor VFP.

Pavel gave the right advice, but the best bet is to set up user-defined paper size in the printer settings. You say you don't find margin settings, well, most likely you can choose paper sizes and one of them is user-defined, where you can define the size smaller than the physical paper size, therefore defining margins indirectly.

Bye, Olaf.

Author

Commented:
Closing the question. Haven't had the time, inclination or pressing need to return to the problem. Thanks to both for your input

Explore More ContentExplore courses, solutions, and other research materials related to this topic.