Showing posts from 2005

Reflection API to access COM objects sample

quoted from URL

Object o;
System.Type t = Type.GetTypeFromProgID("MODI.Document");
o = System.Activator.CreateInstance(t);

Object[] a = new Object[1];
a[0] = "C:\\Temp\\iri36300.TIF";

t.InvokeMember("Create", BindingFlags.InvokeMethod, null, o, a);
Object images = t.InvokeMember( "Images", BindingFlags.GetProperty, null, o, new Object[] {} );
Type imagesType = images.GetType();
Object item = imagesType.InvokeMember( "Item", BindingFlags.GetProperty, null, images, new Object[] {"0"} );
Type itemType = item.GetType();
itemType.InvokeMember("OCR", BindingFlags.InvokeMethod, null, item, new Object[] { 9 } );
Object layout = itemType.InvokeMember("Layout", BindingFlags.GetProperty, null, item, new Object[] {} );
Type layoutType = layout.GetType();
Object ocrResult = layoutType.InvokeMember( "Text", BindingFlags.GetProperty, null, layout, new Object[] …

Locating MAPI directory using FGetComponentPath

Codes below quoted from
By Sam Charchian

(LPSTR szComponent,
LPSTR szQualifier,
LPSTR szDllPath,
DWORD cchBufferSize,
BOOL fInstall);

static TCHAR s_szMSIApplicationLCID[] =
"Microsoft\\Office\\9.0\\Outlook\0LastUILanguage\0"; // STRING_OK
static TCHAR s_szMSIOfficeLCID[] =

age\0"; // STRING_OK

// Function name : CSVCFile::InitMAPIDir
// Description : For Outlook 2000 compliance. This will get the
correct path to the
// : MAPISVC.INF file.
// Return type : void
// Argument : LPSTR szMAPIDir - Buffer to hold the path to the
void CSVCFile::InitMAPIDir(LPTSTR szMAPIDir)
HINSTANCE hinstStub…

Troubleshooting Outlook Express (IMAP, POP3, HTTP, NEWS) with the log file

Just happen to know this when trying to solve my friend OE problem.

You can log in POP3, IMAP, NEWS, HTTP commands of your Outlook Express into a log file. (note, the password in the log file is encrypted by Microsoft, therefore, it is safe to ask user to send the log file over if you are a IT support)

To enable logging.

Tools(menu) - Options (menu) - Maintenance(menu) - check on the protocol you need. (POP3, IMAP, NEWS or HTTP)

To view the log file

Goto path

C:\Documents and Settings\YourUserName\Local Settings\Application Data\Identities\{8D32DF8B-D3B8-4783-A0C5-FE37E2FC8659}\Microsoft\Outlook Express\pop3.log (for pop3)

imap.log for (imap)
and other respectively.

P.S. The {8D32DF8B-D3B8-4783-A0C5-FE37E2FC8659} may vary and there could be a few Identities in it. Look for the folder with the structure of *.dbx similar to your Outlook Express email account.

Steps to set up VS.NET 2003 remote debugger

(quoted from

msvcmon ( Visual C++ .NET 2003 ) on Windows 9x/NT 4.0/2k/XP.

Steps to set up
the remote debugger

1. copy msvcmon.exe and all the dll it needs to the target machine ( Windows
NT4.0 SP6). Psapi.dll need to be copied over Winnt\System32.
2. on the target machine, open a DOS command windows
c:\app\msvcmon -anyuser
3. start the app ( of course the debug version ) on the target machine
4. on the development machine ( Windows XP SP2 ) , open the project file, go
Debug -> Processes
select "TCP/IP(native only)" as the transport layer, and type the IP
address of the target machine. Then click "refresh" button.

(use PSList or PSKill for remotely terminate process. (at
URL for explanation on its usage.

Outlook : "operation failed, object could not be found. " when trying to close a PST.

When you try to close a PST. The error message
"operation failed, object could not be found"
pop up.
After you have tried scanpst and detect and repair. Still won't work.

Solution. (a hard way)

Start Regedit

Go to Key
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Microsoft Outlook Internet Settings

Where "Microsoft Outlook Internet Settings" is the Outlook profile name that has problem. (note: Outlook support multiple profile even for same Windows login)

In the HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Microsoft Outlook Internet Settings, you will see a bunch of long string sub keys in it

Like in the format of GUID, like e.g. 75d1fa940a0d3a4497130516edbde90e

Then, start at the very first sub keys of HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Microsoft Outlook Internet Settings. Right click on sub key,

Select Find (menu)
And then, in the F…

error LNK2001: unresolved external symbol _IID_IMessage

Often time, I encounter unresolved external symbol _IID_IMessage problem when I am trying to use IID_IMessage in my codes.

This is my solution to the problem, include and define in such sequence.

#define INITGUID
#define USES_IID_IMessage
#define USES_IID_IMAPIPropData
#define USES_IID_IMAPITable

#include <initguid.h> //this is needed,
#include <mapiguid.h> //then this
#include <mapiform.h>
#include <objbase.h>
#include <mapix.h>
#include <mapitags.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include <imessage.h>

Managed string to Unmanaged string

Taken from

Example Code#include "stdafx.h" #include
using namespace std; #using
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices; //Converts a System::String to a std::string
//This code assumes that you have used the following namespace:
// using namespace System::Runtime::InteropServices;
std::string ManagedToSTL(System::String *managed) {
//get a pointer to an array of ANSI chars
char *chars = (char*) Marshal::StringToHGlobalAnsi(managed).ToPointer(); //assign the array to an STL string
std::string stl = chars; //free the memory used by the array
//since the array is not managed, it will not be claimed by the garbage collector
Marshal::FreeHGlobal(chars); return stl;
} //Converts a std::string to a System::String
//This code assumes that you have used the following namespace:
// using n…

IT conversation

Listener-supported audio programs,
interviews and important events.

Viewing STL container in VS.NET 2003 watch windows

For a vector, you can start with these examples:

"v._Myfirst" -> the first element
"v._Myfirst, 10" -> 10 elements
"v._Myfirst[1]" -> the element at index 1
"v.size()" -> number of elements

For a list:

"l._Mysize" -> number of elements
"l._Myhead->_Next->_Myval" -> the first element
"l._Myhead->_Next->_Next->_Myval" -> the second element
"l._Myhead->_Next->_Next->_Next->_Myval" -> the third element, etc.

MFC Windows Message Processing - yield control

(Refering Programming Ms Visual C++ fifth edition - Ms Press)

A workaround which works with both Win16 and Win32. Yield control once in a while by inserting the following instructions inside the time consuming function: MSG message;
if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
The PeekMessage function works like GetMessage, except that it returns immediately even if no message has arrived for your program. In that case, the function keeps on processing. If there is a message, however, the function pauses, the handler is called, and the function starts up again after the handler exits.

void CMyClass::LengthyFunction()
MSG message;

volatile int nTemp;
for (m_nCount = 0; m_nCount < nMaxCount; m_nCount++) {
for (nTemp = 0; nTemp < 10000; nTemp++) {
// processing here.
if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {

Recover HDD after format

SystemRescueCd is an improvement of the gentoo live cd. It aims to provide an high quality bootable CD-Rom, with all system utilities that can be required to repair your system.

There seems to be some utilities for FAT16/32 (dosfstools[^]) and NTSF (NTSFProgs[^]) included on the bootable linux CD

There is also this tool R-Studio 2.0[^][^]

Merging menu items for MDI container and MDI child forms

Say, if MDI container has a "About" Menu that the MDI child forms need to merge with.

Set the MDI container menu in such manner. (In the InitializeComponent or change it using the IDE property window)

this.menuItemAbout.Index = 1;
this.menuItemAbout.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemAbout.MergeOrder = 1;
this.menuItemAbout.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuItemAbout.Text = "Help";

this.menuItemMainHelp.Index = 0;
this.menuItemMainHelp.MergeOrder = 1000; //this need to be larger than the child so that it appear //underneath the child menu items.
this.menuItemMainHelp.Text = "Main Help";

Integrate help to .NET apps

"Enter Phone number here. Valid input characters are 0-9,space,'-','(', and ')'",

//this will show an unconventional popup message box on the cursor position. Nicer than standard //messagebox

Can also use the HelpProvider object HelpString properties to achieve the same effect but seems to have less control over.

when drag a System.Windows.Forms.HelpProvider to a form.

All the controls in the form will have the option HelpNavigator on myHelpProvider avail in the properties windows.

For directing the F1 key press to index of the CHM. The helpprovider need to set HelpNamespace to "Help\VB.chm" (to chm appropriate).

Then, in the needed control, HelpNavigator on myHelpProvider option, choose keyword index, and then key in the helpkeyword.

This will automatically map the F1 key press or the "?" help button button to be directed to the CHM.

To sort using ArrayList.Sort()

Quoted from

publicstruct MyStrcuture
public Int32 iID;
public String sName;
In order to be able to sort elements contained in an ArrayList, we have to define the CompareTo method of the IComparable interface, and then use the ArrayList's .Sort() method. This -of course- means that our structure should be inherited from that interface .. and so we'll do! publicstruct MyStrcuture : IComparable
public Int32 iID;
public String sName;

public Int32 CompareTo(Object obj)
MyStrcuture tmpObj = (MyStrcuture) obj;
return (this.sName.CompareTo(tmpObj.sName));

This would allow the array list to be sorted by just calling MyArrayList.Sort()
provided the arraylist containing the item with the above structure.

Useful sorting algorithms in C#. URL

Useful C++ code snippet (ascii to unicode)

void ascii2unicode(LPCTSTR strin, wchar_t* strout)
int len = strlen(strin);
for(int i=0; i<len; i++)
strout[i] = 0;


ImpLib32 is a small utility which creates an import library for Visual C++ 2.x/4.x/5.x from an existing DLL.
What is Implib32:

Implib32 creates 32 bit import libraries for the use with Microsoft Visual
C++ 2.x/4.x/5.x.

Back in the good old days of Windows 3.x, Microsoft supplied a tool called
IMPLIB. This tool was able to create a import library for a given DLL.
After creating this library, you linked it to your program in order to
call functions contained in the DLL.

Unfortunatly, there is no equivalent to IMPLIB for Win32. Microsoft suggests
on the Win32 Knowledge Base that you should use DUMPBIN to create a file
which lists all exports of a DLL, reformat this file to .DEF-file using a
text editor and then use LIB to create a import library from the .DEF-file.
Implib32 does all this work for you: It invokes DUMPBIN and LIB and creates
an import library!

Note: ImpLib32 can't process 16-Bit DLLs, it will only work…

Open Source Licensing Quick Guide

(quoted from
| hackers like to accept code under it
| | combine with proprietary and redistribute
| | | combine with GPL'ed code and redistribute
| | | | must share source of redistributed version
| | | | | must include patent license with contribution
| | | | | |
| | | | | |
v v v v v v
--- --- --- --- --- ---
permissive Y Y Y N N
Mozilla PL 1.1 Y2 Y N3 Y Y (FAQ on MPL URL)

Excel doc which explains various licensing stuff

The Robots Exclusion Standard (web spider)

C++: Named Constructor Idiom

(quoted from
What is the "Named Constructor Idiom"? A technique that provides more intuitive and/or safer construction operations for users of your class. The problem is that constructors always have the same name as the class. Therefore the only way to differentiate between the various constructors of a class is by the parameter list. But if there are lots of constructors, the differences between them become somewhat subtle and error prone. With the Named Constructor Idiom, you declare all the class's constructors in the private or protected sections, and you provide publicstatic methods that return an object. These static methods are the so-called "Named Constructors." In general there is one such static method for each different way to construct an object. For example, suppose we are building a Point class that represents a position on the X-Y plane. Turns out there are two common ways to …

C++: Warning: Derived::f(char) hides Base::f(double)

(quoted from

What's the meaning of, Warning: Derived::f(char) hides Base::f(double)? Updated! [Recently included a new example, changed the parameter types so the behavior seems more bizarre/ominous, and added a note about warnings not being standardized, thanks to Daniel Kabs (in 12/04). Click here to go to the next FAQ in the "chain" of recent changes.]It means you're going to die. Here's the mess you're in: if Base declares a member function f(double x), and Derived declares a member function f(char c) (same name but different parameter types and/or constness), then the Basef(double x) is "hidden" rather than "overloaded" or "overridden" (even if the Base f(double x) is virtual). class Base {
void f(double x); ← doesn't matter whether or not this is virtual

class Derived : public Base {
void f(char c); ← doesn't …

Resolution to C++ "dreaded diamond"

(quoted from

The "dreaded diamond" refers to a class structure in which a particular class appears more than once in a class's inheritance hierarchy. For example, class Base {
int data_;

class Der1 : public Base { ... };

class Der2 : public Base { ... };

class Join : public Der1, public Der2 {
void method()
data_ = 1; ← bad: this is ambiguous; see below

int main()
Join* j = new Join();
Base* b = j; ← bad: this is ambiguous; see below
} Forgive the ASCII-art, but the inheritance hierarchy looks something like this: Base
/ / / Der1 Der2
\ /
\ /
\ /
Join Before we explain why the dreaded diamond is dreaded, it is important to note that C++ provides techniques to deal with each of the "dreads." In other words, this structure is often called the dreaded di…

Wrapping .NET Framework SP1 into a installer

(Original :

1. First download the .NET framework v1.1 re-distributable package, and run "dotnetfx.exe" with the "/C" switch (to extract contents).
2. Then download the .NET fw v1.1 SP1 update, and run "NDP1.1sp1-KB867460-X86.exe" with the /XP" switch (to extract contents).
3. A dialog box asking you where to save the MSP (update patch) comes up, choose where you want to save it (size 18,760 KB).
4. Rename that MSP to SP1.MSP, and place the extracted contents of dotnetfx.exe (.NET framework installer) in the same directory.
5. Clean the directory so sp1.msp,, and netfx.msi are the only files (3 files) in the directory.
6. Run the following commands (from a command prompt):

msiexec /a netfx.msi TARGETDIR="c:\netfx1"
msiexec /p sp1.msp /a c:\netfx\netfx.msi

7. Your c:\netfx directory should have 3 items in it after this operation: 2 directories - Program Files & Win, and ne…

Log4Net tutorial (my straightforward version)

After playing around with the Log4Net, this is my version of tutorial of Log4Net. (WinForm or console)

I have come across a few tutorials but it seems that most of them are either not working or missing out some details that could lead to further waste of time in searching. Hence, my version is here. (in case in future I need to refer back again)

1. Download latest Log4Net. Not the release version 1.1.1, it won't work in this tutorial. Actually, I haven't seen any tutorials works on 1.1.1 release with FileAppender, what an upset. You will need to download the 1.2.0 Beta8 or later.
2. Start a .NET WinForm application or console application.
3. Add reference to Log4Net.dll
4. Add codes below to AssemblyInfo.cs

[assembly: log4net.Config.DOMConfigurator(ConfigFile="Logging", ConfigFileExtension="config",Watch=false)]

5. Add these two lines into your class.

private static readonly ILog logger =

static YourClas…


It seems that Log4J is a de facto logger for the Java Developer community. Automatically, the Log4Net gets all the limelight since it is a direct port from Log4J.

It is unbelievable that the project page (url below) does not provide helpful tutorials or something for people to kick start the logger. I suppose probably the developers of log4net assumed people who choose to use log4net are users from log4j. (well, at least not for me.)

Let see, after some search. These are what I found.

(tutorial for ASP.NET users)

(explanation on the Log4Net, usage and design and structure)

(another explanation,in layman terms)

(Console example)

Coding Standard Enforcer Tool

Only for VS5/6 and VS.NET

GOF Codesmith Template

In refer to my previous post on the Jan 18, 2005. One of the tools, codesmith, and below a cool template for GOF.

C# 2.0 language features

A tutorial to connect to open source project with WinCVS.

(quoted from

Reason I copy all over to my blog is that overtime I notice many web sites will be either dissapeared, content changed or URL broken after some times. Just do not want to search here and there again for the same stuff. Therefore I just place the whole thing here for my sake of future references. The credit should still be all dued to the real authors.

These are the steps to build Compiere from Source:Download the CVScompiere-all module (details see below)In the utils-dev sub-directory customize the myDevEnv.bat fileexecute RUN_build.batWe internally use Eclipse, but you are able to use any IDE or Java development environment to build Compiere form Source.Please note that there is a delay between the CVS commit and it's availability in anomynous (general) CVS access - up to 24 hours according to SourceForge. Usually it does NOT create a problem, but it has resulted in compile errors. In that case, please re-down…

Ten Must-Have Tools Every Developer Should Download Now (.NET)


It basically introduces,

Snippet Compiler Regulator (regex tool)CodeSmithNUnit (unit tester.)NUnit: (an alternative to NUnit)NMock : Humble Dialog Box
Lutz Roeder's .NET Reflector (ildasn advanced)
NAnt (.NET based builder)ASP.NET Version SwitcheProject Convertor

.NET Memory Profiler

Found this

in the forum. Seems like it capable to be used to optimize the .NET application.

Moving Forward >>> .NET Reality Check

(quoted from


To follow up with my previous email about the deprecation of SOAPFormatter in .NET 2.0, I am wondering how many ppl here uses heavy-duty remoting in their projects. If you are, how are you securing that channel ? Are you using Custom Sinks for that ? Or are you using Enterprise Services ? If you are using Custom Formatters and Sinks, please minimize the use of it as it is NOT a strategic step moving forward.

The reason why i am asking is because Microsoft's focus is on Web services, Remoting is not getting a whole lot of new features going forward. Thus, it is not a long-term strategic technology. The deprecation of SOAPFormatters is just the beginning. To move forward to Indigo which will significantly change a lot of things (for the better...), it will also change the way you look at XML Services. Notice that I dropped the word "Web"...You may also need to change the way you look at communication..…

Ways to prevent virus (manually without AV)

A hands-on knowledge for anyone who wants to prevent virus attack manually.

COM spying tool

Hope this will solve some of my COM debugging problems.

From Microsoft Developer Guide - Signing Assembly

Happen to read the Microsoft Developer Guide that my colleague received in the Ms Technet in Sunway Pyramid. Found a few useful tips. (well, although this could be easily found in MSDN or by googling) But want to jot it down for my future references.

Create a key pair and sign the assembly

Sign assembly. Run “sn” utility, add the key file by hand, or use IDE to generate strong name.

1. In the solution explorer, double click on the AssemblyInfo.vb and edit.
2. Modify AssemblyTitle and AssemblyDescription lines to be
- < Assembly: AssemblyTitle(“ClassName”) >
- < Assembly: AssemblyDescription(“.NET Version of PhysServer”) >

3. In the solution Explorer, right click project node, choose “Properties”. Click “Common Properties” folder and then “Strong Name” property page. Select box labeled “Generate Strong Name Using”. Click “Generate Key” to generate a key file and add to the project. Click OK then, build.

Register Assembly and create type library

Go to Ms Visual Studio .NET tools s…

Indenpendent Contractor How To

Bump into people blog and found useful stuff.

Independent Contractor

However, it is a bit US centric but I guess it still relavant.


Wow, this site is really cool, it is free and it is HUGE in coverage.

It supports a number of languages. I reckon this would probably replace all the commercial encyclopedias in the market in no time. At the same time I was enjoying this, I was also feeling worried as it is scary to see all those goodies, especially technology related, set to be free (as in no fees) which lead to non profit jobs and eventually backfire all the IT jobs. Sigh~


Well, just read some debates of MLM in a forum whether would it helps in making a fortune for an employee. My opinion is that MLM could not bring them far enough but only up to sustainable level.Only with solid R&D and export could do that. (my opinion of course)

Below are the facts taken from Herald Press. (quoted from the forum as well)

The 10 Big Lies of Multi-Level Marketing

Lie #1: MLM is a business offering better opportunities for making large sums of money than all other conventional business and professional models.

Truth: For almost everyone who invests, MLM turns out to be a losing financial proposition. Less than one percent of all MLM distributors ever earn a profit and those earning a sustainable living at this business are a much smaller percentage still.

Extraordinary sales and marketing obstacles account for much of this failure, but even if the business were more feasible, sheer mathematics would severely limit the opportunity. The MLM type of business structure c…

Working collaboratively with team members without the topography barrier

Either through company VPN with source control server or with this Source Forge Enterprise Edition. (web version of source control whereby the source codes database (CVS) is hosted by sourceforge but not made public)

Optimizing Distributed Development™ SourceForge® Enterprise Edition is a secure, centralized, enterprise-grade solution for optimizing and managing distributed development. Whether teams are distributed across the building, the country or around the world, SourceForge provides an easy-to-use, web-accessible solution that: Integrates disparate tools and processesExpands visibility and controlImproves development efficiencyEmpowers collaboration and innovation Simply put, SourceForge optimizes distributed development by helping organizations deliver higher quality software in less time and with greater manageability and consistency.

open source project

Wow, what a patriot.

A open source project named "singapore"


Was checking these freelance sites.

It seems that what was mentioned in the web or press are true that many Indians are actively involving themselves into it. Just look at the number of Indian programmers in these sites. No wonder the number of IT graduates are decreasing globally except for India.