博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Visual studio 2008如何使用Skype API
阅读量:4121 次
发布时间:2019-05-25

本文共 4125 字,大约阅读时间需要 13 分钟。

 

两种使用方式:一、向Skype进程发送消息(可以参考msgapitest),二、注册Skype4COM.dll,使用该Active控件。本文主要讲述第二种方式,同时在文末介绍在实际使用过程中遇到的一些问题,最后不得不换成第一种方式。

 

首先创建SkypeAPIDemo项目,项目采用MFC Application模板,对话框类型,其它配置默认。

 

资源视图拉开对话框资源选择IDD_SKYPEAPIDEMO_DIALOG。在新打开的Dialog Tab页,对话框区域右键选择Insert ActiveX Control,在弹出的Insert ActiveX Control对话框中选择Skype Class

SkypeTapiDemo图一

 

自动在资源文件中插入如下代码

#define IDC_SKYPE1                      1000

 

……

 

CONTROL         "",IDC_SKYPE1,"{830690FC-BF2F-47A6-AC2D-330BCB402664}",WS_TABSTOP,0,0,60,25

 

……

 

/

//

// Dialog Info

//

IDD_SKYPEAPIDEMO_DIALOG DLGINIT

BEGIN

    IDC_SKYPE1, 0x376, 16, 0

0x0000, 0x0000, 0x0800, 0x0000, 0x094d, 0x0000, 0x043d, 0x0000,

    0

END

 

类视图选择项目SkypeAPIDemo,右键选择Add Class。在弹出的Add Class对话框中选择MFC Class From Activex Control Templates。在弹出的Add Class From ActiveX Control Wizard对话框中选择Skype Class<1.0>,在Interfaces 列表框中选择Iskype Interface添加到Generated classes列表框。项目就添加了CSkype类。

SkypeTapiDemo图二

 

 

右键Skype ActiveX控件选择Add Variable,在Variable Name中填写m_SkypeCtl,其它默认

 

SkypeTapiDemo图三

 

SkypeAPIDemoDlg.h文件中添加了如下代码

CSkype m_SkypeCtl;

 

类视图选择项目SkypeAPIDemo,右键选择Add Class。在弹出的Add Class对话框中选择MFC Class From TypeLib Templates。在弹出的Add Class From TypeLib Wizard对话框中选择Skype4COM 1.0  Type Library.<1.0>,在Interfaces 列表框中将需要的类添加到Generated classes列表框(eg. 选择ICall,项目会添加CCall头文件)

 

接下来添加Skype事件,在Dialog Tab页中选择整个对话框,打开Properties Window,在Control Events Categorized中拉开IDC_SKYPE1,选择需要的事件,比如监听Skype事件 AttachmentStatus 在后面的Text控件中填写OnAttachmentStatus,按下回车。

会添加如下代码

SkypeAPIDemo.h

DECLARE_EVENTSINK_MAP()

void OnAttachmentStatus(long Status);

 

SkypeAPIDemo.cpp

BEGIN_EVENTSINK_MAP(CSkypeAPIDemoDlg, CDialog)

ON_EVENT(CSkypeAPIDemoDlg, IDC_SKYPE1, 4, CSkypeAPIDemoDlg::OnAttachmentStatus, VTS_I4)

END_EVENTSINK_MAP()

 

void CSkypeAPIDemoDlg::OnAttachmentStatus(long Status)

{

// TODO: Add your message handler code here

}

可以在OnAttachmentStatus实现中添加如下代码打印Attachment状态

 

 

以下以如何获得Skype好友为例,说明如何使用Skype API。关于接口说明请参考Skype4COM.chm文件。

无论如何使用Skype,最上层的接口类就是ISKype(Skype is the default interface for the class)。在Skype接口说明中查找获取Skype好友的接口。

 

IUserCollection Friends [get] This command queries the users in a contact list.

 

从接口说明中可以得到以下信息:

接口名称:get_Friends(ISkype接口members分两类:一、Public member functions,大致是动作类的那种,包括呼叫、发消息之类的;二、Properties,属性类接口,分get和set两种,主要用于获得类属性或是设置类属性的,而get_Friends属于Properties->get分类)

返回:IUserCollection对象

 

再查看IUserCollection接口说明,我们发现以下对于获得好友列表有用的接口

LONG Count [get] This command queries the number of users in a UserCollection. 

 

IUser Item ([in] LONG Index) [get] This command queries an item in a UserCollection with a specified index value. 

注意Item下标是从1开始的,如果参数为0的话会报错。

 

再查看IUser接口说明,我们发现以下对于获得好友列表有用的接口 

BSTR Handle [get, set] This command queries/sets the Skypename of the user. 

 

接下来就可以实现获得Skype好友功能了。

首先通过MFC class From TypeLib添加IUserCollection与IUser接口(注意:如果在Skype.tlb位置产生com类编译错误,请注释新添加的接口类文件中的#import Skype4COM.dll语句)。

 

 

注意:

一、监控进程必须得与Skype进程处于同等权限之下(要么都是标准用户,要么都是管理员权限)。

二、如果在注意一前提下,你的监听程序无法监听skype(skype没有弹出是否同意attach提示)的话该怎么做?

It is starting to sound like your application/program is not approved to be used by the current Skype user. 

Anytime your program changes, it will be required to be re-authorized. 

You can check the status of your program authorization using the Skype client: 

Tools -> Options -> Advanced -> Manage Other Programs Access To Skype 

Is a record there for your program? 

 <>

 

在实际使用过程中遇到两个问题:一、对话框页选择Skype ActiveX控件,转到属性页时,整个Visual Studio 2008失去响应,无法恢复。在Visual studio 2010上试了试还是同样问题。二、无法对多个Skype实例同时监控。

 

转载地址:http://rzppi.baihongyu.com/

你可能感兴趣的文章
北京十大情人分手圣地
查看>>
Android自动关机代码
查看>>
Android中启动其他Activity并返回结果
查看>>
2009年33所高校被暂停或被限制招生
查看>>
GlassFish 部署及应用入门
查看>>
iWatch报错: Authorization request cancled
查看>>
iWatch报错: Authorizationsession time out
查看>>
如何运行从网上下载的iWatch项目详细步骤.
查看>>
X-code7 beta error: warning: Is a directory
查看>>
Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.
查看>>
X-code beta 开发iWatch项目,运行没有错误,但是某些操作一点就崩,而且找不错误的原因场景一
查看>>
Xcode 报错: Extra argument in call
查看>>
iTunes Connect 上传APP报错: Communication error. please use diagnostic mode to check connectivity.
查看>>
#import <Cocoa/Cocoa.h> 报错 Lexical or Preprocessor Issue 'Cocoa/Cocoa.h' file not found
查看>>
`MQTTClient (~> 0.2.6)` required by `Podfile`
查看>>
X-Code 报错 ld: library not found for -lAFNetworking
查看>>
Bitcode
查看>>
If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
查看>>
3.5 YOLO9000: Better,Faster,Stronger(YOLO9000:更好,更快,更强)
查看>>
iOS菜鸟学习--如何避免两个按钮同时响应
查看>>