ATL包容实例模板.doc_第1页
ATL包容实例模板.doc_第2页
ATL包容实例模板.doc_第3页
ATL包容实例模板.doc_第4页
ATL包容实例模板.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/Contain/Contain.idl/ Contain.idl : IDL source for Contain.dll/ This file will be processed by the MIDL tool to/ produce the type library (Contain.tlb) and marshalling code.import oaidl.idl;import ocidl.idl;uuid(380F79EA-4098-11D1-883A-444553540000),helpstring(IMath Interface),pointer_default(unique)interface IMath : IUnknownhelpstring(method Add) HRESULT Add(long lOp1, long lOp2, long* plResult);helpstring(method Subtract) HRESULT Subtract(long lOp1, long lOp2, long* plResult);helpstring(method Multiply) HRESULT Multiply(long lOp1, long lOp2, long* plResult);helpstring(method Divide) HRESULT Divide(long lOp1, long lOp2, long* plResult);uuid(380F79F9-4098-11D1-883A-444553540000),helpstring(IAdvancedMath Interface),pointer_default(unique)interface IAdvancedMath : IUnknownhelpstring(method Factorial) HRESULT Factorial( short sOp, long* plResult );helpstring(method Fibonacci) HRESULT Fibonacci( short sOp, long* plResult );uuid(380F79FD-4098-11D1-883A-444553540000),version(1.0),helpstring(Contain 1.0 Type Library)library CONTAINLibimportlib(stdole32.tlb);importlib(stdole2.tlb);uuid(380F7A0B-4098-11D1-883A-444553540000),helpstring(AdvancedMath Class)coclass AdvancedMathdefault interface IAdvancedMath;interface IMath;/Contain/Containps.defLIBRARY ContainPSDESCRIPTION Proxy/Stub DLLEXPORTSDllGetClassObject 1PRIVATEDllCanUnloadNow 2PRIVATEGetProxyDllInfo 3PRIVATEDllRegisterServer4PRIVATEDllUnregisterServer5PRIVATE/Contain/Containps.mkContainps.dll: dlldata.obj Contain_p.obj Contain_i.objlink /dll /out:Containps.dll /def:Containps.def /entry:DllMain dlldata.obj Contain_p.obj Contain_i.obj kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib oleaut32.lib uuid.lib .c.obj:cl /c /Ox /DWIN32 /D_WIN32_WINNT=0x0400 /DREGISTER_PROXY_DLL $ 1 ) return n * calcFactorial( n - 1 ); else return 1;STDMETHODIMP CAdvancedMath:Factorial( short sOp, long* plResult ) *plResult = calcFactorial( sOp ); return S_OK;long calcFibonacci( short n ) if ( n Add( lOp1, lOp2, plResult );STDMETHODIMP CAdvancedMath:Subtract(long lOp1, long lOp2, long * plResult) return m_pSimpleMath-Subtract( lOp1, lOp2, plResult );STDMETHODIMP CAdvancedMath:Multiply(long lOp1, long lOp2, long * plResult) return m_pSimpleMath-Multiply( lOp1, lOp2, plResult );STDMETHODIMP CAdvancedMath:Divide(long lOp1, long lOp2, long * plResult) return m_pSimpleMath-Divide( lOp1, lOp2, plResult );/Contain/AdvancedMath.h/ AdvancedMath.h : Declaration of the CAdvancedMath#ifndef _ADVANCEDMATH_H_#define _ADVANCEDMATH_H_#include resource.h / main symbolsconst CLSID CLSID_SimpleMath = 0x380F79EB,0x4098,0x11D1,0x88,0x3A,0x44,0x45,0x53,0x54,0x00,0x00;/ CAdvancedMathclass ATL_NO_VTABLE CAdvancedMath : public CComObjectRootEx,public CComCoClass,public IAdvancedMath, public IMathpublic: CAdvancedMath() : m_pSimpleMath( 0 ) HRESULT FinalConstruct() HRESULT hr = CoCreateInstance( CLSID_SimpleMath, 0, CLSCTX_INPROC_SERVER, IID_IMath, (void*) &m_pSimpleMath ); return hr; void FinalRelease() if ( m_pSimpleMath ) m_pSimpleMath-Release(); DECLARE_REGISTRY_RESOURCEID(IDR_ADVANCEDMATH)BEGIN_COM_MAP(CAdvancedMath)COM_INTERFACE_ENTRY(IAdvancedMath)COM_INTERFACE_ENTRY(IMath)END_COM_MAP()/ IMath - We now must explicitly implement these methodspublic:STDMETHOD(Divide)(long lOp1, long lOp2, long* plResult);STDMETHOD(Multiply)(long lOp1, long lOp2, long* plResult);STDMETHOD(Subtract)(long lOp1, long lOp2, long* plResult);STDMETHOD(Add)(long lOp1, long lOp2, long* plResult);/ IAdvancedMathpublic:STDMETHOD(Fibonacci)( short sOp, long* plResult );STDMETHOD(Factorial)( short sOp, long* plResult );private: IMath* m_pSimpleMath;#endif /_ADVANCEDMATH_H_/Contain/AdvancedMath.rgsHKCRChapter5.Containment.1 = s AdvancedMath ClassCLSID = s 380F7A0B-4098-11D1-883A-444553540000Chapter5.Containment = s AdvancedMath ClassCurVer = s Chapter5.Containment.1CLSID = s 380F7A0B-4098-11D1-883A-444553540000NoRemove CLSIDForceRemove 380F7A0B-4098-11D1-883A-444553540000 = s AdvancedMath ClassProgID = s Chapter5.Containment.1VersionIndependentProgID = s Chapter5.ContainmentInprocServer32 = s %MODULE%val ThreadingModel = s Apartment/Contain/Contain.cpp/ Contain.cpp : Implementation of DLL Exports./ Note: Proxy/Stub Information/To build a separate proxy/stub DLL, /run nmake -f Containps.mk in the project directory.#include stdafx.h#include resource.h#include initguid.h#include Contain.h#include Contain_i.c#include AdvancedMath.hCComModule _Module;BEGIN_OBJECT_MAP(ObjectMap)OBJECT_ENTRY(CLSID_AdvancedMath, CAdvancedMath)END_OBJECT_MAP()/ DLL Entry Pointextern CBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)if (dwReason = DLL_PROCESS_ATTACH)_Module.Init(ObjectMap, hInstance);DisableThreadLibraryCalls(hInstance);else if (dwReason = DLL_PROCESS_DETACH)_Module.Term();return TRUE; / ok/ Used to determine whether the DLL can be unloaded by OLESTDAPI DllCanUnloadNow(void)return (_Module.GetLockCount()=0) ? S_OK : S_FALSE;/ Returns a class factory to create an object of the requested typeSTDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)return _Module.GetClassObject(rclsid, riid, ppv);/ DllRegisterServer - Adds entries to the system registrySTDAPI DllRegisterServer(void)/ registers object, typelib and all interfaces in typelibreturn _Module.RegisterServer(TRUE);/ DllUnregisterServer - Removes entries from the system registrySTDAPI DllUnregisterServer(void)_Module.UnregisterServer();return S_OK;/Contain/Contain.def; Contain.def : Declares the module parameters.LIBRARY Contain.DLLEXPORTSDllCanUnloadNow 1 PRIVATEDllGetClassObject 2 PRIVATEDllRegisterServer 3 PRIVATEDllUnregisterServer4 PRIVATE/Contain/Contain.rc/Microsoft Developer Studio generated resource script./#include resource.h#define APSTUDIO_READONLY_SYMBOLS/ Generated from the TEXTINCLUDE 2 resource./#include winres.h/#undef APSTUDIO_READONLY_SYMBOLS/ English (U.S.) resources#if !defined(AFX_RESOURCE_DLL) | defined(AFX_TARG_ENU)#ifdef _WIN32LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US#pragma code_page(1252)#endif /_WIN32#ifdef APSTUDIO_INVOKED/ TEXTINCLUDE/1 TEXTINCLUDE DISCARDABLE BEGIN resource.h0END2 TEXTINCLUDE DISCARDABLE BEGIN #include winres.hrn 0END3 TEXTINCLUDE DISCARDABLE BEGIN 1 TYPELIB Contain.tlbrn 0END#endif / APSTUDIO_INVOKED#ifndef _MAC/ Version/VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL#ifdef _DEBUG FILEFLAGS 0x1L#else FILEFLAGS 0x0L#endif FILEOS 0x4L FILETYPE 0x2L FILESUBTYPE 0x0LBEGIN BLOCK StringFileInfo BEGIN BLOCK 040904B0 BEGIN VALUE CompanyName, 0 VALUE FileDescription, Contain Module0 VALUE FileVersion, 1, 0, 0, 10 VALUE InternalName, CONTAIN0 VALUE LegalCopyright, Copyright 19970 VALUE OriginalFilename, CONTAIN.DLL0 VALUE ProductName, Contain Module0 VALUE ProductVersion, 1, 0, 0, 10 VALUE OLESelfRegister, 0 END END BLOCK VarFileInfo BEGIN VALUE Translation, 0x409, 1200 ENDEND#endif / !_MAC/ REGISTRY/IDR_ADVANCEDMATH REGISTRY DISCARDABLE AdvancedMath.rgs/ String Table/STRINGTABLE DISCARDABLE BEGIN IDS_PROJNAME ContainEND#endif / English (U.S.) resources/#ifndef APSTUDIO_INVOKED/ Generated from the TEXTINCLUDE 3 resource./1 TYPELIB Contain.tlb/#endif / not APSTUDIO_INVOKED/Contain/resource.h/_NO_DEPENDENCIES/ Microsoft Developer Studio generated include file./ Used by Contain.rc/#define IDS_PROJNAME 100#define IDR_ADVANCEDMATH 101/ Next default values for new objects/ #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 201#define _APS_NEXT_COMMAND_VALUE 32768#define _APS_NEXT_CONTROL_VALUE 201#define _APS_NEXT_SYMED_VALUE 102#endif#endif/Contain/StdAfx.cpp/ stdafx.cpp : source file that includes just the standard includes/ stdafx.pch will be the pre-compiled header/ stdafx.obj will contain the pre-compiled type information#include stdafx.h#ifdef _ATL_STATIC_REGISTRY#include #include #endif#include /Contain/StdAfx.h/ stdafx.h : include file for standard system include files,/ or project specific include files that are used frequently,/ but are changed infrequently#if !defined(AFX_STDAFX_H_380F7A01_4098_11D1_883A_444553540000_INCLUDED_)#define AFX_STDAFX_H_380F7A01_4098_11D1_883A_444553540000_INCLUDED_#if _MSC_VER = 1000#pragma once#endif / _MSC_VER = 1000#define STRICT#define _WIN32_WINNT 0x0400#define _ATL_APARTMENT_THREADED#include /You may derive a class from CComModule and use it if you want to override/something, but do not change the name of _Moduleextern CComModule _Module;#include /_AFX_INSERT_LOCATION/ Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif / !defined(AFX_STDAFX_H_380F7A01_4098_11D1_883A_444553540000_INCLUDED)/ Simple.idl : IDL source for Simple.dll/ This file will be processed by the MIDL tool to/ produce the type library (Simple.tlb) and marshalling code.import oaidl.idl;import ocidl.idl;uuid(380F79EA-4098-11D1-883A-444553540000),helpstring(IMath Interface),pointer_default(unique)interface IMath : IUnknownhelpstring(method Add) HRESULT Add(long lOp1, long lOp2, long* plResult);helpstring(method Subtract) HRESULT Subtract(long lOp1, long lOp2, long* plResult);helpstring(method Multiply) HRESULT Multiply(long lOp1, long lOp2, long* plResult);helpstring(method Divide) HRESULT Divide(long lOp1, long lOp2, long* plResult);uuid(380F79DD-4098-11D1-883A-444553540000),version(1.0),helpstring(Simple 1.0 Type Library)library SIMPLELibimportlib(stdole32.tlb);importlib(stdole2.tlb);uuid(380F79EB-4098-11D1-883A-444553540000),helpstring(SimpleMath Class)coclass SimpleMathdefault interface IMath;/ Client.cpp/#include #include #include const IID IID_IAdvancedMath = 0x380F79F9,0x4098,0x11D1,0x88,0x3A,0x44,0x45,0x53,0x54,0x00,0x00;const IID IID_IMath = 0x380F79EA,0x4098,0x11D1,0x88,0x3A,0x44,0x45,0x53,0x54,0x00,0x00;/ This gets us the Vtable layouts/ For IMath and IAdvancedMath#include Simple.h#include Contain.hint main( int argc, char *argv ) cout Initializing COM endl; if ( FAILED( Co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论