VS2010调用Com组件
Com组件开发过程中用的不多,资料也不多,故记录开发Com组件中的部分问题。
在这一篇文章里,讲解了如何使用VS2010创建Com组件。现在基于该文章创建的Com组件接口,创建VC++项目来调用该接口。
使用流程
新建win32控制台项目。
主文件代码如下:
#include "stdafx.h"
#include "../testCom/testCom_i.h"
#include "../testCom/testCom_i.c" int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
IMyClass *pCom = NULL;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_MyClass,NULL,1,IID_IMyClass,(LPVOID*)&pCom);
if (SUCCEEDED(hr))
{
LONG res;
pCom->Add(2,3,&res);
printf("2+3=%d\n",res);
}
CoUninitialize();
return 0;
}
代码说明:
#include "../testCom/testCom_i.h"
#include "../testCom/testCom_i.c"
是将com组件定义接口的文件包含到本工程中,这样操作后才可以在后面直接调用Com接口函数。
调用Com组件前必须调用CoInitialize(NULL);
调用完成后需要释放CoUninitialize();
CoCreateInstance用于创建一个Com实例,函数说明如下:
HRESULT CoCreateInstance(
__in REFCLSID rclsid,
__in LPUNKNOWN pUnkOuter,
__in DWORD dwClsContext,
__in REFIID riid,
__out LPVOID *ppv
); rclsid [in]
The CLSID associated with the data and code that will be used to create the object. pUnkOuter [in]
If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown). dwClsContext [in]
Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX. riid [in]
A reference to the identifier of the interface to be used to communicate with the object. ppv [out]
Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, * ppv contains the requested interface pointer. Upon failure, * ppv contains NULL.
相关下载
VS2010调用Com组件的更多相关文章
- Titanium中调用ios组件时语言不是本地化的解决方法
用Titanium开发的ios应用中,当调用系统组件时,尽管手机已经设置了系统语言为中文,但那些组件的界面却仍为英文.比如调用iphone中的相册组件,其界面为: 那么怎么让它跟系统语言保持一致呢? ...
- VC中调用COM组件的方法(转载)
原文参考:http://hi.baidu.com/mingyueye/item/53ebecd44da76917d80e4449 总结一下在VC中调用COM组件的方法 准备及条件: COM服务器为进程 ...
- .NET通过调用Office组件导出Word文档
.NET通过调用Office组件导出Word文档 最近做项目需要实现一个客户端下载word表格的功能,该功能是用户点击"下载表格",服务端将该用户的数据查询出来并生成数据到Word ...
- 服务器端调用Word组件读取Word权限、未将对象引用到对象实例终极解决方案
最近因为业务需要,需要在服务器上调用Word组件,结果遇到各种问题,比如检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败 ...
- vc中调用Com组件的方法详解
vc中调用Com组件的方法详解 转载自:网络,来源未知,如有知晓者请告知我.需求:1.创建myCom.dll,该COM只有一个组件,两个接口: IGetRes--方法Hello(), IGet ...
- Asp.Net调用Office组件操作时的DCOM配置 (转)
Asp.Net调用Office组件操作时的DCOM配置 http://blog.csdn.net/gz775/article/details/6447758 在项目中将数据导出为Excel格式时出现“ ...
- vue组件之间的通信以及如何在父组件中调用子组件的方法和属性
在Vue中组件实例之间的作用域是孤立的,以为不能直接在子组件上引用父组件的数据,同时父组件也不能直接使用子组件的数据 一.父组件利用props往子组件传输数据 父组件: <div> < ...
- php实现ppt转图片,php调用com组件问题
PHP 调用com组件将ppt转为图片. 需要在php.ini中开启 extension=php_com_dotnet.dllcom.allow_dcom = true 测试代码如下: < ...
- 【微服务】之五:轻松搞定SpringCloud微服务-调用远程组件Feign
上一篇文章讲到了负载均衡在Spring Cloud体系中的体现,其实Spring Cloud是提供了多种客户端调用的组件,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使 ...
随机推荐
- DateTime.Parse
上月第一天:DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01")) 上周星期天:DateTime.Par ...
- android之对话、单复框的使用
对话框 通过builder来构建一个单选框 package xidian.dy.com.chujia; import android.content.DialogInterface; import a ...
- 配置ipvsadm服务
LVS的三种包转发方式 LVS提供了三种包转发方式:NAT(网络地址映射).IP Tunneling(IP隧道).Direct Routing(直接路由) 不同的转发模式决定了不同的 ...
- Sublime-jQueryDocs
Package Control Messages======================== jQueryDocs---------- This package shows a selected ...
- Address already in use: JVM_Bind<null>:80
Address already in use: JVM_Bind<null>:80 咱还是闲话少说,直接切入正题. 起因: 一直用Tomcat,但是前几天突然报错: java.net.Bi ...
- Tomcat_修改代码后tomcat是否需要重启
在修改一个类时,如果没有修改到已经贮存于虚拟机的实例,在你重新编译后,发布至classes,都不需要重启. 怎样才叫已经贮存于虚拟机的实例呢: 1.成员变量 2.类名称 3.方法名 ………… 如果 ...
- 【HDU 5363】Key Set
题 Description soda has a set $S$ with $n$ integers $\{1, 2, \dots, n\}$. A set is called key set if ...
- python逐行读写
代码: fileReadObj = open("input.txt") fileWriteObj = open("output.txt", 'w') fileL ...
- Android模拟器端口被占用问题的解决办法
一.问题描述 今天在Eclipse中运行Android项目时遇到"The connection to adb is down, and a severe error has occured& ...
- [Angularjs]ng-class,ng-class-even,ng-class-odd
写在前面 最近在通过angularjs将数据绑定到前端,其中也涉及到很多新的东西,一些效果还是很有必要实现的.在使用中发现ng-class,ng-class-even.ng-class-odd的使用, ...