在C++下实现的程序拨号代码

简介: 下面是一段拨号代码(摘自Nokia的例子),代码虽然不多,但很多地方都值得学习,例如:对R类的使用,清理;server/client机制;参数传递机制;编码风格;注释风格等等自己体会吧。
下面是一段拨号代码(摘自Nokia的例子),代码虽然不多,但很多地方都值得学习,例如:对R类的使用,清理;server/client机制;参数传递机制;编码风格;注释风格等等自己体会吧。
 在阅读代码之前请熟悉Symbian OS C++中的ETel结构,以及它的核心类RTelServer,RPhone,RLine,RCall.
下面是代码内容:
void DialNumberL(const TDesC& aPhoneNumber)
{
//Create a connection to the tel server
RTelServer server;
CleanupClosePushL(server);
User::LeaveIfError(server.Connect());
//Load in the phone device driver
User::LeaveIfError(server.LoadPhoneModule(KTsyName));


//Find the number of phones available from the tel server
TInt numberPhones;
User::LeaveIfError(server.EnumeratePhones(numberPhones));
//Check there are available phones
if (numberPhones < 1)
{
User::Leave(KErrNotFound);
}


//Get info about the first available phone
RTelServer::TPhoneInfo info;
User::LeaveIfError(server.GetPhoneInfo(0, info));
//Use this info to open a connection to the phone, the phone is identified by its name
RPhone phone;
CleanupClosePushL(phone);
User::LeaveIfError(phone.Open(server, info.iName));


//Get info about the first line from the phone
RPhone::TLineInfo lineInfo;
User::LeaveIfError(phone.GetLineInfo(0, lineInfo));
//Use this to open a line
RLine line;
CleanupClosePushL(line);
User::LeaveIfError(line.Open(phone, lineInfo.iName));


//Open a new call on this line
TBuf <100> newCallName;
RCall call;
CleanupClosePushL(call);
User::LeaveIfError(call.OpenNewCall(line, newCallName));
//newCallName will now contain the name of the call
User::LeaveIfError(call.Dial(aPhoneNumber));
//Close the phone, line and call connections and remove them from the cleanup stack


//NOTE: This does not hang up the call
CleanupStack::PopAndDestroy(3);//phone, line, call
//Unload the phone device driver
User::LeaveIfError(server.UnloadPhoneModule(KTsyName));


//Close the connection to the tel server and remove it from the cleanup stack
CleanupStack::PopAndDestroy(&server);
}   //end

目录
相关文章
|
15天前
|
C语言 C++ 开发者
深入探索C++:特性、代码实践及流程图解析
深入探索C++:特性、代码实践及流程图解析
|
3天前
|
存储 安全 算法
【Linux | C++ 】基于环形队列的多生产者多消费者模型(Linux系统下C++ 代码模拟实现)
【Linux | C++ 】基于环形队列的多生产者多消费者模型(Linux系统下C++ 代码模拟实现)
17 0
|
3天前
|
算法 Linux 数据安全/隐私保护
【Linux | C++ 】生产者消费者模型(Linux系统下C++ 代码模拟实现)
【Linux | C++ 】生产者消费者模型(Linux系统下C++ 代码模拟实现)
9 0
|
9天前
|
C++
【C++】一文深入浅出带你参透库中的几种 [ 智能指针 ]及其背后实现原理(代码&图示)
【C++】一文深入浅出带你参透库中的几种 [ 智能指针 ]及其背后实现原理(代码&图示)
|
9天前
|
C++ 数据格式
【C++】C++中的【文件IO流】使用指南 [手把手代码演示] & [小白秒懂]
【C++】C++中的【文件IO流】使用指南 [手把手代码演示] & [小白秒懂]
【C++】C++中的【文件IO流】使用指南 [手把手代码演示] & [小白秒懂]
|
9天前
|
编译器 C++
【C++】【C++的常变量取地址问题(对比C的不同)】const修饰的常变量&volatile修饰用法详解(代码演示)
【C++】【C++的常变量取地址问题(对比C的不同)】const修饰的常变量&volatile修饰用法详解(代码演示)
|
10天前
|
C++
【期末不挂科-C++考前速过系列P6】大二C++实验作业-模板(4道代码题)【解析,注释】
【期末不挂科-C++考前速过系列P6】大二C++实验作业-模板(4道代码题)【解析,注释】
【期末不挂科-C++考前速过系列P6】大二C++实验作业-模板(4道代码题)【解析,注释】
|
10天前
|
Serverless C++ 容器
【期末不挂科-C++考前速过系列P5】大二C++实验作业-多态性(3道代码题)【解析,注释】
【期末不挂科-C++考前速过系列P5】大二C++实验作业-多态性(3道代码题)【解析,注释】
|
10天前
|
C++ 芯片
【期末不挂科-C++考前速过系列P4】大二C++实验作业-继承和派生(3道代码题)【解析,注释】
【期末不挂科-C++考前速过系列P4】大二C++实验作业-继承和派生(3道代码题)【解析,注释】
|
10天前
|
编译器 C++
【期末不挂科-C++考前速过系列P3】大二C++第3次过程考核(20道选择题&12道判断题&2道代码题)【解析,注释】
【期末不挂科-C++考前速过系列P3】大二C++第3次过程考核(20道选择题&12道判断题&2道代码题)【解析,注释】