ATL包容实例

2020-03-02 14:39:56 来源:范文大全收藏下载本文

///Contain/Contain.idl // Contain.idl : IDL source for Contain.dll // // This file will be proceed 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 : IUnknown {

[helpstring(\"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 : IUnknown {

[helpstring(\"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 CONTAINLib { importlib(\"stdole32.tlb\"); importlib(\"stdole2.tlb\"); [

uuid(380F7A0B-4098-11D1-883A-444553540000),

helpstring(\"AdvancedMath Cla\") ] cocla AdvancedMath {

[default] interface IAdvancedMath;

interface IMath; }; };

///Contain/Containps.def LIBRARY

\"ContainPS\" DESCRIPTION \'Proxy/Stub DLL\' EXPORTS DllGetClaObject

@1 PRIVATE DllCanUnloadNow

@2 PRIVATE GetProxyDllInfo

@3 PRIVATE DllRegisterServer @4 PRIVATE DllUnregisterServer @5 PRIVATE

///Contain/Containps.mk Containps.dll: dlldata.obj Contain_p.obj Contain_i.obj link /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 $

///Contain/AdvancedMath.cpp // AdvancedMath.cpp : Implementation of CAdvancedMath #include \"stdafx.h\" #include \"Contain.h\" #include \"AdvancedMath.h\" ///////////////////////////////////////////////////////////////////////////// // CAdvancedMath // IAdvancedMath interface long calcFactorial( short n ) {

if ( n > 1 )

return n * calcFactorial( n1 ) + calcFibonacci( nWe now must explicitly implement these methods public: 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); // IAdvancedMath public: STDMETHOD(Fibonacci)( short sOp, long* plResult ); STDMETHOD(Factorial)( short sOp, long* plResult ); private:

IMath* m_pSimpleMath; }; #endif //__ADVANCEDMATH_H_

///Contain/AdvancedMath.rgs HKCR { Chapter5.Containment.1 = s \'AdvancedMath Cla\' {

CLSID = s \'{380F7A0B-4098-11D1-883A-444553540000}\' } Chapter5.Containment = s \'AdvancedMath Cla\' {

CurVer = s \'Chapter5.Containment.1\'

CLSID = s \'{380F7A0B-4098-11D1-883A-444553540000}\' } NoRemove CLSID {

ForceRemove {380F7A0B-4098-11D1-883A-444553540000} = Cla\'

{

ProgID = s \'Chapter5.Containment.1\'

VersionIndependentProgID = s \'Chapter5.Containment\'

InprocServer32 = 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.h\" CComModule _Module; BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_AdvancedMath, CAdvancedMath)

s \'AdvancedMath END_OBJECT_MAP() ///////////////////////////////////////////////////////////////////////////// // DLL Entry Point extern \"C\" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, /*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 OLE STDAPI DllCanUnloadNow(void) { return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; } ///////////////////////////////////////////////////////////////////////////// // Returns a cla factory to create an object of the requested type STDAPI DllGetClaObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { return _Module.GetClaObject(rclsid, riid, ppv); } ///////////////////////////////////////////////////////////////////////////// // DllRegisterServerRemoves entries from the system registry STDAPI DllUnregisterServer(void) { _Module.UnregisterServer(); return S_OK; }

///Contain/Contain.def

LPVOID ; Contain.def : Declares the module parameters.LIBRARY

\"Contain.DLL\" EXPORTS DllCanUnloadNow

@1 PRIVATE DllGetClaObject

@2 PRIVATE DllRegisterServer

@3 PRIVATE DllUnregisterServer @4 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 _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN

\"resource.h\\0\" END 2 TEXTINCLUDE DISCARDABLE BEGIN

\"#include \"\"winres.h\"\"\\r\\n\"

\"\\0\" END 3 TEXTINCLUDE DISCARDABLE BEGIN

\"1 TYPELIB \"\"Contain.tlb\"\"\\r\\n\"

\"\\0\" END #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 0x0L BEGIN

BLOCK \"StringFileInfo\"

BEGIN

BLOCK \"040904B0\"

BEGIN

VALUE \"CompanyName\", \"\\0\"

VALUE \"FileDescription\", \"Contain Module\\0\"

VALUE \"FileVersion\", \"1, 0, 0, 1\\0\"

VALUE \"InternalName\", \"CONTAIN\\0\"

VALUE \"LegalCopyright\", \"Copyright 1997\\0\"

VALUE \"OriginalFilename\", \"CONTAIN.DLL\\0\"

VALUE \"ProductName\", \"Contain Module\\0\"

VALUE \"ProductVersion\", \"1, 0, 0, 1\\0\"

VALUE \"OLESelfRegister\", \"\\0\"

END

END

BLOCK \"VarFileInfo\"

BEGIN

VALUE \"Translation\", 0x409, 1200

END END #endif

// !_MAC ///////////////////////////////////////////////////////////////////////////// // // REGISTRY // IDR_ADVANCEDMATH

REGISTRY DISCARDABLE

\"AdvancedMath.rgs\" ///////////////////////////////////////////////////////////////////////////// // // String Table // STRINGTABLE DISCARDABLE BEGIN

IDS_PROJNAME

\"Contain\" END #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 cla from CComModule and use it if you want to override //something, but do not change the name of _Module extern 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 proceed 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 : IUnknown {

[helpstring(\"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 SIMPLELib { importlib(\"stdole32.tlb\"); importlib(\"stdole2.tlb\");

[

uuid(380F79EB-4098-11D1-883A-444553540000),

helpstring(\"SimpleMath Cla\") ] cocla SimpleMath {

[default] 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.h\"

int main( int argc, char *argv[] ) {

cout

if ( FAILED( CoInitialize( NULL )))

{

cout

return -1;

}

CLSID clsid;

HRESULT hr;

hr = CLSIDFromProgID( L\"Chapter5.Containment.1\", &clsid );

cout

if ( FAILED( hr ))

{

cout.setf( ios::hex, ios::basefield );

cout

return -1;

}

// Use CoCreateInstance

IMath* pMath;

hr = CoCreateInstance( clsid,

NULL,

CLSCTX_INPROC,

IID_IMath,

(void**) &pMath );

if ( FAILED( hr ))

{

cout.setf( ios::hex, ios::basefield );

cout

return -1;

}

cout

long result;

pMath->Multiply( 100, 8, &result );

cout

pMath->Subtract( 1000, 333, &result );

cout

// Try IAdvancedMath, QI through IMath

IAdvancedMath* pAdvMath = NULL;

hr = pMath->QueryInterface( IID_IAdvancedMath, (LPVOID*)&pAdvMath );

if ( FAILED( hr ))

{

cout

pMath->Release();

CoUninitialize();

return -1;

}

pAdvMath->Factorial( 10, &result );

cout

pAdvMath->Fibonacci( 10, &result );

cout

cout

pMath->Release();

cout

pAdvMath->Release();

cout

CoUninitialize();

return 0; }

包容

包容

包容 团结

懂得包容

包容素材

学会包容

包容议论文

包容(议论文)

包容(记叙文)

包容 作文

《ATL包容实例.doc》
ATL包容实例
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档
下载全文