COM IDispatch接口封装

AbstractDispatch.idl
import "unknwn.idl";
import "oaidl.idl";
coclass CAbstractDispatch;
interface IAbstractDispatch;
[
	// {35EE0AE4-D79B-4d50-8532-F27911171EC5}
	//static const GUID <<name>> = { 0x35ee0ae4, 0xd79b, 0x4d50, { 0x85, 0x32, 0xf2, 0x79, 0x11, 0x17, 0x1e, 0xc5 } };
	object,
	uuid(35EE0AE4-D79B-4d50-8532-F27911171EC5),
	pointer_default(unique),
	dual,
	oleautomation
]
interface IAbstractDispatch:IDispatch
{
	[id(1), helpstring("初始化")]HRESULT Init();
	[id(2), helpstring("释放资源")]HRESULT Destory();
};
[
	// {7D969C16-F84C-45e8-9922-CC0C41E351BC}
	//static const GUID <<name>> = {0x7d969c16, 0xf84c, 0x45e8, { 0x99, 0x22, 0xcc, 0xc, 0x41, 0xe3, 0x51, 0xbc } };

	uuid(7D969C16-F84C-45e8-9922-CC0C41E351BC),
	version(1.0)
]
library AbstractDispatchLib
{
	importlib("stdole2.tlb");
	// {64DCAD3D-B39C-4b96-902D-8059336C3410}
	//static const GUID <<name>> = { 0x64dcad3d, 0xb39c, 0x4b96, { 0x90, 0x2d, 0x80, 0x59, 0x33, 0x6c, 0x34, 0x10 } };
	[
		uuid(64DCAD3D-B39C-4b96-902D-8059336C3410)
	]
	coclass CAbstractDispatch
	{
		[default]interface IAbstractDispatch;
	};
};

 

CCOMIDispatchImpl.h
#ifndef __unknwn_h__
#include <objbase.h>
#include <unknwn.h>
#endif
class CCOMIDispatchImpl:public IDispatch
{
	public:
		CCOMIDispatchImpl(REFGUID rgUid,REFGUID clsUid,OLECHAR* file)
		{
			Init(rgUid,clsUid,file);
		}
		virtual HRESULT _stdcall Init(REFGUID rgUid,REFGUID clsUid,OLECHAR* file)
		{
			HRESULT hr=NULL;
			ITypeLib* t_t=NULL;
			if(m_pi==NULL)
			{
				hr=LoadRegTypeLib(rgUid,1,0,0x00,&t_t);
				if(FAILED(hr))
				{
					return hr;
				}
				hr=LoadTypeLib(file,&t_t);
				if(FAILED(hr))
				{
					return hr;
				}
				hr=RegisterTypeLib(t_t,file,NULL);
				if(FAILED(hr))
				{
					return hr;
				}
				HRESULT hr=t_t->GetTypeInfoOfGuid(clsUid,&m_pi);
				t_t->Release();
				if(FAILED(hr))
				{
					return hr;
				}
			}
			return S_OK;
		}
		virtual HRESULT _stdcall QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
		{
			return S_OK;
		}
		virtual ULONG _stdcall  AddRef()
		{
			return InterlockedIncrement(&m_comRef);
		}
		virtual ULONG _stdcall Release()
		{
			if(InterlockedDecrement(&m_comRef)==0)
			{
				delete this;
				return 0;
			}
			return m_comRef;
		}
		virtual HRESULT _stdcall GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
		{
			*ppTInfo=NULL;
			if(iTInfo!=0)
			{
				return DISP_E_BADINDEX;
			}
			m_pi->AddRef();
			*ppTInfo=m_pi;
			return S_OK;
		}
		virtual HRESULT _stdcall GetTypeInfoCount(UINT __RPC_FAR *pctinfo)
		{
			*pctinfo=1;
			return S_OK;
		}
		virtual HRESULT _stdcall GetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId)
		{
			if(riid!=IID_NULL)
			{
				return DISP_E_UNKNOWNINTERFACE;
			}
			HRESULT hr=m_pi->GetIDsOfNames(rgszNames,cNames,rgDispId);
			return hr;
		}
		virtual HRESULT _stdcall Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr)
		{
			if(riid!=IID_NULL)
			{
				return DISP_E_UNKNOWNINTERFACE;
			}
			SetErrorInfo(0,NULL);
			HRESULT hr=m_pi->Invoke(static_cast<IDispatch*>(this),dispIdMember,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr);
			return hr;
		}
	protected:
		long m_comRef;
		ITypeInfo* m_pi;
};

 

AbstractDispatch.h
/* this ALWAYS GENERATED file contains the definitions for the interfaces */


/* File created by MIDL compiler version 5.01.0164 */
/* at Sun Jan 03 20:26:24 2010
 */
/* Compiler settings for AbstractDispatch.idl:
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data 
*/
//@@MIDL_FILE_HEADING(  )


/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 440
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__

#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/

#ifndef __AbstractDispatch_h__
#define __AbstractDispatch_h__

#ifdef __cplusplus
extern "C"{
#endif 

/* Forward Declarations */ 

#ifndef __IAbstractDispatch_FWD_DEFINED__
#define __IAbstractDispatch_FWD_DEFINED__
typedef interface IAbstractDispatch IAbstractDispatch;
#endif 	/* __IAbstractDispatch_FWD_DEFINED__ */


#ifndef __CAbstractDispatch_FWD_DEFINED__
#define __CAbstractDispatch_FWD_DEFINED__

#ifdef __cplusplus
typedef class CAbstractDispatch CAbstractDispatch;
#else
typedef struct CAbstractDispatch CAbstractDispatch;
#endif /* __cplusplus */

#endif 	/* __CAbstractDispatch_FWD_DEFINED__ */


/* header files for imported files */
#include "unknwn.h"
#include "oaidl.h"

void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void __RPC_FAR * ); 

/* interface __MIDL_itf_AbstractDispatch_0000 */
/* [local] */ 





extern RPC_IF_HANDLE __MIDL_itf_AbstractDispatch_0000_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_AbstractDispatch_0000_v0_0_s_ifspec;

#ifndef __IAbstractDispatch_INTERFACE_DEFINED__
#define __IAbstractDispatch_INTERFACE_DEFINED__

/* interface IAbstractDispatch */
/* [oleautomation][dual][unique][uuid][object] */ 


EXTERN_C const IID IID_IAbstractDispatch;

#if defined(__cplusplus) && !defined(CINTERFACE)
    
    MIDL_INTERFACE("35EE0AE4-D79B-4d50-8532-F27911171EC5")
    IAbstractDispatch : public IDispatch
    {
    public:
        virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Init( void) = 0;
        
        virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Destory( void) = 0;
        
    };
    
#else 	/* C style interface */

    typedef struct IAbstractDispatchVtbl
    {
        BEGIN_INTERFACE
        
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )( 
            IAbstractDispatch __RPC_FAR * This,
            /* [in] */ REFIID riid,
            /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
        
        ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )( 
            IAbstractDispatch __RPC_FAR * This);
        
        ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( 
            IAbstractDispatch __RPC_FAR * This);
        
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfoCount )( 
            IAbstractDispatch __RPC_FAR * This,
            /* [out] */ UINT __RPC_FAR *pctinfo);
        
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetTypeInfo )( 
            IAbstractDispatch __RPC_FAR * This,
            /* [in] */ UINT iTInfo,
            /* [in] */ LCID lcid,
            /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
        
        HRESULT ( STDMETHODCALLTYPE __RPC_FAR *GetIDsOfNames )( 
            IAbstractDispatch __RPC_FAR * This,
            /* [in] */ REFIID riid,
            /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
            /* [in] */ UINT cNames,
            /* [in] */ LCID lcid,
            /* [size_is][out] */ DISPID __RPC_FAR *rgDispId);
        
        /* [local] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Invoke )( 
            IAbstractDispatch __RPC_FAR * This,
            /* [in] */ DISPID dispIdMember,
            /* [in] */ REFIID riid,
            /* [in] */ LCID lcid,
            /* [in] */ WORD wFlags,
            /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
            /* [out] */ VARIANT __RPC_FAR *pVarResult,
            /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
            /* [out] */ UINT __RPC_FAR *puArgErr);
        
        /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Init )( 
            IAbstractDispatch __RPC_FAR * This);
        
        /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE __RPC_FAR *Destory )( 
            IAbstractDispatch __RPC_FAR * This);
        
        END_INTERFACE
    } IAbstractDispatchVtbl;

    interface IAbstractDispatch
    {
        CONST_VTBL struct IAbstractDispatchVtbl __RPC_FAR *lpVtbl;
    };

    

#ifdef COBJMACROS


#define IAbstractDispatch_QueryInterface(This,riid,ppvObject)	\
    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)

#define IAbstractDispatch_AddRef(This)	\
    (This)->lpVtbl -> AddRef(This)

#define IAbstractDispatch_Release(This)	\
    (This)->lpVtbl -> Release(This)


#define IAbstractDispatch_GetTypeInfoCount(This,pctinfo)	\
    (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo)

#define IAbstractDispatch_GetTypeInfo(This,iTInfo,lcid,ppTInfo)	\
    (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo)

#define IAbstractDispatch_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)	\
    (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)

#define IAbstractDispatch_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)	\
    (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)


#define IAbstractDispatch_Init(This)	\
    (This)->lpVtbl -> Init(This)

#define IAbstractDispatch_Destory(This)	\
    (This)->lpVtbl -> Destory(This)

#endif /* COBJMACROS */


#endif 	/* C style interface */



/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE IAbstractDispatch_Init_Proxy( 
    IAbstractDispatch __RPC_FAR * This);


void __RPC_STUB IAbstractDispatch_Init_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);


/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE IAbstractDispatch_Destory_Proxy( 
    IAbstractDispatch __RPC_FAR * This);


void __RPC_STUB IAbstractDispatch_Destory_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase);



#endif 	/* __IAbstractDispatch_INTERFACE_DEFINED__ */



#ifndef __AbstractDispatchLib_LIBRARY_DEFINED__
#define __AbstractDispatchLib_LIBRARY_DEFINED__

/* library AbstractDispatchLib */
/* [uuid] */ 


EXTERN_C const IID LIBID_AbstractDispatchLib;

EXTERN_C const CLSID CLSID_CAbstractDispatch;

#ifdef __cplusplus

class DECLSPEC_UUID("64DCAD3D-B39C-4b96-902D-8059336C3410")
CAbstractDispatch;
#endif
#endif /* __AbstractDispatchLib_LIBRARY_DEFINED__ */

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif

 

AbstractDispatch_i.c
/* this file contains the actual definitions of */
/* the IIDs and CLSIDs */

/* link this file in with the server and any clients */


/* File created by MIDL compiler version 5.01.0164 */
/* at Sun Jan 03 20:26:24 2010
 */
/* Compiler settings for AbstractDispatch.idl:
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data 
*/
//@@MIDL_FILE_HEADING(  )
#ifdef __cplusplus
extern "C"{
#endif 


#ifndef __IID_DEFINED__
#define __IID_DEFINED__

typedef struct _IID
{
    unsigned long x;
    unsigned short s1;
    unsigned short s2;
    unsigned char  c[8];
} IID;

#endif // __IID_DEFINED__

#ifndef CLSID_DEFINED
#define CLSID_DEFINED
typedef IID CLSID;
#endif // CLSID_DEFINED

const IID IID_IAbstractDispatch = {0x35EE0AE4,0xD79B,0x4d50,{0x85,0x32,0xF2,0x79,0x11,0x17,0x1E,0xC5}};


const IID LIBID_AbstractDispatchLib = {0x7D969C16,0xF84C,0x45e8,{0x99,0x22,0xCC,0x0C,0x41,0xE3,0x51,0xBC}};


const CLSID CLSID_CAbstractDispatch = {0x64DCAD3D,0xB39C,0x4b96,{0x90,0x2D,0x80,0x59,0x33,0x6C,0x34,0x10}};


#ifdef __cplusplus
}
#endif

AbstractDispatch_p.c
/* this ALWAYS GENERATED file contains the proxy stub code */


/* File created by MIDL compiler version 5.01.0164 */
/* at Sun Jan 03 20:26:24 2010
 */
/* Compiler settings for AbstractDispatch.idl:
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data 
*/
//@@MIDL_FILE_HEADING(  )


/* verify that the <rpcproxy.h> version is high enough to compile this file*/
#ifndef __REDQ_RPCPROXY_H_VERSION__
#define __REQUIRED_RPCPROXY_H_VERSION__ 440
#endif


#include "rpcproxy.h"
#ifndef __RPCPROXY_H_VERSION__
#error this stub requires an updated version of <rpcproxy.h>
#endif // __RPCPROXY_H_VERSION__


#include "AbstractDispatch.h"

#define TYPE_FORMAT_STRING_SIZE   3                                 
#define PROC_FORMAT_STRING_SIZE   3                                 

typedef struct _MIDL_TYPE_FORMAT_STRING
    {
    short          Pad;
    unsigned char  Format[ TYPE_FORMAT_STRING_SIZE ];
    } MIDL_TYPE_FORMAT_STRING;

typedef struct _MIDL_PROC_FORMAT_STRING
    {
    short          Pad;
    unsigned char  Format[ PROC_FORMAT_STRING_SIZE ];
    } MIDL_PROC_FORMAT_STRING;


extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;
extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;


/* Standard interface: __MIDL_itf_AbstractDispatch_0000, ver. 0.0,
   GUID={0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} */


/* Object interface: IUnknown, ver. 0.0,
   GUID={0x00000000,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}} */


/* Object interface: IDispatch, ver. 0.0,
   GUID={0x00020400,0x0000,0x0000,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}} */


/* Object interface: IAbstractDispatch, ver. 0.0,
   GUID={0x35EE0AE4,0xD79B,0x4d50,{0x85,0x32,0xF2,0x79,0x11,0x17,0x1E,0xC5}} */


extern const MIDL_STUB_DESC Object_StubDesc;


#pragma code_seg(".orpc")

/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE IAbstractDispatch_Init_Proxy( 
    IAbstractDispatch __RPC_FAR * This)
{

    HRESULT _RetVal;
    
    RPC_MESSAGE _RpcMessage;
    
    MIDL_STUB_MESSAGE _StubMsg;
    
    RpcTryExcept
        {
        NdrProxyInitialize(
                      ( void __RPC_FAR *  )This,
                      ( PRPC_MESSAGE  )&_RpcMessage,
                      ( PMIDL_STUB_MESSAGE  )&_StubMsg,
                      ( PMIDL_STUB_DESC  )&Object_StubDesc,
                      7);
        
        
        
        RpcTryFinally
            {
            
            _StubMsg.BufferLength = 0U;
            NdrProxyGetBuffer(This, &_StubMsg);
            NdrProxySendReceive(This, &_StubMsg);
            
            if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
                NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[0] );
            
            _RetVal = *(( HRESULT __RPC_FAR * )_StubMsg.Buffer)++;
            
            }
        RpcFinally
            {
            NdrProxyFreeBuffer(This, &_StubMsg);
            
            }
        RpcEndFinally
        
        }
    RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)
        {
        _RetVal = NdrProxyErrorHandler(RpcExceptionCode());
        }
    RpcEndExcept
    return _RetVal;
}

void __RPC_STUB IAbstractDispatch_Init_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase)
{
    HRESULT _RetVal;
    MIDL_STUB_MESSAGE _StubMsg;
    
NdrStubInitialize(
                     _pRpcMessage,
                     &_StubMsg,
                     &Object_StubDesc,
                     _pRpcChannelBuffer);
    RpcTryFinally
        {
        
        *_pdwStubPhase = STUB_CALL_SERVER;
        _RetVal = (((IAbstractDispatch*) ((CStdStubBuffer *)This)->pvServerObject)->lpVtbl) -> Init((IAbstractDispatch *) ((CStdStubBuffer *)This)->pvServerObject);
        
        *_pdwStubPhase = STUB_MARSHAL;
        
        _StubMsg.BufferLength = 4U;
        NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);
        *(( HRESULT __RPC_FAR * )_StubMsg.Buffer)++ = _RetVal;
        
        }
    RpcFinally
        {
        }
    RpcEndFinally
    _pRpcMessage->BufferLength = 
        (unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);
    
}


/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE IAbstractDispatch_Destory_Proxy( 
    IAbstractDispatch __RPC_FAR * This)
{

    HRESULT _RetVal;
    
    RPC_MESSAGE _RpcMessage;
    
    MIDL_STUB_MESSAGE _StubMsg;
    
    RpcTryExcept
        {
        NdrProxyInitialize(
                      ( void __RPC_FAR *  )This,
                      ( PRPC_MESSAGE  )&_RpcMessage,
                      ( PMIDL_STUB_MESSAGE  )&_StubMsg,
                      ( PMIDL_STUB_DESC  )&Object_StubDesc,
                      8);
        
        
        
        RpcTryFinally
            {
            
            _StubMsg.BufferLength = 0U;
            NdrProxyGetBuffer(This, &_StubMsg);
            NdrProxySendReceive(This, &_StubMsg);
            
            if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
                NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[0] );
            
            _RetVal = *(( HRESULT __RPC_FAR * )_StubMsg.Buffer)++;
            
            }
        RpcFinally
            {
            NdrProxyFreeBuffer(This, &_StubMsg);
            
            }
        RpcEndFinally
        
        }
    RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)
        {
        _RetVal = NdrProxyErrorHandler(RpcExceptionCode());
        }
    RpcEndExcept
    return _RetVal;
}

void __RPC_STUB IAbstractDispatch_Destory_Stub(
    IRpcStubBuffer *This,
    IRpcChannelBuffer *_pRpcChannelBuffer,
    PRPC_MESSAGE _pRpcMessage,
    DWORD *_pdwStubPhase)
{
    HRESULT _RetVal;
    MIDL_STUB_MESSAGE _StubMsg;
    
NdrStubInitialize(
                     _pRpcMessage,
                     &_StubMsg,
                     &Object_StubDesc,
                     _pRpcChannelBuffer);
    RpcTryFinally
        {
        
        *_pdwStubPhase = STUB_CALL_SERVER;
        _RetVal = (((IAbstractDispatch*) ((CStdStubBuffer *)This)->pvServerObject)->lpVtbl) -> Destory((IAbstractDispatch *) ((CStdStubBuffer *)This)->pvServerObject);
        
        *_pdwStubPhase = STUB_MARSHAL;
        
        _StubMsg.BufferLength = 4U;
        NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);
        *(( HRESULT __RPC_FAR * )_StubMsg.Buffer)++ = _RetVal;
        
        }
    RpcFinally
        {
        }
    RpcEndFinally
    _pRpcMessage->BufferLength = 
        (unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);
    
}


static const MIDL_STUB_DESC Object_StubDesc = 
    {
    0,
    NdrOleAllocate,
    NdrOleFree,
    0,
    0,
    0,
    0,
    0,
    __MIDL_TypeFormatString.Format,
    1, /* -error bounds_check flag */
    0x10001, /* Ndr library version */
    0,
    0x50100a4, /* MIDL Version 5.1.164 */
    0,
    0,
    0,  /* notify & notify_flag routine table */
    1,  /* Flags */
    0,  /* Reserved3 */
    0,  /* Reserved4 */
    0   /* Reserved5 */
    };

CINTERFACE_PROXY_VTABLE(9) _IAbstractDispatchProxyVtbl = 
{
    &IID_IAbstractDispatch,
    IUnknown_QueryInterface_Proxy,
    IUnknown_AddRef_Proxy,
    IUnknown_Release_Proxy ,
    0 /* IDispatch_GetTypeInfoCount_Proxy */ ,
    0 /* IDispatch_GetTypeInfo_Proxy */ ,
    0 /* IDispatch_GetIDsOfNames_Proxy */ ,
    0 /* IDispatch_Invoke_Proxy */ ,
    IAbstractDispatch_Init_Proxy ,
    IAbstractDispatch_Destory_Proxy
};


static const PRPC_STUB_FUNCTION IAbstractDispatch_table[] =
{
    STUB_FORWARDING_FUNCTION,
    STUB_FORWARDING_FUNCTION,
    STUB_FORWARDING_FUNCTION,
    STUB_FORWARDING_FUNCTION,
    IAbstractDispatch_Init_Stub,
    IAbstractDispatch_Destory_Stub
};

CInterfaceStubVtbl _IAbstractDispatchStubVtbl =
{
    &IID_IAbstractDispatch,
    0,
    9,
    &IAbstractDispatch_table[-3],
    CStdStubBuffer_DELEGATING_METHODS
};

#pragma data_seg(".rdata")

#if !defined(__RPC_WIN32__)
#error  Invalid build platform for this stub.
#endif

static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =
    {
        0,
        {
			0x53,		/* FC_RETURN_PARAM_BASETYPE */
			0x8,		/* FC_LONG */

			0x0
        }
    };

static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =
    {
        0,
        {
			NdrFcShort( 0x0 ),	/* 0 */

			0x0
        }
    };

const CInterfaceProxyVtbl * _AbstractDispatch_ProxyVtblList[] = 
{
    ( CInterfaceProxyVtbl *) &_IAbstractDispatchProxyVtbl,
    0
};

const CInterfaceStubVtbl * _AbstractDispatch_StubVtblList[] = 
{
    ( CInterfaceStubVtbl *) &_IAbstractDispatchStubVtbl,
    0
};

PCInterfaceName const _AbstractDispatch_InterfaceNamesList[] = 
{
    "IAbstractDispatch",
    0
};

const IID *  _AbstractDispatch_BaseIIDList[] = 
{
    &IID_IDispatch,
    0
};


#define _AbstractDispatch_CHECK_IID(n)	IID_GENERIC_CHECK_IID( _AbstractDispatch, pIID, n)

int __stdcall _AbstractDispatch_IID_Lookup( const IID * pIID, int * pIndex )
{
    
    if(!_AbstractDispatch_CHECK_IID(0))
        {
        *pIndex = 0;
        return 1;
        }

    return 0;
}

const ExtendedProxyFileInfo AbstractDispatch_ProxyFileInfo = 
{
    (PCInterfaceProxyVtblList *) & _AbstractDispatch_ProxyVtblList,
    (PCInterfaceStubVtblList *) & _AbstractDispatch_StubVtblList,
    (const PCInterfaceName * ) & _AbstractDispatch_InterfaceNamesList,
    (const IID ** ) & _AbstractDispatch_BaseIIDList,
    & _AbstractDispatch_IID_Lookup, 
    1,
    1,
    0, /* table of [async_uuid] interfaces */
    0, /* Filler1 */
    0, /* Filler2 */
    0  /* Filler3 */
};
 

 

CAbstractDispatch.h
#include "AbstractDispatch.h"
class CAbstractDispatch:public IAbstractDispatch
{
public:
	CAbstractDispatch();
	CAbstractDispatch(ITypeInfo* m_p);
	virtual HRESULT _stdcall Init();
	virtual HRESULT _stdcall Destory();
	virtual ULONG _stdcall AddRef();
	virtual ULONG _stdcall Release();
	virtual HRESULT _stdcall QueryInterface(const IID& riid,void** ppvObject)=0;
	/************************************************************************/
	/* 读取一个函数名称,返回调度ID DISPID长整数索引(函数指针数组),由自动化化控制程序调用invoke                                                               
	/************************************************************************/
	virtual HRESULT _stdcall GetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId);
	/************************************************************************/
	/*                                                                      
	/************************************************************************/
	virtual HRESULT _stdcall GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
	/************************************************************************/
	/* 自动化组件支持接口的数目  ITypeInfo                                                                 
	/************************************************************************/
	virtual HRESULT _stdcall GetTypeInfoCount(UINT __RPC_FAR *pctinfo);
	virtual HRESULT _stdcall Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
protected:
	ITypeInfo* m_pITtypeInfo;
	long m_ref;
};
const CLSID CLS_CABSTRACTDISPATCH = { 0x64dcad3d, 0xb39c, 0x4b96, { 0x90, 0x2d, 0x80, 0x59, 0x33, 0x6c, 0x34, 0x10 } };

 

 

CAbstractDispatch.cpp
#include "CAbstractDispatch.h"
//#include "CCOMIDispatchImpl.h"
//extern GUID LIBID_SERVER;
//extern IID IID_IX;
CAbstractDispatch::CAbstractDispatch()
{
	m_ref=0;
	m_pITtypeInfo=NULL;
	Init();
}
CAbstractDispatch::CAbstractDispatch(ITypeInfo* m_p)
{
	m_pITtypeInfo=m_p;
}
HRESULT _stdcall CAbstractDispatch::Destory()
{
	return S_OK;
}

HRESULT _stdcall CAbstractDispatch::Init()
{
	/**
	HRESULT hr;
	if(m_pITtypeInfo==NULL)
	{
		ITypeLib* pITypeLib=NULL;
			hr=LoadRegTypeLib(LIBID_SERVER,1.0,0x00,NULL,&pITypeLib);
			if(FAILED(hr))
			{
				hr=LoadTypeLib(L"Server.lib",&pITypeLib);
				if(FAILED(hr))
				{
					return hr;
				}
				hr=RegisterTypeLib(pITypeLib,L"Server.tlb",NULL);
				if (FAILED(hr))
				{
					return hr;
				}
			}
			hr=pITypeLib->GetTypeInfoOfGuid(IID_IX,&m_pITtypeInfo);
			pITypeLib->Release();
			if(FAILED(hr))
			{
				return hr;
			}
			
	}
	*/
	return S_OK;
}

/**
HRESULT _stdcall CAbstractDispatch::QueryInterface(const IID& riid,void** ppvObject)
{
	return S_OK;
}
*/
ULONG _stdcall CAbstractDispatch::AddRef()
{
	return InterlockedIncrement(&m_ref);
}
ULONG _stdcall CAbstractDispatch::Release()
{
	if(InterlockedDecrement(&m_ref)==0)
	{
		delete this;
		return 0;
	}
	return m_ref;
}
HRESULT _stdcall CAbstractDispatch::GetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId)
{
	if(riid!=IID_NULL)
	{
		return DISP_E_UNKNOWNINTERFACE;
	}
	HRESULT hr=m_pITtypeInfo->GetIDsOfNames(rgszNames,cNames,rgDispId);
	return hr;
}
HRESULT _stdcall CAbstractDispatch::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
{
	*ppTInfo=NULL;
	if(iTInfo!=0)
	{
		return DISP_E_BADINDEX;
	}
	m_pITtypeInfo->AddRef();
	*ppTInfo=m_pITtypeInfo;
	return S_OK;

}
HRESULT _stdcall CAbstractDispatch::GetTypeInfoCount(UINT __RPC_FAR *pctinfo)
{
	*pctinfo=1;
	return S_OK;
}
HRESULT _stdcall CAbstractDispatch::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr)
{
	if(riid!=IID_NULL)
	{
		return DISP_E_UNKNOWNINTERFACE;
	}
	SetErrorInfo(0,NULL);
	HRESULT hr=m_pITtypeInfo->Invoke(static_cast<IDispatch*>(this),dispIdMember,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr);
	return hr;
}

 

dlldata.c
/*********************************************************
   DllData file -- generated by MIDL compiler 

        DO NOT ALTER THIS FILE

   This file is regenerated by MIDL on every IDL file compile.

   To completely reconstruct this file, delete it and rerun MIDL
   on all the IDL files in this DLL, specifying this file for the
   /dlldata command line option

*********************************************************/

#define PROXY_DELEGATION

#include <rpcproxy.h>

#ifdef __cplusplus
extern "C"   {
#endif

EXTERN_PROXY_FILE( AbstractDispatch )


PROXYFILE_LIST_START
/* Start of list */
  REFERENCE_PROXY_FILE( AbstractDispatch ),
/* End of list */
PROXYFILE_LIST_END


DLLDATA_ROUTINES( aProxyFileList, GET_DLL_CLSID )

#ifdef __cplusplus
}  /*extern "C" */
#endif

/* end of generated dlldata file */

 

你可能感兴趣的:(C++,c,C#,OS,ext)