《COM的CALLBACK(回调)示例》由会员分享,可在线阅读,更多相关《COM的CALLBACK(回调)示例(16页珍藏版)》请在金锄头文库上搜索。
1、/CallBack/Proxy/CallBack/Proxy/CallBackServer.idl/ CallBackServer.idl : IDL source for CallBackServer.dll/ This file will be processed by the MIDL tool to/ produce the type library (CallBackServer.tlb) and marshalling code.import oaidl.idl;import ocidl.idl;object,uuid(48CD3740-50A3-11d1-B5EC-0004ACF
2、F171C),helpstring(ICallBack Interface),interface ICallBack : IUnknownhelpstring(method ComputationComplete) HRESULT ComputationComplete( long lResult );uuid(DB5CCD8E-5489-11D1-883A-444553540000),helpstring(IMath Interface),pointer_default(unique)interface IMath : IUnknownhelpstring(method Add) HRESU
3、LT Add(in long lOp1,in long lOp2);helpstring(method Subtract) HRESULT Subtract(in long lOp1,in long lOp2);helpstring(method Multiply) HRESULT Multiply(in long lOp1,in long lOp2);helpstring(method Divide) HRESULT Divide(in long lOp1,in long lOp2);helpstring(method Advise) HRESULT Advise(in ICallBack*
4、 pCallBack);helpstring(method UnAdvise) HRESULT UnAdvise();uuid(DB5CCD81-5489-11D1-883A-444553540000),version(1.0),helpstring(CallBackServer 1.0 Type Library)library CALLBACKSERVERLibimportlib(stdole32.tlb);importlib(stdole2.tlb);uuid(DB5CCD8F-5489-11D1-883A-444553540000),helpstring(Math Class)cocla
5、ss Mathdefault interface IMath;/* source, default */ interface ICallBack;/CallBack/Proxy/CallBackServerps.defLIBRARY CallBackServerPSDESCRIPTION Proxy/Stub DLLEXPORTSDllGetClassObject PRIVATEDllCanUnloadNow PRIVATEGetProxyDllInfo PRIVATEDllRegisterServer PRIVATEDllUnregisterServer PRIVATE/CallBack/S
6、erver/CallBack/Server/CallBackServer.cpp/ CallBackServer.cpp : Implementation of DLL Exports./ Note: Proxy/Stub Information/ To build a separate proxy/stub DLL, / run nmake -f CallBackServerps.mk in the project directory.#include stdafx.h#include resource.h#include initguid.h#include CallBackServer.
7、h#include CallBackServer_i.c#include Math.hCComModule _Module;BEGIN_OBJECT_MAP(ObjectMap)OBJECT_ENTRY(CLSID_Math, CMath)END_OBJECT_MAP()/ DLL Entry Pointextern CBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)if (dwReason = DLL_PROCESS_ATTACH)_Module.Init(ObjectMap, hI
8、nstance);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
9、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.Regi
10、sterServer(TRUE);/ DllUnregisterServer - Removes entries from the system registrySTDAPI DllUnregisterServer(void)_Module.UnregisterServer();return S_OK;/CallBack/Server/CallBackServer.def; CallBackServer.def : Declares the module parameters.LIBRARY CallBackServer.DLLEXPORTSDllCanUnloadNow PRIVATEDll
11、GetClassObject PRIVATEDllRegisterServer PRIVATEDllUnregisterServer PRIVATE/CallBack/Server/CallBackServer.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_READON
12、LY_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 BEGINresource.h0END2 TEXTINCLUDE DISCARDABLE BEGIN#inclu
13、de winres.hrn0END3 TEXTINCLUDE DISCARDABLE BEGIN1 TYPELIB CallBackServer.tlbrn0END#endif / APSTUDIO_INVOKED#ifndef _MAC/ Version/VS_VERSION_INFO VERSIONINFOFILEVERSION 1,0,0,1PRODUCTVERSION 1,0,0,1FILEFLAGSMASK 0x3fL#ifdef _DEBUGFILEFLAGS 0x1L#elseFILEFLAGS 0x0L#endifFILEOS 0x4LFILETYPE 0x2LFILESUBTYPE 0x0LBEGINBLOCK StringFileInfoBEGINBLOCK 040904B0BEGINV