Friday, July 16, 2010

Compact Framework Network Printing

As usual a lot of time without posting but I had no time. I am really excited about the beta tools of WP7 (2 days ago I felt asleep while installing the beta cause the only time I have is after 11 p.m.). I also did some improvements on the Sqlite port but I will post it as soon as it will be usable (I plan to compare the performance with Perst even if it's a different approach).
I am posting this because I lost almost two days and maybe someone that needs it will find it right away. My task was some labeling process using MC9090 devices and Zebra S4m printers. I decided to go for in-memory parameterized forms. The client application uses two method for connecting to the printer:
1) Some of the printers have ethernet port and it is quite simple to communicate with the printer as you will open a socket to 9100 port and send the commands to the printer. This is simple
2) Other printers are connected as shared printers from pc's. This one should also be simple but it gave me a lot of headaches and mainly from my fault. I have two approaches:

a. The classic one that you would also do on Windows applications is to invoke CreateFile with the UNC name of the shared printer. My mistake with this approach was that I set the main window as TopMost and when calling the CreateFile windows mobile it will pop up a networking window where you have to insert the user name and password to use for authentication (this even if Guest access is enabled on the shared printer). So this approach was working but as I did not see the pop up window I thought it doesn't work

b. The second one is a little bit more complex. I am invoking WNetAddConnection3 to map the printer as a local resource (when using this method you can also pass the username and the password) and than using CreateFile on the local resource. After sending everything to the printer I call WNetCancelConnection2 to remove the resource (not really optimized but works). The second one seems more stable

The only annoying thing in this moment is the POCKET PC networking pop-up that tells me that the job has finished printing. I want to disable it (I think that it's something to do with the registry) but didn't find the way yet.

I am attaching 2 files Print.cs and Networking.cs. Print.cs has two methods one with authentication and another without.

Hope someone will find it useful


Namaste


4 comments:

  1. MobileReflex introduces the power of mobile computing. It makes your smartphone a convergence device for your business applications. visit www.mobilereflex.com for more details

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. I am also having the same problem with message popping up.. Any solns ?

    ReplyDelete
  4. Unable to find the namespace OpenNETCF.Runtime.InteropServices
    could you provide the same and post the sample to use to print from windows mobile CE device

    ReplyDelete