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

}

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

2009年5月18日 星期一

install windows sdk

1. install .net framework
2. install 6.0.6001.18000.367-KRMSDK_EN.iso

2009年5月15日 星期五

using vshadow.exe

ex:
vshadow.exe -nw -p F:
// create a shadow copy for F:

2009年5月14日 星期四

2009年5月13日 星期三

ddk version

3790 : windows server 2003 sdk

6000: windows vista sdk

6001.18000: windows server 2008 sdk

2009年4月23日 星期四

create a new atl project in visual

1. new project --> atl project --> 應用程式設定 --> 伺服程式類型 -- > service (EXE)
(Attributed check box is not selected.)

CServiceModule

1. CServiceModule::ServiceMain

2 CServiceModule::Start

3. CServiceModule::Run


前置處理器設定 in visual

資源 --> 前置處理器定義

2009年4月22日 星期三

link設定 in visual

連結器 --> 一般 --> 其它程式庫目錄
link到的lib所在的目錄

連結器 --> 輸入 --> 其他相依性
link到的lib

compile jni program on windows

c/c++ --> 一般 --> 其它include目錄
C:\Program Files\Java\jdk1.6.0_07\include
C:\Program Files\Java\jdk1.6.0_07\include\win32


c/c++ --> 進階 --> 強制include檔
C:\Program Files\Java\jdk1.6.0_07\include\jni.h

LPTSTR problem

LPTSTR has one of two possible definitions depending on whether you're duing a Unicode build or not

wcslen only works on Unicode strings, so in an ANSI build, LPTSTR and wcslen are incompatible

solution: add UNICODE in preprocessor definations

2009年4月19日 星期日

compile project with ddk

設定:
工具 ---> 選項 --> 專案 --> VC++目錄 --> include檔案
add C:\WinDDK\6001.18000\inc\api

工具 ---> 選項 --> 專案 --> VC++目錄 --> 可執行檔
add C:\WinDDK\6001.18000\bin\x86