《VC++进行COM编程.pdf》由会员分享,可在线阅读,更多相关《VC++进行COM编程.pdf(21页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、?VCCOM?2007-8-30?COM?COM?100%?0%?EXE?DLL?Windows?DLL?Windows?DLL?(1)?DLL?DLL?(2)?C?C?DLL?VC?DLL?BC?extern C;?C?C?(3)?(4)DLL?EXE?DLL?EXE?DLL?DLL?DLL?DLL?COM?COM?DLL?COM?DLL?ActiveX?.ocx?DLL?DLL?COM?COM?DLL?DLL?COM?EXE?VC?COM?COM?COM?COM?COM?COM?COM?COM?COM?COM?VC?(?C?COM?)(1)COM?C+?C+?COM?class IObje
2、ctpublic:virtual Function1(.)=0;virtual Function2(.)=0;.;class MyObject:public IObjectpublic:virtual Function1(.).virtual Function2(.).;?IObject?MyObject?COM?COM?COM?C+?COM?VTable?(2)COM?IUnknown?IClassFactory?IDispatchCOM?IUnknown?IUnknown?QueryInterface?AddRef?Release?QueryInterface?AddRef?Release
3、?COM?COM?DLL?DLL?COM?COM?COM?COM?COM?COM?VC?AddRef?AddRef?Release?Release?QueryInterface?MSDN?AddRef?Release?IUnknown?IClassFactory?COM?COM?new?!?COM?new?128?new?new?IClassFactory?CreateInstance?API?VC?COM?VB?IDispatch?C+?VB?VJ?VBScript?JavaScript?IDispatch?:-)?COM?C+?VC?C+?VB?VB?VTable?VJ?VBScript?
4、JavaScript?COM?IDispatch?:-)?IDispatch?IDispatch?IDispatch?Invoke?Invoke?MS?Invoke?:-)(3)dispinterface?Dual?Custom?ATL?-:)?IDispatch?IDispatch?VBScript?JavaScript?COM?Invoke?VTable?IDispatch?VC?Invoke?VC?VC?IDispatch?(?dual?IDispatch?IUnknown?IDispatch?IDispatch?IUnknown?IDispatch?IUnknown?IDispatch
5、:Invoke?C+?dispinterface?IDispatch?(?)?COM?Custom?IUnknown?(4)COM?COM?DLL?COM?DLL?COM?.?WIN32?4GB?DLL?Windows?DCOM?RPC?Windows?DLL?COM?EXE?DLL?dllhost.exe?COM?DLL?MTS?DLL?MTS?DLL?COM?COM?COM+?(5)COM?IDL?COM?COM?C+?COM?C+?IDL?IDL?IDL?IDL?VC?VB?DLL?(6)COM?COM?COM?IUnknown*pUnk=NULL;IObject*pObject=NUL
6、L;CoInitialize(NULL);CoCreateInstance(CLSID_Object,CLSCTX_INPROC_SERVER,NULL,IID_IUnknown,(void*)&pUnk);pUnk-QueryInterface(IID_IOjbect,(void*)&pObject);pUnk-Release();pObject-Func();pObject-Release();CoUninitialize();CoCreateInstance?:CoCreateInstance(.).IClassFactory*pClassFactory=NULL;CoGetClassO
7、bject(CLSID_Object,CLSCTX_INPROC_SERVER,NULL,IID_IClassFactory,(void*)&pClassFactory);pClassFactory-CreateInstance(NULL,IID_IUnknown,(void*)&pUnk);pClassFactory-Release();.?IUnknown?CoGetClassObject?CoGetClassObject(.)/?CLSID_Object?DLL?/?DLL?/?GetProcAddress(.)?DLL?DllGetClassObject?/?DllGetClassOb
8、jectDllGetClassObject?.?DllGetClassObject?DllGetClassObject(.).CFactory*pFactory=new CFactory;/?pFactory-QueryInterface(IID_IClassFactory,(void*)&pClassFactory);/?IClassFactory?pFactory-Release();.CoGetClassObject?CoCreateInstance?CreateInstance?CFactory:CreateInstance(.).CObject*pObject=new CObject;/?pObject-QueryInterface(IID_IUnknown,(void*)&pUnk);pObject-Release();.?COM+?COPY?CoCreateInstance?(7)?COM DLL?DllGetClassObject:?DllRegisterServer:?DllUnregisterServer:?DllCanUnloadNow:?DLLDLL?DllMain,?COM?VC?(8)?COM?GUID?COM?GUID?GUID?128?GUID?COM?DLL?CLSID?DLL?