DCSIMG
November 2008 - Posts - Pavel's Blog
Sign in | Join | Help

Pavel's Blog

Pavel is a software guy that is interested in almost everything
software related... way too much for too little time

November 2008 - Posts

Virtual Memory Map Viewer

Published at Nov 27 2008, 09:47 AM by pavely

Some of you old folks may recall a small tool called “Pwalk” (process walk), that showed the memory map of a running process. As the tool is hard to come by and is generally old, I decided to create a new one (maybe there’s something else like this out there). This is the first version – very basic, but gets the job done. It supports sorting by any column. I intend to add memory viewing capabilities, process heaps information and allocations in the future. Here’s a screen shot and the executable (no need to install. This is a 32 bit version. If anyone is interested, I will publish a 64-bit native version as well):

ScreenHunter_01 Nov. 27 16.41

ROT Object Invisible When Hosted in a Service

Published at Nov 11 2008, 11:23 AM by pavely

This will not interest any .NET developers…

One of my customers wanted to create a system-wide singleton COM object hosted in a Windows service. However, the object implementation must be in a DLL. The service should start and create an instance of the object and make it available from other client processes. A simple approach would be to use the RegisterActiveObject function to register that instance as the class moniker of its kind. A client can get a proxy to the same instance by using GetActiveObject. Simple, right? Almost.

If the service is run as a service (and not as a regular EXE server), other clients can’t see the object, as the service needs to run in the local system account, even without the “allow the service to interact with desktop”. In this case, GetActiveObject fails.

The solution is to implement the registration process itself using the little flag ROTFLAGS_ALLOWANYCLIENT when registering with the ROT.

Here’s a sample code to replace RegisterActiveObject: Maybe someone else will find this useful.

HRESULT DoRegisterActiveObject(IUnknown* pUnk, REFCLSID rclsid, DWORD dwFlags, DWORD* pdwRegister) {

   CComPtr<IRunningObjectTable> spROT;

   CComPtr<IMoniker> spMoniker;

   HRESULT hr;

   OLECHAR szCLSID[MAX_PATH];

 

   if(!StringFromGUID2(rclsid, szCLSID, (sizeof(szCLSID) / sizeof(szCLSID[0]))))

      return E_UNEXPECTED;

 

   if(FAILED(hr = ::GetRunningObjectTable(0, &spROT)))

      return hr;

 

   if(SUCCEEDED((hr = CreateItemMoniker(L"!", szCLSID, &spMoniker)))) {

      hr = spROT->Register(((dwFlags & ACTIVEOBJECT_WEAK) ? 0 : ROTFLAGS_REGISTRATIONKEEPSALIVE ) | ROTFLAGS_ALLOWANYCLIENT, pUnk, spMoniker, pdwRegister);

   }

 

   return hr;

}

Developer Academy 3

Published at Nov 09 2008, 05:20 AM by pavely

Developer Academy 3 is just around the corner, on December 15th at Airport city. I will be doing a session entitled “Hardcore C#”… I will talk about many features of the language (C# 2 & 3) including (but not limited to) anonymous delegates & lambdas, extension methods, elegant iterators, partial classes & methods, using & IDisposable, dynamic delegates and more. Here’s a link to all sessions.

PDC Report: Day 4 and Summary

Published at Nov 03 2008, 07:48 AM by pavely

PDC is over. Getting back to reality…and work. Plenty of work…

Now that I’ve recovered somewhat from the Jet lag, my report continues.

I started the 4th day (finally no keynote) with “Windows 7: Web services in native code”. A new library installed on Windows 7 (and will be available for Vista as well) allows creating and consuming web services (including using WSE) with native C. I have to say I’m disappointed the API is not C++ or COM, but ugly C. The creation of proxies from WSDL creates very ugly wrappers. It could have been nicer. Nobody codes in plain C anymore. Still, as a general feature, finally one can create web services and clients without incurring the overhead of .NET. It’s about time!

My next session was the new CLR 4.0 features. They will be covered in a future post, for now you can read about it in Sasha’s post (and part 2).

The next session I watched was “Oslo: building textual DSLs”. Finally the benefits of Oslo start to show (at least for me). I’ve written languages and parsers before, and it’s a difficult task. The “Mg” language (sister of “M”) allows defining languages with syntax, tokens and all that. A parse tree is created and can be used in code. Very nice, I’m going to use it and explore it further.

The last session of PDC for me was “WPF extensibility with Pixel shaders, etc.”. It was a nice session, although the presenter was boring, the ability to write pixel shaders and use them from WPF is a huge benefit. New effects replace the old WPF effects. The new effects use GPU acceleration (most of them), which was not in the past.

Summary

All in all, the PDC was fun. I ate plenty and got some glimpse of Microsoft’s vision. And got a 160GB hard disk. Many more posts will be written based on that PDC!