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