×
Namespaces

Variants
Actions
Revision as of 07:37, 30 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ECom: 接口的完成

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 3rd Edition FP1
S60 3rd Edition FP1

文章
翻译:
hoolee
最后由 hamishwillee 在 30 May 2013 编辑
  • 详细描述

下列代码示例演示了如何完成基类的ECom组件


  • 前言和重要问题

MMP文件中的UID2(0x10009D8D)应该为0x10009D8D,表示是ECom插件,UID3(0xE01F5465)为ECom DLL的UID接口的UID可以从保护或未保护的区域选择,这个依赖于你定下的certification path。这里我们使用未保护的UID,这样程序可以自签名即可。

如果插件DLL的UID改变了(相应rss文件中的名称也要改变),那么ECom框架就无法找到插件新的UID,可能需要删除开发环境下的ECom.ROM.Z.dat and Ecom.idx文件,如:\Symbian\9.1\S60_3rd_MR\Epoc32\winscw\c\private\10009D8F\目录下。当模拟器重启时,该文件会被重新生成。

ECom资源名必须要识别为ECom component/DLL名目标类型(TARGETTYPE)要为PLUGIN编译后的EComExample.rsc资源文件必须要拷贝到WINSCW环境下的\Epoc32\release\winscw\udeb\z\resource\plugins目录,具体查看MMP文件中的TARGETPATH属性。

  • MMP文件
TARGET EComExample.dll
TARGETTYPE PLUGIN
 
...
 
UID 0x10009D8D 0xE01F5465
 
...
 
SOURCE Proxy.cpp
SOURCE CMyHelloEcom.cpp // Your ECom impl
 
...
 
// Import base class header and inline file
USERINCLUDE ..\interface
SYSTEMINCLUDE \epoc32\include
SYSTEMINCLUDE \epoc32\include\ecom
 
// ECom resource name must be identical to ECom component/DLL name.
START RESOURCE E01F5465.rss
TARGET EComExample.rsc
TARGETPATH \resource\plugins
END
  • 头文件

这个头文件派生自ECom基类

// Include base class header
#include <CHelloEcomIF.h>
 
class CMyHelloEcom : public CHelloEcomIF
{
public:
static CMyHelloEcom* NewL();
virtual ~CImplementationClassOne();
 
// Implementation of CHelloEcomIF
void SayHello(TDes& aString);
 
private:
CMyHelloEcom();
void ConstructL();
};
 
private:
HBufC* iDescriptor;


  • 源文件

这里必须要完成定义在基类中的虚函数SayHello(TDes& aString)

#include "CMyHelloEcom.h"
 
CMyHelloEcom* CMyHelloEcom::NewL()
{
CMyHelloEcom* self=new(ELeave) CMyHelloEcom();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
 
CMyHelloEcom::~CMyHelloEcom()
{
delete iDescriptor;
}
 
CMyHelloEcom::CMyHelloEcom()
{
}
 
void CMyHelloEcom::ConstructL()
{
}
 
// Implementation of CHelloEcomIF
void CMyHelloEcom::SayHello(TDes& aString)
{
aString.Copy(*iDescriptor);
}
  • 插件资源文件

这个资源文件描述了插件DLL的内容,它定义了IMPLEMENTATION_INFO用以描述不同的完成。ECOM框架则使用

IMPLEMENTATION_INFO::implementation_uid查找被询问的客户端接口完成。

#include "RegistryInfo.rh"
 
RESOURCE REGISTRY_INFO theInfo
{
// UID for the DLL
dll_uid = 0xE01F5465;
// Declare an array of interface info
interfaces =
{
INTERFACE_INFO
{
// UID of the interface that is implemented
interface_uid = 0xE0009DC1;
implementations =
{
// Info for implementation of CHelloEcomIF
IMPLEMENTATION_INFO
{
implementation_uid = 0xE0009DC7;
version_no = 1;
display_name = "ecomexample";
opaque_data = "";
default_data = "ecomexample";
}
};
}
};
}
  • Proxy

定义的完成位于DLL中。ECom框架可以使用TImplementationProxy项将实际完成的方法(NewL)映射为ID,TImplementationProxy中每个完成的ID在资源文件中必须如下描述:

#include <e32std.h>
#include <ImplementationProxy.h>
#include "CMyHelloEcom.h"
 
// Maps the interface UIDs to implementation factory functions
const TImplementationProxy ImplementationTable[] =
{
IMPLEMENTATION_PROXY_ENTRY(0xE0009DC7, CMyHelloEcom::NewL)
};
 
// Exported proxy for instantiation method resolution
EXPORT_C const TImplementationProxy* ImplementationGroupProxy
(TInt& aTableCount)
{
aTableCount =
sizeof(ImplementationTable) / sizeof(TImplementationProxy);
return ImplementationTable;
}
  • 后记

如上方法ECom接口已经完成了。ECom组件需要一个对应的资源文件。已完成的factory functions定义在"proxy"中。

This page was last modified on 30 May 2013, at 07:37.
115 page views in the last 30 days.
×