IDispatch接口 - Part II -CComDispatchDriver智能指针
来源:互联网 发布:照片审核工具 mac 编辑:程序博客网 时间:2024/06/06 08:40
前面一篇文章讲述了怎么样通过GetIDsOfNames和Invoke来调用一个支持Idispach的COM组件。
看起来好像很麻烦,实际上,COM已经提供了一个专门的智能指针来解决这个问题。
CComDispatchDriver
看一下它的定义,实际上它就是一个特殊的CComQIPtr。
- typedef CComQIPtr<IDispatch, &__uuidof(IDispatch)> CComDispatchDriver;
使用其实也很简单,直接看个例子好了。
使用例子
- // ConsoleApplication4.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <thread>
- #include <atlbase.h>
- #include <atlcom.h>
- #include <algorithm>
- #include <vector>
- #include <memory>
- #include "../MyCom/MyCom_i.h"
- #include "../MyCom/MyCom_i.c"
- int _tmain(int argc, _TCHAR* argv[])
- {
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- CComDispatchDriver dsp;
- dsp.CoCreateInstance(CLSID_MyCar);
- CComVariant rt;
- dsp.GetPropertyByName(L"Gas", &rt);
- LONG total = rt.lVal;
- CComVariant p1;
- p1.vt = VT_I4;
- p1.lVal = 12;
- CComVariant p2;
- p2.vt = VT_I4 | VT_BYREF;
- LONG Gas = 0;
- p2.byref = &Gas;
- dsp.Invoke2(L"AddGas", &p1, &p2, NULL);
- CComVariant totalGas;
- dsp.GetPropertyByName(L"Gas", &totalGas);
- total = totalGas.lVal;
- dsp.Release();
- CoUninitialize();
- return 0;
- }
0 0
- IDispatch接口 - Part II -CComDispatchDriver智能指针
- IDispatch接口 - CComDispatchDriver智能指针
- IDispatch接口 - CComDispatchDriver智能指针
- IDispatch接口 - Part I - GetIDsOfNames和Invoke
- IDispatch接口 - Part III - Dual和Custom
- IDispatch接口 - Part IV - 跨语言调用
- IDispatch 接口
- IDispatch接口
- IDispatch接口
- IDispatch接口
- IDispatch接口
- IDispatch接口是什么?
- VC6的IDispatch接口
- IDispatch接口的作用
- IDispatch接口的作用
- IDispatch接口的作用
- C++中IDispatch接口
- ATL IDispatch调度接口
- COM线程模型 - Part VI - COM服务端(STA组件)创建线程
- 社会化登陆-第三方SDK
- CSS学习笔记----position简单举例
- IDispatch接口 - Part I - GetIDsOfNames和Invoke
- Status bar colour for UIImagePickerController
- IDispatch接口 - Part II -CComDispatchDriver智能指针
- 一个小型的网页抓取系统的架构设计
- 【2119】数据结构实验之链表四:有序链表的归并
- IDispatch接口 - Part III - Dual和Custom
- C# String.Format格式说明
- Construct Binary Tree from Inorder and Postorder Traversal
- linux 的代码格式化工具 indent
- IDispatch接口 - Part IV - 跨语言调用
- 【Leetcode】3Sum Closest (Sum)