2009年6月4日 星期四

IUnknown

root of all com interface

ex:
[object, uuid(DA4A270-AIBA-lldO-BC2C-OOBOC73925BA)]
interface ITest : IUnknown {
import "unknwn.idl" // bring in definition of IUnknown
HRESULT test(void);

}

GUID

globally unique identifier

128-bit

32 hexadecimal digit

ex:
BDA4A270-AIBA-lldO-BC2C-OOBOC73925BA

com interface & com implementation both have GUID

ex:
[object, uuid( BDA4A270-AIBA-lldO-BC2C-OOBOC73925BA)]
interface ITtest : IBaseInterface {
HRESULT add(void);
}

GUID structure in COM:
typedef struct _GUID {
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} GUID;
typedef GUID IID; // GUID for interface
typedef GUID CLSID; // GUID for class implementation

CLSID: class id
IID: interface id
ex:
#include "wtypes.h"

// {FC3B3F61-BCEC-11D1-91FE-E1CBED988F66}
DEFINE_GUID(IID_IStack,
0xFC3B3F61, 0xBCEC, 0x11D1, 0x91, 0xFE,
0xE1, 0xCB, 0xED, 0x98, 0x8F, 0x66);

create new GUID:
1. use guidgen.exe
2. CoCreateGuid

DLL

dynamic link library (DLL)

package the class in DLL, then this class can be reused
when the implementation of class is modified, the client program does not need to rebuild

problem:
ex:
test.DLL has two version,
version 1: class Test is 4 bytes
version 2: class Test is 8 bytes
If user installed test.DLL version 2, then client program originally use test.DLL version one will fail because it thinks the class Test is 4 bytes

2009年6月3日 星期三

regedit.exe

register editor

.vcproj

the setting for project is define in .vcproj file