Wednesday, October 24, 2007

Vista and the "Windows cannot connect to the printer" error message

Several months ago I purchased a new PC with Windows Vista Home Premium. I purchased it mostly to be able to make use of the parental control features of Vista and I'm pretty happy with it from that point of view.

There has been one nagging sticking point however. I couldn't get the Vista system to connect to a printer shared from another computer running Windows XP. From the Printer control panel I selected "Add Printer", clicked on "Add a Network Computer" and then choose the shared printer from the list. This resulted in a "Windows cannot connect to the printer. Access is denied" error message. In printing emergencies I was able to save the documents to the XP systems "Shared Documents" folders and then print it from the XP system but that is less than an ideal solution.

Fortunately, I've found a solution. Rather than choosing "Add a Network Computer", select "Add a local computer". Then click on "Create a new port" and click "Next". In the dialog box that appears enter \\ComputerName\PrinterName where computer name is the name of the computer sharing the printer and printer name is the shared name of the printer. (I found these instructions here).

Note however this won't work if you've already browsed the computer in Explorer to find out the printer name. Apparently, Vista will already create a port with that name and so the steps above will fail. So, be sure to shared the printer from the remote computer and then remember the name so you can type it in.

How to Debug with SOS in Visual Studio

Want to make use of the power of SOS (Son of Strike)? Are you a regular Visual Studio user intimidated by the relatively user unfriendly WinDbg? Tess has a post here to get you started using SOS with Visual Studio. There are also excellent references here and here.

Wednesday, October 17, 2007

How to declare out and ref parameters with managed C++

Lately, I've been using managed C++ quite a bit. Managed C++ would not be my choice for a project of any size but it's really convenient when you need to create a managed wrapper for C++ classes that you have in-hand.

The replacement syntax available with Visual Studio 2005 is much improved over Visual Studio 2003 (which was the last time I attempted to use managed C++ and so certainly isn’t news). However, I did struggle a bit trying to figure out how to declare what would be out and ref parameters in C# using managed C++.

Normally, I might use the most excellent Reflector in these cases. I just code up the construct in C#, load the assembly into Reflector and then choose the target language in the dissembler window. Unfortunately, Reflector only support the /clr:oldSyntax managed C++ syntax. Various Google searches proved unhelpful as well.

Finally, I stumbled upon the syntax for the tracking reference. Combine that with the System::Runtime::InteropServices::OutAttribute and it’s easy:

public ref class ExampleClass
{
public:
void OutParameter([System::Runtime::InteropServices::Out] String^% v);
void ByRefParameter(String^% v);
};

Simple (and unforgettable) once you know!

Tuesday, October 16, 2007

How to Read Performance Counters Without Administrator Privileges

This is mostly as a reminder to myself. Adding the user to the "Performance Monitor Users" groups, logging out and logging back resolve the unauthorized access exception with the PerformanceMonitor class when running on Vista. The BCL team blog has the source post here.