Morning News

They say that to be reactive is a bad thing (don’t ask me who are they), but you cant be proactive if you are not reactive.

The news items in the morning give you more food for thought than your own breakfast.

Image
There was row over Lakshman’s Cartoons in Parliament ( God knows Parliament has got its own gallery of cartoons without bothering about Lakshman’s).
Image
Actually cartoon’s give you feedbacks for which one has to pay if one wants to have feed back otherwise. The anger of politicians is not against cartoon, but they are angry why it is being given for free when a fat fee could be given to consultants for it (A country has to pay a lot to have intellectuals as its citizens).

Second news item was a photograph showing a doctor handcuffed and in chains for copying in exams using high tech devices
Image
( Poor chap did not know that it was his memory test, it was neither his knowledge test nor electronic device test). It shouldbe mandatory that all text book should carry statutory warning on its cover stating that the book is meant for cramming, in no case it should be used to enhance knowledge.

Deeper Thoughts: Identity Politics

Good analysis. Something very true, and to be thought about.

IoC Containers for .NET

Looking at different frameworks for IoC in .NET. Have been digging into various frameworks. Hopefully will publish my findings soon.

Maybe you can help me by giving your vote

The truth is out there

MPatrol: A library for controlling and tracing dynamic memory allocations.

A nice open-source library for memory leak detection and debugging runtime memory allocations for c++ covered by the GNU Library General Public License.

The mpatrol library is a powerful debugging tool that attempts to diagnose run-time errors that are caused by the wrong use of dynamically allocated memory. It acts as a malloc() debugger for debugging dynamic memory allocations, although it can also trace and profile calls to malloc() and free() too. — (excerpt from project home page)

You can download it from here.

What Have I done (WHID) – A nifty utility

Keeping track of my daily work hours was always a problem for me until I came across this nifty utility from What have I done (WHID).
It is quite useful in keeping track of your hours while you work and also generating reports. It has a built-in check-in and check-out task feature with pause to ensure accurate journal of your activities. You can download it from here.

A tough competition to Microsoft Groove

I installed collanos today. Seems to be a very good peer-to-peer open-source collaboration software.
Its worth checking out. Functions exactly like Microsoft Groove, except its totally free. The product is java based, hence should run on almost ay platform, (btw, works for Vista too 😉 ).

UDT (User Defined Types) and COM

During one of my recent projects I came across a typical problem of passing user-defined types from my COM component. The problem I had was that I was using Attributed ATL (one which even Microsoft seems to have abandoned 😉 ). I came up with the following way to expose UDT from COM. Beware though, passing UDT supporting IDispatch interface is a different ball-game altogether and scripting languages don’t readily support UDT’s.

The way to send UDT using IDispatch involves wrapping it in a VARIANT but again for scripting, its a no-no. Passing UDT as an array is slightly more complicated. I will write about these some time in the near future.
There are various good articles on the net about this, but here is a simple, to the point approach.
First Declare your type in your header file, like this

[ uuid("FD27CE79-9C08-4afa-AEB0-BB5B3E2F6DEA")]
struct MiscInformation
{
BSTR Name;
BSTR Status;
BSTR Source;
INT Priority;
};


Now you will have to declare the type in your IDL file. But, because its an attributed project, here is how you do it.

Create a new idl file in you project and name it, for example structures.idl. The make an entry in the IDL file as follows:

[ uuid("FD27CE79-9C08-4afa-AEB0-BB5B3E2F6DEA")]
struct MiscInformation
{
BSTR Name;
BSTR Status;
BSTR Source;
INT Priority;
}

[ version(1.0), uuid(5C6ADADA-1583-4DCB-8F14-4CF9F5BC048C), helpstring("Test UDT 1.0 Type Library") ]
library TestUDT
{
struct MiscInformation;
}


Once this is done you have to include this IDL file in the generated IDL file. Here is how I do it. In my main .cpp file I insert the line [importidl] on top. Like this:

[importidl("structures.idl")];
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you[ module(dll, uuid = "{5C6ADADA-1583-4DCB-8F14-4CF9F5BC048C}",
name = "TestUDT",
helpstring = "TestUDT 1.0 Type Library",
resource_name = "IDR_TESTUDT") ]


class CTestUDTModule
{
public:
// Override CAtlDllModuleT members
};

This takes care to compile the right Type Information.

Now to use this UDT simply do it like this, for example:

    [id(33), helpstring("method GetMiscInformation")] 
HRESULT GetMiscInformation([out,retval] MiscInformation* pMiscInfo);

For creating a VARIANT type for the structure, I use the following function:

    VARIANT GetVariantForStruct(REFGUID rGuidTypeInfo, void* data)
{
VARIANT vnt;
IRecordInfo *pRI;
HRESULT hr;

hr = GetRecordInfoFromGuids(LIBID_TestUDT, 1, 0, 0x409, rGuidTypeInfo, &pRI);
VariantInit(&vnt);
vnt.vt = VT_RECORD;
vnt.pvRecord = data;
vnt.pRecInfo = pRI;
pRI = NULL;

return vnt;

}

This can take care of wrapping structure in a variant. Of-course there are other things to talk about like passing UDT in a SAFEARRAY, but I will talk about them sometime in future.

Any suggestions/comments are welcome.

Undo – Redo and Memento Pattern

How many times we have come across the problem of implementing undo/redo feature in course of software development? I reckon not many a times but ever wondered how to implement such a neat feature (like in office applications) in the software design.
Lo and Behold, the Memento Pattern is here to the rescue.

The idea is to encapsulate the state of an object in another object and hold its reference to be able to restore the object to original state when required. So if you have an object say A. Its state shall be represented by another object called B. Now when object A is to be modified to a new state the requesting object shall ask A for a state object, in this case called B and hold its reference. It will continue to change state of A. If an undo is required it simply resets the state of A by passing it back its original state B.
A detailed description with code example can be found here.
Another great resource on Memento is here and here

Some useful links to opensource projects hosts

Here are some links to the various open source project hosting sites। I visit them regularly to keep up with whats new, these guys are coming up with.

  • SourceForge।net SourceForge।net is the world’s largest Open Source software development web site, hosting more than 100,000 projects and over 1,000,000 registered users with a centralized resource for managing projects, issues, communications, and code। SourceForge.net has the largest repository of Open Source code and applications available on the Internet, and hosts more Open Source development products than any other site or network worldwide.
  • The Codehaus The Codehaus is an open-source project repository with a strong emphasis on Java, focussed on quality components that meet real world needs।
  • The Apache Software Foundation The Apache Software Foundation provides support for the Apache community of open-source software projects। The Apache projects are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field.
  • Tigris.org is a mid-sized open source community focused on building better tools for collaborative software development।
  • Freshmeat.net freshmeat maintains the Web’s largest index of Unix and cross-platform
    software, themes and related “eye-candy”, and Palm OS software. freshmeat is the
    first stop for Linux users hunting for the software they need for work or play।
  • CodePlex CodePlex is Microsoft’s open source project hosting web site. You can use
    CodePlex to create new projects to share with the world, join others who have
    already started their own projects, or use the applications on this site and
    provide feedback।
  • Google Code Code.google.com is the site for external developers interested in
    Google-related development. It’s where google will publish free source code and
    lists of our API services.