Create Windows Print Driver [duplicate] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'm looking to create a virtual printer that passes data to my .NET application. I want to then create an installer that installs both the printer and the .NET application. It would we really nice to be able to write it all in C#, but I have a feeling that this will require a printer driver to be written is unmanaged code. Does anyone know of a fairly clean tutorial or example of how to do this?

Did exactly what you are asking using the Github project: Microsoft/Windows-driver-samples/print/XPSDrvSmpl
https://github.com/Microsoft/Windows-driver-samples/tree/master/print/XPSDrvSmpl
Installer: http://wixtoolset.org/
Application: Listen to internal port
Flow: Install printer and application from a single installer. User prints something with your driver while the application listens to the internal port. When data is sent the application picks it up. This is for XPS, can be converted to PDF, but the flow is similar no matter what you are printing. If you need anything else check out Microsoft/Windows-driver-samples/print/ on GitHub or other sources specific to your needs.
Update:
A lot of questions about how to get the driver working so here is a quick example:
Start by downloading Windows Driver Kit (WDK) if you do not have it installed already. When installing choose to add the extension for Visual Studio as well in the final step. In your Visual Studio 2017 Install you need to have Desktop development with C++ to have the right SDKs. If you don't have it see the anser below on how to add it.
How do I add features to Visual Studio 2017?
https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit
Then download the .zip file for Windows-driver-samples master:
https://github.com/Microsoft/Windows-driver-samples/archive/master.zip
Navigate to the folder <UnzipFolder>\print\XPSDrvSmpl and open XPSDrvSmpl.sln in Visual Studio.
Then follow Microsofts own guide on GitHub. As you can see it is for Visual Studio 2015 but I think it is the same for 2017 (not tested yet):
To build a driver solution using Windows Driver Kit (WDK) 10 and Visual Studio 2015, perform the following steps.
Open the solution file in Visual Studio 2015.
Add all non-binary files (usually located in the \install directory
of the sample) to the Package project: a. In the Solution Explorer,
right click Driver Files b. Select Add, then click Existing Item c.
Navigate to the location to which you downloaded the sample, and
select all the files in the install directory, or the equivalent set
of non-binary files such as INFs, INIs, GPD, PPD files, etc. d.
Click Add
Configure these files to be added into the driver package: a. In the
Solution Explorer, right click on the solution and choose Add > New
Project. Choose Driver Install Package under Visual C++/Windows
Driver/Package. b. In the Solution Explorer, right click the Package
project and select Properties. c. In the left pane, click
Configuration Properties > Driver Install > Package Files. d. In the
right pane, use the ellipsis button (...) to browse to the set of
files that needs to be added to the driver package. All the data
files that you added in Step 2-c, except the INF file, should be
added. This configuration is per-architecture, so this configuration
must be repeated for each architecture that will be built. e. Click
OK.
Open the INF file and edit it to match the built output. a. Open the
INF file. b. In the Version section, add a reference to a catalog
file like this: CatalogFile=XpsDrvSmpl.cat. c. In the
SourceDisksFiles section, change the location of the DLL files you
are building, to =1. This indicates that there is no architecture
specific directory in this driver. If you ship multiple
architectures simultaneously, you will need to collate the driver
INF manually.
At this point, Visual Studio 2015 will be able to build a driver package and output the files to disk. In order to configure driver signing and deployment, see Developing, Testing, and Deploying Drivers.
https://github.com/Microsoft/Windows-driver-samples/tree/master/print/XPSDrvSmpl#build-the-sample

I think you will have to do a lot of WinAPI wrapping. Start researching
on Windows Driver Development Kit to find the things you have to do.
I also found this commercial Printer Driver Resource Toolkit for .NET...

You could simply have your app expose itself like an LPD type printer or monitor port 9100. You could then install any print driver you like, and point it a your app.

Was looking for an answer for similar question, and found this link through Wikipedia - http://www.colorpilot.com/emfprinterpilot.html (allows to create Virtual Printers in different languages)

Why not consider using an alternative approach. Like using an intermediate ready made printing program, such as those freely available Print-to-PDF application. Then all you need is to decode PDF using some 3rd party library (which has free and opensource variance too) instead of cracking your head to reinvent the wheel. There are other Print-to-XXX application which you could also consider depending on the format you see fit.

I don't thing interpreting PDF approach is any good either. I don't know why you want to do what you want to do. Maybe you're trying to write a PDF printer of your own.
I think you should really give the Windows Driver Development thing a look. If you want to develop a printer driver, I think you'll have to do it in C++.
Good Luck.

If I remember correctly Microsoft does not support .NET within printer driver development. I have yet to come across a pure .NET printer driver. You will be a very brave man to do so! The website "Printer Driver Resource Toolkit" does not say that the driver has been written in .NET

Related

Using Sharpen and eclipse : error "Application "sharpen.core.application" could not be found in the registry."

Background
I'm currently doing a benchmark of solutions to convert java code to c#
We have a fast evolving java software and wan't to port some low level (not ui) apis with a tool, because maintaining all changes between versions could prove really tiresome...
Anyway, I've been trying to use Sharpen, as I heard it's a pretty wicked tool used by some mono "freaks" to keep some versions of their tools in check.
What I did
For this purpose, I tried several tutorials I found on internet, the easiest to understand being http://www.pauldb.me/post/14916717048/a-guide-to-sharpen-a-great-tool-for-converting-java
As the link he gives for a pre-build sharpen plugin is now broken, I build my own version of the plugin using sources and instructions found here : https://github.com/xamarin/XobotOS/
Result
The plugin build perfectly, and is installed in my eclipse folder. But when I try to run the ant script after setting everything up, I get an error :
java.lang.RuntimeException: Application "sharpen.core.application" could not be found in the registry.
Conclusion
Well. I'm lost here.
I have no idea what that means.
I'm using Windows 7 64bit
I'm using Eclipse 3.7
I'm using java 6 sdk 64 bit
If anyone ran into this and has a solution... That be helpful.
Thanks in advance.
Initially I tried the same approach as you did, with the same result. But if you follow the instructions in the README.build file, section Setting things up, you should be able to launch a secondary Eclipse applications with the sharpen.core and sharpen.xobotos plug-ins included.
You could then import your Java project subject to conversion into the secondary Eclipse app, provided that you have included a Sharpen Xobot builder command and nature into your project file, like this .project file in the XobotOS/android folder. I edited the .project file manually before importing the project, but I assume you can also configure this from within Eclipse?
The configuration files provided by Paul Du Bois are not applicable, instead you will need to copy and edit the converter-config.xml file from the XobotOS/android folder. This file in turn references a file in the app sub-folder, which probably also needs to be copied and edited.
This is basically as far as I have been able to take it until now. I have been able to edit the configuration files to enable the converter to run, but at this point I have only been able to generate C# stubs. If you or someone else manages to take this even further, I would be happy to learn how to generate real C# files using the XobotOS Sharpen converter.
UPDATE
Asked Miguel de Icaza if there were any instructions for converting arbitrary Java projects using the XobotOS Sharpen version. He responded that there are many hard-coded details in this version that makes it difficult to apply to arbitrary projects. At this stage he recommends Lluis Sanchez' Sharpen version to be used instead.
BTW, the NGit library has been moved to here. You will find a fully functional sharpen plug-in for Eclipse in the gen/plugins sub-folder.
UPDATE MAY 17
Note that you need to have the Plug-in Development Environment software installed in Eclipse to be able to build and run the plug-in projects. IF you are running Eclipse IDE for Java (SE) Developers, you need to extend it with the PDE software.

Creating a cab. installer with compact framework intergrated [duplicate]

This question already has an answer here:
Closed 10 years ago.
i'm trying to make an installer for an app i developed for windows ce.The problem is,if i dont deploy it via visual studio and create an installer and run it inside CE,i get "framework not installed error".Is there a way to integrate the framework components to my installer?
Regards.
Edit:i managed to get 2 seperate cab files, one for my app and one for the framework,now,is there a way to merge these two cab files??
Sure, you could "merge" the CABs. The simplest way is to just include the CF runtimes and libraries into your own CAB and not worry about getting them GACed on the target. Openn the CAB and you'll find a _setup.xml file that describes the file names you need to use for the CAB contents. Typically I'll just add the files directly to my own app's INF file (we never use the deployment package in Studio for building CABs) and have them deployed to the \Windows folder of the target.
No. You can not merge the two.
If I am wrong and someone is able to show me differently, I will gladly accept the downvote.
I've been deploying Windows Mobile cabs for about 4 years now, and I've always got to install all prerequisites as additional cabs.
Perhaps you could write a wrapper that calls the correct cabs in sequence, but Visual Studio 2008 and earlier does not come with a built in mechanism to do this.

Reboot after installation from CAB using NET Compact Framework

We need to reboot a Windows CE device after installation of our CAB file. We basically created a smart device CAB project in Visual Studio 2008. We are developing in C#.
I have seen examples of modifying MSI properties in Stack Overflow question How can I prompt the user to reboot in a .NET installation?. So I was going to try setting this MSI property in Orca.exe. But CAB files don't seem to open in Orca.exe, so I assume it isn't an option for CAB files on smart devices.
I also see an example of making it happen in C++, Stack Overflow question Reboot on installation of .CAB WM, but we would rather avoid using C++. There isn't an option for C# custom actions for smart devices either.
Is there a setting or some way for us to do this in C#?
There's nothing you can do in C# for this, no. The CAB file is unpacked and parsed by wceload. If you need to do any custom actions, you must use a custom setup DLL, which must be written in C. That said, what you're after is not at all complex, so writing it in C really shouldn't be a problem. You simply need to add the soft reset call to Install_Exit (probably after checking that nothing failed).

Can I create a single EXE in Microsoft Visual # 2010 Express when my applications is depending on Google Data API SDK?

I have an application depending on the Google Data API SDK (which are .dll's).
When I publish the application (Debug > Build Solution), my EXE-file only works on another computer when I copy the references in the same directory which I have included in my Visual Studio project.
The application is querying my Google Calendar for the current event, so I want to be able to run it from a memory stick.
Is there a solution so I can include those DLL's in one single EXE (make it kind of portable?).
Thank you so much!
You could potentially use ilmerge to do this. However, I don't know what the ramifications of this are in terms of licensing, particularly if you're going to distribute the app.
I would personally vote for keeping them separate, and just deploying them next to each other (whether in an installer or on a memory stick).
Most of the libraries Google provides are open-source and hosted on Google Code. This means you can download the source code and include it in the same project as the .exe project. That eliminates the need to have references to other dlls.
Here is the link to the .Net Google Code project. You'll need svn to check out the latest source code. The svn command is here:
svn checkout http://google-gdata.googlecode.com/svn/trunk/ google-gdata-read-only

What are the differences between MSI and EXE installers, and which should I choose? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What are the specific differences between .msi and setup.exe file?
I am working on an installer for a new version of my project (C#).
Previously, I've used Inno Setup to create .exe files for installing my projects on other computers in the workplace. While reading through some tutorials, though, I came across Windows Installer XML, which uses XML files to build a .msi installer.
My project will be available on a network share that all the employees have access to so they can install the software (I'm currently working on an update checker as well)
What are the major differences between .exe and .msi installers? Why would I want to chose one over the other? Would either make more sense given my specific environment?
I found some of the information at this question, but there was not a lot of information.
I wouldn't use WiX for a new project. I'd use an 'Installer Project' in Visual Studio to build an MSI. An installer project is much, much easier to put together.
Many exe installers are actually stubs or containers that hold an MSI, btw.
I guess you've checked out http://en.wikipedia.org/wiki/Windows_Installer?
MSI's give administrators the ability to restrict installs, rebase installs, change or add custom actions, automate installs/reinstalls/uninstalls, standard logging and switches. It just really integrates into a corporate IT environment ( http://technet.microsoft.com/en-us/library/bb742606.aspx ).
A custom installer may have many of those features, but that would depend on the installer package.
Most EXE installers available today are simply stubs to verify that the target machine has just enough support to launch an MSI stored within the EXE. They do basic windows version checking and Windows Installer version checking, then essentially invoke msiexec and let Windows Installer handle the rest.
For a very basic installation, the Installer Project in Visual Studio can get you by, but for just about any kind of real customization or tweaking you'll need a real MSI editor. We use WiX and love it - but it's a bear to learn. If you've got the cash you can invest in InstallShield - but that has it's own set of quirks.
MSI is configurable while EXE is not. I know this doesn't answer your question directly, but I thought I should point towards the ClickOnce technology.
MSDN: See example here.
Simply stated, a ClickOnce application
is any Windows Presentation
Foundation, Windows Forms, or console
application published using ClickOnce
technology. You can publish a
ClickOnce application in three
different ways: from a Web page, from
a network file share, or from media
such as a CD-ROM. A ClickOnce
application can be installed on an end
user's computer and run locally even
when the computer is offline, or it
can be run in an online-only mode
without permanently installing
anything on the end user's computer.
For more information, see Choosing a
ClickOnce Deployment Strategy.
IndigoRose's MSI factory is extremely powerful and much, much cheaper than InstallShield.
It uses WiX internally and allows you to modify the XML files in any way you like. The bootstrapper (.exe, if you add one) has a powerful scripting engine based on Lua to do... well anything.

Categories