雙介面元件的簡單實現

2021-04-15 01:42:43 字數 2893 閱讀 3186

//math.h

////

math.h 

////

access to the global variables

extern

dword g_dwobjs;

extern

dword g_dwlocks;

const

intdispid_add =1

;const

intdispid_subtract =2

;const

intdispid_multiply =3

;const

intdispid_divide =4

;class

math : 

public

imath

// 而對於idispatch介面 class

math : 

public

idispatch

;class

mathclassfactory : 

public

iclassfactory;

//

math.cpp

////

math.cpp

////

#include 

<

windows.h

>

#include 

"dualserver.h

"#include 

"math.h"//

//math class implementation

////

constructors

math::math()

math::

~math()

//iunknown implementation

stdmethodimp math::queryinte***ce( refiid riid, 

void

**ppv )

return

e_nointe***ce;

}stdmethodimp_(ulong) math::addref()

stdmethodimp_(ulong) math::release()

//idispatch implementation

stdmethodimp math::gettypeinfocount( uint

*pctinfo )

stdmethodimp math::gettypeinfo( uint itinfo,

lcid lcid,

itypeinfo

**pptinfo )

stdmethodimp math::getidsofnames( refiid riid,

olechar

**rgsznames,

uint cnames,

lcid lcid,

dispid

*rgdispid )

stdmethodimp math::invoke( dispid dispid,

refiid riid,

lcid lcid,

word wflags,

dispparams far

*pdispparams,

variant far

*pvarresult,

excepinfo far

*pexcepinfo,

unsigned 

intfar

*puargerr )

else

return

s_ok;

switch

( dispid )}

//imath implementation

stdmethodimp math::add(

long

lop1, 

long

lop2, 

long

*plresult)

stdmethodimp math::subtract(

long

lop1, 

long

lop2, 

long

*plresult)

stdmethodimp math::multiply(

long

lop1, 

long

lop2, 

long

*plresult)

stdmethodimp math::divide(

long

lop1, 

long

lop2, 

long

*plresult)

mathclassfactory::mathclassfactory()

mathclassfactory::

~mathclassfactory()

stdmethodimp mathclassfactory::queryinte***ce( refiid riid, 

void

**ppv )

return

(e_nointe***ce);

}stdmethodimp_(ulong) mathclassfactory::addref()

stdmethodimp_(ulong) mathclassfactory::release()

stdmethodimp mathclassfactory::createinstance

( lpunknown punkouter, refiid riid, 

void

**ppvobj )

stdmethodimp mathclassfactory::lockserver( bool flock )

IDispatch介面元件的簡單實現

math.h math.h access to the global variables extern dword g dwobjs extern dword g dwlocks define guid clsid math,0xa988bd40 0x9f1a 0x11ce 0x8b 0x9f 0x...

雙鏈表介面的簡單實現

雙向鍊錶相當於單鏈表來說,實現的幾個介面無疑是比較簡單的,在這一篇部落格中,我將會整理一下關於雙向鍊錶的幾個介面實現的過程,希望各位大佬多多指正。1.首先建立乙個帶有雙向鍊錶的節點 如下 typedef int ltdatatype typedef struct listnode listnode ...

雙鏈表的簡單實現

include include include typedef int elemtype using namespace std typedef struct dulnode dulnode,dulinklist 建立帶有頭結點的雙鏈表,順序輸入 void createdulist dl dulin...