Missing class members ImageList in .NETCF

Recently I was trying to enhance CHMReader (http://code.google.com/p/chmreader-smartphone/) and wanted to use an image against CHM files which were shown in the FileBrowser dialog. The project was compiled for Windows Mobile 5 & .NETCF 2.0. I upgraded it to Windows Mobile 6 and .NETCF 3.0.  It is using a TreeNode class (http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx) which has the possibility to show such an image besides the name by using the ImageIndex property. This ImageIndex comes from an associated ImageList (http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx). The problem with .NETCF is that some of the (easier) members are not available. To add an image to this list, we need to use the Image Class (http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx).  And as can be seen, we only have FromHBitMap (http://msdn.microsoft.com/en-us/library/system.drawing.image_members.aspx) available besides FromStream. We need to do a lot of things to draw an image from HBitMap so I decided to use FromStream.

The code is really simple.

FileStream strm = new FileStream(“CHMIcon.ico”, System.IO.FileMode.Open);
Bitmap bm = new Bitmap(strm);
imgList.Images.Add(bm);

This code compiled great. But when I tried to run it, I got exceptions such as not enough memory. I checked the icon file and it was around 3Kb. I googled for it and I didn’t get any straight answers. I finally decided to change the icon to jpg format instead and low and behold, everything started working perfectly.

Nobody in Microsoft told us that we cannot load icon files! Well, I tell it to you now, you cannot load ico files using this method. I wasted a couple of hours doing this before I decided to change format. An out of memory exception does not give much information and what the hell, I had my super computer resources available so there was no way it could go out of memory on an emulator. Microsoft needs to improve. Provide it in the MSDN for gods sake.

Anyways, no more ranting now since the stuff works finally. So you guys take care. The solution is more simpler then it looks.

Hello World in D! – Part 2

As discussed in my post http://www.naresh.se/?p=5, I am trying to do a comparison between programs written in C++ and D. Why I am doing it is a question not to be asked but in any case, I am bored and would like to do something fun. I thought this is the nice way to have fun. We are going to write a Complex class and a main to test it and compare it with D. I am using Code::Blocks and mingW for C++ and Code::Blocks and Digital Mars D compiler for D. Saying that, read the previous post to know how to use Code::Blocks (CB) or RTFM.

I have created the following code for Complex.h file:

#ifndef __COMPLEX_H_INCLUDED__
#define __COMPLEX_H_INCLUDED__

class CComplex
{
private:
    double dA;
    double dB;
public:
    // default constructor
    CComplex();

    // Copy constructor
    CComplex(const CComplex &aComplex);

    // Overloaded constructor
    CComplex(double aA, double aB);

    // Access functions setters
    void setValueA(double aA);
    void setValueB(double aB);

    // Access functions getters
    double getValueA();
    double getValueB();

    // Overloaded operators
    CComplex& operator = (const CComplex &aComplex);
    CComplex& operator += (const CComplex &aComplex);
    CComplex& operator -= (const CComplex &aComplex);

    const CComplex operator + (const CComplex &aComplex) const;
    const CComplex operator - (const CComplex &aComplex) const;
    bool operator == (const CComplex &aComplex) const;
    bool operator != (const CComplex &aComplex) const;

    // More interesting overloads for * & /
    const CComplex operator * (const CComplex &aComplex) const;
    const CComplex operator / (const CComplex &aComplex) const;

    // Utility functions
    void vPrintComplexNumbers(); // prints the complex number
};

#endif // __COMPLEX_H_INCLUDED__

And the following code for Complex.cpp file:

#include "Complex.h"

#include 

using namespace std;

// default constructor
CComplex::CComplex()
{
    dA = 0; dB = 0.0;
}

// Copy constructor
CComplex::CComplex(const CComplex &aComplex)
{
    dA = aComplex.dA;
    dB = aComplex.dB;
}

// Overloaded constructor
CComplex::CComplex(double aA, double aB):dA(aA),dB(aB)
{
// Can also assign values inside the function. Lets see if compiler optimizes stuff.
// But yes, this is the mingW compiler on Win32.
}

// Access functions setters
void CComplex::setValueA(double aA)
{
    dA = aA;
}

void CComplex::setValueB(double aB)
{
    dB = aB;
}

// Access functions getters
double CComplex::getValueA()
{
    return dA;
}

double CComplex::getValueB()
{
    return dB;
}

// Overloaded operators
CComplex& CComplex::operator = (const CComplex &aComplex)
{
    // Check for self-assignment
    if(this != &aComplex)   // Not the Same Object then copy
    {
        this->dA = aComplex.dA;
        this->dB = aComplex.dB;
    }
    return *this;
}

CComplex& CComplex::operator += (const CComplex &aComplex)
{
    this->dA += aComplex.dA;
    this->dB += aComplex.dB;
    return *this;
}

CComplex& CComplex::operator -= (const CComplex &aComplex)
{
    this->dA -= aComplex.dA;
    this->dB -= aComplex.dB;
    return *this;
}

const CComplex CComplex::operator + (const CComplex &aComplex) const
{
    // Not optimized in terms of lines of code. I will leave it to the compiler to do it for me this time
    CComplex retClass = *this;
    retClass += aComplex;
    return retClass;
}

const CComplex CComplex::operator - (const CComplex &aComplex) const
{
    // Optimized call. Lets see how the compiler handles it
    return (CComplex(*this) -= aComplex);
}

const CComplex CComplex::operator * (const CComplex &aComplex) const
{
    // (a + bi).(c + di) = ac + adi + bci - bd = (ac - bd) + (ad + bc)i
    CComplex retClass(*this);

    // ac - bd
    retClass.dA *= aComplex.dA;
    retClass.dB *= aComplex.dB;
    retClass.dA = retClass.dA - retClass.dB;

    // ad + bc
    retClass.dB = (this->dA * aComplex.dB) + (this->dB * aComplex.dA);
    return retClass;
}

const CComplex CComplex::operator / (const CComplex &aComplex) const
{
/*
     (ac + bd)        (bc - ad)
    = ---------   +  i-----------
      (c2 + d2)        (c2 + d2)
*/
    CComplex retClass(*this);
    double c2d2 = (aComplex.dA * aComplex.dA) + (aComplex.dB * aComplex.dB);

    // ac + bd
    retClass.dA *= aComplex.dA;
    retClass.dB *= aComplex.dB;
    retClass.dA = retClass.dA + retClass.dB;

    // (ac+bd)/(c2+d2)
    retClass.dA = retClass.dA / c2d2;

    // bc - ad
    retClass.dB = (this->dB * aComplex.dA) - (this->dA * aComplex.dB);
    // (bc-ad)/(c2+d2)
    retClass.dB = retClass.dB / c2d2;

    return retClass;
}

bool CComplex::operator == (const CComplex &aComplex) const
{
    if(dA == aComplex.dA && dB == aComplex.dB)
    {
        return true;
    }
    return false;
}

bool CComplex::operator != (const CComplex &aComplex) const
{
    return !(*this == aComplex);
}

// Utility functions
void CComplex::vPrintComplexNumbers() // prints the complex number
{
    cout<

And forgot to put in the main.cpp file but here it is. Copy the following code into main.cpp and off you go...

#include 

#include "Complex.h"

using namespace std;

int main()
{
    CComplex a(2,3), b(a), c;
    a.vPrintComplexNumbers();
    b.vPrintComplexNumbers();
    c = a+b;
    c.vPrintComplexNumbers();
    if(a!=b)
    {
        cout << "Var a "; a.vPrintComplexNumbers();
        cout << " is not equal to Var b "; b.vPrintComplexNumbers();
    }
    else
    {
        cout << "Var a is equal to Var b with values "; a.vPrintComplexNumbers();
    }

    c += a;
    cout<<"Var c is "; c.vPrintComplexNumbers();
    c -= b;
    cout<<"Var c is "; c.vPrintComplexNumbers();

    if(c == (a+b))
        cout<<"Program works fine..."<

Okay. With this done, you can compile and run the program. Runs pretty good eh.. And time for some statistics now.

- Clean rebuild takes around 2 seconds for debug and 1 second for release on the mingw compiler with 0 errors and 0 warnings. The command line was: mingw32-g++.exe -Wall -fexceptions  -g  -pg for compiling and mingw32-g++.exe -pg -lgmon for linking

- Output executable size is 595.99 KB for debug release and 271.50 KB for release executable

- Code Statistics is: 3 files, 66% code only, 2% code + comments, 14% comments and 18% empty

- Code only lines: 155, Empty lines: 43, Comment Lines: 32, Code & Comments: 4 with a total of 234 lines

Besides this I also have a gprof output for code profiling. This post would be way too long if I paste it here especially since the blog doesn’t support any plugins. But lets move over to D now and see whats it store for us for a similar program doing similar things except that it is in D. Note that I am writing the code from scratch instead of using the D utility which converts the C/CPP headers to D files.

—- End Part 2 of Hello World in D!…

Raaz 2 – The Mystery Continues… Critic Review

Of course I am the critic reviewing the Raaz 2 movie by Mahesh Bhatt starring Imran Hasmi, …. , another actor and actress… What the fuck? What kind of critic am I when I don’t even remember the names of the actors/actresses in the movie? Well, never mind, infact after watching the movie, I felt that I had not only wasted 2.5 hours of my critical time but also wasted quite a lot of energy before the movie in speculation and raising serious expectations. So why am I wasting my time writing a review. Because there are lot of negative subtle messages in the movie which needs to be brought to light. Being an Indian and follower of Hindu religion, it amazes me that movies which are downright racist and making fun of the greatest religion in the world are made in India without any repurcursions neither from the media and nor from the people themselves. All of these does affect me since I am not living in India. Most of the people outside of India know about the great country from the movies which are produced there.

One such movie was “The Slumdog Millionaire”. I don’t know why it received Oscars. Maybe it is a part of international agenda to show how pathetic Indians are and why it can’t become a world power. All I know is that the movie was pure Bullshit. Infact, Bullshit would have been more interesting than that movie. After the movie was released, I had a hundred people giving me condolances on the state of India and how people live there and of course they were worried about my relatives living in those unhealthy environments!? It took a lot of time on my behalf to bring out the wrongs in the movie and show them the correct picture of India, to show them that India is not those slums, the slums ofcourse are there but they are not that bad, and that all the calamities occuring on the character do occur but do not occur to just one person. And I also had to bring out examples from their history and current affairs which proved that there state was not fairing any better. I could like others might have laid low and let everything pass. But my blood boils when some son of a bitch whose father was a white skinned asshole who fucked his mother in broad daylight and was brought up in a slum outside India, comes to India and starts bullshitting all over. I will write down another post with all the words that I have in my dictionary that I rarely use for that movie reivew. So back to Raaz 2 as the topic suggests.

Raaz (the first part) was a very good film starring Bipasha Basu. It had a story. It had something that compels you to feel other elements which cannot generally be felt. It had its fair share of hair raising scenes. I definitely liked the movie. I had similar expectations when I started watching Raaz 2. But instead of receving 2 hours of entertainment, it was 2 hours of copy paste from hollywood movies, with a lot of India and Hindu bashing put in to create a kind of masala which tasted downright horse shit.

The movie starts with the scene of a temple which is abandoned and a white guy running around with his shoes on. The priest of the temple is shown in mess in one of the rooms and when the white guy enters that room, he tries to remove his shoes, but the priest tells him that they had killed Bhagwan! Remember that Bhagwan and God are distinguished in the movie and both have not been considered one and the same. One of the subtle messages was that it was easy to kill Bhagwan. Hmm… maybe I am a pervert and am not thinking properly. So lets go ahead. Then we come to some bakwas/boring actress doing photo shoots, etc. The film goes ahead and after some time, a scene props up where Hindus are being shown workshipping their Bhagwan. After a minute, there comes a guy who starts saying stupid things about the religion like “Moorti/statue drinking milk, monkey doing pooja/prayers”, etc. and saying that these are all superstitions and that we as India would like to go forward, but we always go backward because of these kind of thinking.

Look at the subtle messages again. First of all, Hindu religion and Hindus doing poojas are termed as superstitious. Notice that Hindus are singled out and the statement necessarily does not apply to other religion followers since nothing about them is being wispered. Hindus might be the majority in India but ask a person outside India about people’s religion in India and he would come out with 3 religions namely Islam, Christianity and Buddism. The other subtle message is that India is always going backwards. I don’t know but if that would have been the case, then we would have our Shankaracharya (i.e. head of religion similar to Pope) asking people to not use condoms. But I see this and similar statements from heads of major religions of the world being made from developed countries. Another subtle message was that until and unless the Hindus discard superstition (which was worship) according to the movie, India will not grow and become a super power.

hmm.. It seems to be a far fetched conclusion since it is the Hindus and the people of India who have bled and suffered to give the world whatever good it has right now. Discussions on that are available on many other sites and might be the topics of further posts. But this movie undermined the faith of the followers of the third largest religion of the world with more than a billion followers. These kind of movies definitely affect the Hindu children who are being brought up in a multi-cultural environment where it becomes difficult for them to assert their identity because of the negative images/thoughts being broadcast in movies and media. Infact I had a couple of my friends who started identifying themselves as South Indians instead of Indians after Slumdog Millionaire was released and when they were asked downright stupid but humiliating questions from fellow people.

Finally the movie goes on to show that there was a ghost of a good person who was killed by the trio, priest, police inspector and factory owner for money? I haven’t seen any Bollywood movie, where a father or a mullah has been shown as evil. Why only Hindu Priests are singled out? Subtle messages. I know of many children who have already stopped going to temples because they think that the priest is evil and temples are a place where they earn money. So they instead go to a church/mosque to pray to God since it is cool and hitech as described in these bloody movies. I seriously doubt if Mahesh Bhatt has lost his mind along with his hair. Of course he might be looking forward to getting an oscar and the only way to get it is to criticize the heart and life of India, the people who make India what it is, and the only people in the world who cannot retaliate to such inconsistencies since it is their leaders who would like them killed and extinct. Read the following from : http://rajeev2004.blogspot.com/2008/01/bigot-arun-gandhi-forced-to-quit-fake.html

“he Mahatma had advised Jews, when they faced extinction at the hands
of the Nazis, “… to lay down the arms you have… You will invite
Herr Hitler and Signor Mussolini to take what they want of the
countries you call your possessions…”. Louis Fisher, Gandhi’s
biographer, asked him: “You mean that the Jews should have committed
collective suicide?” Gandhi responded, “Yes, that would have been
heroism.” May be, his grandson wants the same.

The Mahatma was consistent in his advice to Hindus, too. When faced
with violence perpetrated by Muslims, he asked them to not fight back
but die “honourably”. Many Hindus succumbed to the Mahatma’s advice,
and hundreds of thousands of Hindus were killed, raped and assaulted,
over a period of three decades that the Mahatma’s writ ran over India.

Gandhi never advised Muslims to lay down their arms. He sang, “Ishwar,
Allah tere naam” but did not acknowledge that Muslims would never
accept Allah be called anything but Allah. He did not ask Muslims to
look into their hearts and find why they so hated their Hindu
neighbours and fellow countrymen.”

http://agrasen.blogspot.com/2009/01/true-face-of-gandhi.html is also a good read which shows the real face of the Indian rulers. I have been living outside of India and have come to know of the real essence which makes India. It is the people and the culture and it is not alien and imported one. It is the Hindus and Hinduism who cradle the world in its nectar. If they are not there, India would be another one of those countries without any real identity.

I pray to God/Bhagwan to give strength to the people of India, to fight against the onslaught of misinformation and misogamist views of traitors and Hindu baitors, to make them win and survie the unpleasant past and the not so good present and give them a very bright future where the real India says Jai Hind looking at a country which was the super power of the world and which will be the super power of the world.

Jai Hind

Hello World in D!

Recently I came across D programming language. It is the successor of c++ with some Java like features. Since I am a C/C++ lover, I have a stupid feeling when I start coding with either Java or C#. I still will give a try and see how many points does it gain on my scale. Though I haven’t seen any widespread use of D. D was invented by Walter Bright of DigitalMars in December 1999 (http://www.prowiki.org/wiki4d/wiki.cgi?WhatIsD). Some of the features of D as it says on its webpage (http://www.digitalmars.com/d/2.0/overview.html) are resizable arrays, garbage collector, etc besides providing low level bare metal access as required. It also boasts of having a very optimizing and generally fast compiler as compared to C++ as many features which took a lot of compiler time for parsing source files have been removed. Interesting part is that some features like #include preprocessors, #defines, etc. are dropped. The overview page has a lot more text and interested people can go and visit it. Also says that it produces files of smaller size.

So all the people who want to skip the bla bla and deep dive into D, first things to do is to download the digialmars D compiler dmc 2.0.6 (an alpha version) as of now but works fine. I use code::blocks as an IDE which provides a template for D (which is an initial version of Tango so won’t work anyways). But go ahead and use Code::Blocks. It is the simplest, best IDE and believe me, I have used a lot of them. Go ahead and select a new D project. A wizard will popup and for the time being you can use HelloWorldD as the project name and select a location to create the project in. Click on next/finish and you get a HelloWorld.D file created. Goto settings->Compilers & Debuggers and select the location of the bin directory where you have extracted the D compiler and linker. Also give the lib path properly. Okay everything and press CTRL+F9. It will give errors. So delete all the stuff that is present in .D file and write the following.

import std.stdio;
void main()
{
     writefln("Hello World with D Language!");
}

Press CTLR+F9 and then CTRL+F10 and it should run fine. For people who know C/C++, printf/cout is replaced with writefln(); I don’t know what writefln stands for (probably write fucking line or write functional line or write line to filestream with filestream redirected to standard out, choose whatever you want). Anyways, probably there is something in the documentation that tells you what it is. I am a hands on guy and not much of a reader of documents. So lets create a simple C++ program and see sizes, compile times, etc. when compared to a D program.

I will divide this post into multiple parts so that I don’t bore people reading it with one long unreadable post. But proceed to the other post titled Part 2 which has the C++ code for a classic class Complex with some operator overloading. Lets see how it fairs in C++ and D.

A tribute to my dear grandmother…

My grandmother Vimlaben whom we also call Kaki Dadi out of sheer love and respect is not keeping up with her health and is in the hospital since today 2009/03/13 in Baroda, Gujarat, India. She has been the role model for every wife, mother and daughter to follow. Her age is almost 83 years, most of which were spent in providing support to the family, community and country as well as educating her children and grand children about values ranging from freedom to dignity to self respect, moral and ethical behavior and love and compassion towards everybody be it a human or an animal. The literal translation of Kaki Dadi means Aunty Grandmother. My grandfather Chandrakant Dada (Kaka Dada) had an elder brother Jayantilal Dada (Mota Dada) who married to Kumud Dadi (Moti Dadi). Mota Dada had children before Kaki Dadi and they used to call her Kaki (Aunty) and my grandfather Kaka (Uncle).

They used to be called that even from their own kids and their grandkids (us). My life’s most important moments have been with my grandfather and grandmother around as a companion and guide. Kaki Dadi is unlike any other wife. She is totally devoted to Kaka Dada. I still remember the days when Dada used to take us to our ancestorial native place in Vadnagar, Gujarat. We used to own a house (infact 4 houses) there. The last one of the house which was a favourite of my Dada was falling apart and was sold after his heavenely accession in 2002. But as far as I can remember, Dada used to take us to Vadnagar for around 2-3 months during our summer vacation in our childhood school going days. Dadi used to accompany my Dada wherever he went. Summer is the time for mangoes in Gujarat we all eat a lot of mangoes in various forms especially Mango Pulp also known as “Ras”.

It was as sweet as honey and full of love when Dadi used to make it for us. She would have been above 60 during that time, but still she was young and vibrant then her daughter in laws who also joined her for some weeks. I remember her making Ras out of 3-4 Kgs of mangoes. And we used to eat her Bepadi rotlis with Ras. It was nectar. Neh.. it was Amrit. Always by my Dada’s side, Dadi used to get up at around 6 in the morning and provide for tea and other morning necessities for Dadaji. Then after doing the daily poojas, she used to prepare the offerings for God. Her god was not only the one in the temple, but also her husband. Dadaji used to have his lunch at 10. Dadi prepared fresh hot food for him with all his favourites every day of the year. Infact Dadaji rarely used to eat food prepared by other people. He was very much devoted and in love with Dadiji.

The day used to go on. Every word my Dadaji said, was taken up as a command by her and fulfilled with pure heavenly love and devotion. Ofcourse when Dadaji was no more, it had left a big hole in Dadiji’s life which nobody was able to fill up. My Dadaji was a great achiever but it wouldn’t have been possible without Dadi and her support. They were the ideal couple who never ever had a difference of opinion. They were two bodies with one soul. And Dadaji’s passing away crippled dadi’s to an irrecoverable extent. She had a fall and broke her hip after which she was not able to walk by herself. This made my Dadaji sad and he left for the heavenly abode. After that, the only wish of Dadiji was to join Dadaji and be with him again.

As a mother, my Dadi brought up 7 kids and gave them values which are pretty hard to find. Today all her children are in good positions materially as well as spiritually. Their ethical and moral values far surpasses any other. I truly appreciate her patience and energy. I have a kid myself and me and my wife find it pretty hard to bring her up. With bringing up 7 kids, educating them, being a good wife and a respected community member, it still makes me wonder about her time management skills and hard work. As a community member, she was well respected in her circles. My Dadaji was a Judge and at times, people used to come to my Dadiji to get her knowledge and advice on pesonal/community issues.

My dadiji never had ever desired materialistic life. For her, spirituality and ethical and moral values were everything. She had a custom of making sure that nobody was hungry before she ate her food. She was the annapurna herself. Cows, Sadhus, beggars, etc. were all invited to our house and were given food during lunch times. It was another of her custom to never make a guest or visitor go hungry. She was the bliss and everything around her was exotic and beautiful with compassin and justice for all. It was like a Ram Rajya when she was running the household. She always has trust in God and humans alike.

After I started living abroad, I had the chance to meet her in Nov 2008. The only thing she told me was to return to my roots, to serve humanity and my country. She expalined her ratioale behind giving me that advice. Today her words are going over in my mind. I have little clue and no idea as to if I would follow her advice but I pray to God to guide me in the matter.

It is sad that I am not with her at this time. Only thing I can do is give her a tribute through this post. I know she is not going to read this, but one thing is for sure, even if she is no more physically present in this world, she and Dadaji are living in my heart, guiding and nurturing me to strive to live the same kind of humane and spiritual life that they have lived. My love and respect for them exceeds that of God. Indeed I pray to them as my God.