2009年9月8日 星期二

get wdk

get wdk from http://www.microsoft.com/whdc/devtools/wdk/WDKpkg.mspx
the latest wdk now is wdk 7.0.0
I get GRMWDK_EN_7600.ISO


note:
After installing WDK in one machine , you can build driver for different version of windows & different CPU

2009年7月3日 星期五

memory management

allocate object:
CoTaskMemAlloc

free object:
CoTaskMemFree

macro for interface method

STDMETHOD:
for method definition, return type must be HRESULT

STDMETHOD_(type)
for method definition, return type is not HRESULT

STDMETHODIMP:
for method implementation, return type must be HRESULT

STDMETHODIMP_(type):
for method implementation, return type is not HRESULT

2009年7月2日 星期四

MIDL

define interface example:

[ object,
uuid(FC3B3F61-BCEC-11D1-91FE-E1CBED988F66)
]
interface IStack : IUnknown
{
import "unknwn.idl";
HRESULT Push([in] long value);
HRESULT Pop([out, retval] long* pVal);
HRESULT Empty([out, retval] boolean* pVal);
};

the mapping c++ code:

#include "wtypes.h"

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

class IStack : public IUnknown {
public:
virtual HRESULT Push(long value) = 0;
virtual HRESULT Pop(long* value) = 0;
virtual HRESULT Empty(long* flag) = 0;
};

or

#include "wtypes.h"

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

DECLARE_INTERFACE_(IStack, IUnknown)
{
// *** IStack methods *** //
STDMETHOD(Push) (THIS_ long value) PURE;
STDMETHOD(Pop) (THIS_ long* value) PURE;
STDMETHOD(Empty) (THIS_ long* flag) PURE;
};

interface and class of com

A COM interface is a set of related methods that have a well-defined contract but have no implementation. A COM class implements one or more interfaces, and all the services a COM class exports are defined by the interfaces it implements. Callers access the services of a COM object by calling the methods defined by its interfaces.

an interface is an abstract class that defines a set of public, pure virtual functions and contains no data members.

ex:
class IUnknown {
public:
virtual HRESULT QueryInterface(REFIID riid, void** ppv) = 0;
virtual unsigned long AddRef() = 0;
virtual unsigned long Release()= 0;
};

com

language transparency

location transparency

use MIDL(microsoft interface definition language) to define method of com interface

unique naming of class & interface: GUID

binary object model:
defines how objects are laid out in memory (hence binary). This permits any programming language or any development tool to create a COM object as long as it is capable of laying out the memory in a manner that conforms with the COM specification and calling the appropriate COM routines.

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);

}