There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Issue with PrintWatchQueue on 64 bit systems
I have been trying to use the PrintWatchQueue component, but I have been running into an odd issue... When adding any printer using the .AddPrinter method I receive the following error:
Attempted to read or write protected memory. this is often an indication that other memory is corrupt.
I was using the latest version of the component (18.104.22.168) on a WindowsXP 64 box, Visual Studio 2005. When I tried to open the source code, I discovered it was written in VS 2008. Thinking that it might be a problem with the target CPU, I loaded the source code
in a Server 2008 (32 bit)/VS 2008 virtual machine that I have. I checked - the target CPU was set to "Any CPU", so that wasn't the problem...
I recompiled anyhow, and copied the new dll back to my application on the 64 bit machine. Ran the program - encountered the same error. I then switched gears, and moved my app to the virtual machine. Converted the project to VS2008, compiled and ran it - BINGO!
No error! Interesting - is this a 32 bit vs. 64 bit Framework issue? On to further investigation...
I needed to debug your source code to identify the location of the error, but the only source I had was VS 2008. So, I dug around a bit on MerrionComputing.com and on the CodePlex PUMA site. I found that the PrintQueueWatch code in the PUMA source was VS 2005.
I recompiled the code, replaced the dll in my app, and was able to establish debugging. Here is what I found:
When I call the .AddPrinter method, the code executes successfully through creating a New PrinterInformation class when the DesiredAccess is set to 131080, but when it tries to create the class with DesiredAccess set to PrinterAccessRights.PRINTER_ALL_ACCESS
(983052) the code throws theprotected memory error.
So there is the source of the error, but my knowledge of the Printer world is much too limited for me to make any sense of it. Do you have any ideas?