Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

    • 14,897

OLE,COM and ActiveX

Posted by kiraninbng on September 8, 2006

First came OLE(Object linking and embedding) , which was basically used in ms applications to embed an object of one into another.

Then came the COM standard which took over the tasks of the OLE.For sometime it was also called as OLE2 for sometime.

Next was the ActiveX,which referred to suite of COM based technologies targeted mainly at the internet.The best known ActiveX technology are ActiveX controls.

Then came DCOM which is basically use of COM across the networks.

I guess now the .NET technologies are replacing the COM based technologies and are much simpler.

Advertisements

Posted in General | 2 Comments »

Splitter Window in C#..

Posted by kiraninbng on August 13, 2006

Heres what it takes to create a splitter window with a listbox and treeview in C#,

 // Create the controls
 this.m_ListBox = new System.Windows.Forms.ListBox();
 this.m_Splitter = new System.Windows.Forms.Splitter();
 this.m_TreeView = new System.Windows.Forms.TreeView();
   
 // Set the docking properties of the control
 this.m_ListBox.Dock = System.Windows.Forms.DockStyle.Left;
 this.m_Splitter.Dock = System.Windows.Forms.DockStyle.Left;
 this.m_TreeView.Dock = System.Windows.Forms.DockStyle.Fill;

 // Set the properties of the control
 this.m_ListBox.Size = new System.Drawing.Size(120, 264);

 this.m_Splitter.Location = new System.Drawing.Point(120, 0);
 this.m_Splitter.Size = new System.Drawing.Size(3, 266);

 this.m_TreeView.Location = new System.Drawing.Point(123, 0);
 this.m_TreeView.Size = new System.Drawing.Size(169, 266);

It is even more simpler if you use the Form designer to get a splitter control working.Just add the controls and set the docking properties in the property window,no need to write a single line of code.

Posted in DotNet | 1 Comment »

Japanese writing system…

Posted by kiraninbng on July 31, 2006

The Japaneses writing consists of 3 character sets

1. Kanji
 Kanjis are chinese characters.Each character has its own meaning and corresponds to a word.The characters can be combined to make a new word.
 For ex. Electricity when combined with Car gives Train 🙂

2. Hiragana
 Hirangana is the writing system developed by japanese which is based on the syllables.There are 46 signs,5 are vowels and the rest are syllables.

3. Katakana
 Katakana is very similar to Hiragana.The characters are more angular where the hiragana characters are cursive. Katakana is mainly used for writing words taken from foreign languages and the names of persons and geographical  places that can’t be written using kanji.

Posted in Nihongo | 1 Comment »

getting special folders path…

Posted by kiraninbng on July 27, 2006

Three simple steps to get the paths for special folders,
1. Use SHGetSpecialFolderLocation with appropriate nFolder value(2nd param)
2. SHGetPathFromIDList – Fetch the path name from returned Item Identifier list
3. Release the Item Identifier list
   

Below is an example,

    LPITEMIDLIST pIDList;
    HRESULT hr = SHGetSpecialFolderLocation(NULL,CSIDL_PERSONAL,&pIDList);

    if(SUCCEEDED(hr))
    {
        char szSpecialFolderPath[_MAX_PATH];

       if(SHGetPathFromIDList(pIDList,szSpecialFolderPath))
       {
           LPMALLOC pMalloc;

           hr = SHGetMalloc(&pMalloc);
           if(SUCCEEDED(hr))
           {
               pMalloc->Free(pIDList);
               pMalloc->Release();
           }
       }

Posted in General | Leave a Comment »

const functions….

Posted by kiraninbng on July 25, 2006

If the function is declared as const,the compiler treats the “this” as const pointer.So if you are calling a non const member function of the same class then all you need to do is to remove the constantness of “this” pointer.The case for an embedded object of user defined type is pretty much straight forward.Below is an example,

Class CConstObj
{
 // dummy class
}

Class CConst
{
public:
    void Constfn()const;
    void NonConstfn(); 
    //…..
private:
    CConstObj m_oConstObj; 
 
}

void CConst::Constfn()const
{
    // Call a non const member function from the same class 
    ((CConstObj*)this)->NonConstfn();

    // Call non const member function of m_oConstObj ; 
    // m_oConstObj is a member of type CConstObj.
    ((CConstObj&)m_oConstObj).CallNonConstFn();
    ((CConstObj*)&m_oConstObj)->CallNonConstFn();
}

void CConst::NonConstfn()
{
   
}

Posted in General | 3 Comments »

function return values…

Posted by kiraninbng on July 18, 2006

Generally functions on success will return a value of 0,but i have often seen funtions which return a value of 1 for success,which i believe makes the function inextensible
for returning meaningful error codes.Heres what i follow,

typedef enum
{
 SUCCESS,
 …,
 FAILURE_N
}RETURNTYPE;

RETURNTYPE SomeFunction()
{
 RETURNTYPE Result = SUCCESS;
 
 if(…)
 {
  Result = FAILURE_N;
 }

 return(Result);

In simple terms return a value of 0(FALSE) for success and a value other than 0 for failure.

Posted in General | 2 Comments »

Event logging using event viewer..

Posted by kiraninbng on July 14, 2006

Event logging is a way for applications /operating system  to log important events.The event-logging service stores events from
various sources in a single collection called an event log.The Event Viewer enables you to view logs.

Below are the steps to create an entry in the event viewer,

1. Create a message file
Ex :
; /* Sample.mc
;
; This is a sample message file. It contains a comment block, followed by a
; header section, followed by messages in two languages.
;
; */

; // This is the header section.

MessageIdTypedef=DWORD

SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
               Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
               Warning=0x2:STATUS_SEVERITY_WARNING
               Error=0x3:STATUS_SEVERITY_ERROR
              )

FacilityNames=(System=0x0:FACILITY_SYSTEM
               Runtime=0x2:FACILITY_RUNTIME
               Stubs=0x3:FACILITY_STUBS
               Io=0x4:FACILITY_IO_ERROR_CODE
              )

LanguageNames=(English=0x409:MSG00409)

; // The following are message definitions.
MessageId=100
SymbolicName=EVMSG_SAMPLE
Language=English
The is a sample message file.

2. Using message compiler compile it into a resource script file
Ex : mc -U Sample.mc 

3. Using resource compiler compile the rc file into a binary res file
Ex: rc -r Sample.rc

4. Create a reource only dll using the res file
Ex: link -dll -noentry Sample.res

5. Add a event source to registry,also put an entry for message file

HKEY_LOCAL_MACHINE
     SYSTEM
          CurrentControlSet
               Services
                    EventLog
                         Application
                              <MYAPPLICATION>
-Create a EventMessageType value under MYAPPLICATION ,and set the value to the  message dll generated using step 4

6. Get the handle to the eventlog source in the registry
7. Log the event into the log
8. Release the handle

Sample code for steps 6 to 8
——————————————

HANDLE h;
h = RegisterEventSource(NULL,”MYAPPLICATION”);           // Step 6

if (!ReportEvent(h,EVENTLOG_ERROR_TYPE,0,100,NULL,0,0,NULL,NULL))                // Step 7
{
   printf(“Could not report the event.”);
}

DeregisterEventSource(h); //Step 8

9. Read/open the log programatically or view it using eventvwr.
   -Run EventVwr and check the for the event entry

Posted in MFC | Leave a Comment »

Microsoft codenames…

Posted by kiraninbng on July 10, 2006

Whidbey – VS2005
Yukon – MSSQL2005
Avalon – Windows Presentation foundation(WPF)
Indigo –  Windows Communication foundation(WCF)
Longhorn – Windows Vista

ofcourse it is not possible to post all the codenames..so heres the complete list.

Posted in General | Leave a Comment »

Pointer to member functions

Posted by kiraninbng on July 10, 2006

A pointer to a member function consists of return type, the class name followed by ::, the function pointer name and the
function’s parameter list.

Ex :

class CTest
{
 int fn();
}

// pmCTest is a pointer to a member function which takes int as the parameter
int CTest::*pmCTest();
Below code shows how to invoke the pointer to member function,

pmCTest = &CTest::fn;
CTest oCTest;
CTest *pCTest = &oCTest;
// Invoke the member function using an object
(oCTest.*pmCTest)();
// Invoke the member function using an object pointer
(pCTest->*pmCTest)();

If you call virtual member function using a pointer to member function, the call will get resolved dynamically.

Also the size of the pointer to member function can change depending on whether the class is inherited from a single class
or from multiple classes.

Posted in General | Leave a Comment »

embedded pdb path…

Posted by kiraninbng on July 8, 2006

Dumpbin is a command line utility used for extracting various information like headers,imported and exported functions etc from the exe or dll.

For more information u can check http://support.microsoft.com/kb/q177429/.

So how do u find the embedded pdb path,just give

Dumpbin /headers <exe name>

and then search for the debug directories section in the output of the dumpbin,u will find something like this,

Debug Directories

Type    Size  RVA    Pointer
—— —— —–  ——–
cv       30  00000000 2A000    Format: NB10, 44a89304, 2, D:\DELETE\ExeNameDebug\ExeName.pdb

Posted in General | 1 Comment »