初始化IDL文件中的结构 [英] initializing structures in IDL file

查看:182
本文介绍了初始化IDL文件中的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IDL文件中声明的结构不能具有构造函数.因此,程序员如何在运行时确保相应的用户对象已正确初始化并且其任何成员都不具有垃圾值?

The structures declared in IDL file cannot have constructors. So, how does programmer ensure that corresponding user object is properly initialized and does not have junk value for any of its members, at runtime?

推荐答案

您的问题根本就没有适用于IDL.它适用于IDL定义的功能的实现.

IDL是接口定义语言".编译时,您只会得到接口(嗯,仅多一点).当您以某些语言生成源代码时,您将获得与接口等效的接口或声明.例如,对于C ++,会生成类,但它们会产生与COM接口完全相同的二进制布局.更确切地说,接口被表示为没有数据的类,而所有成员都是纯虚函数.

当您基于IDL编写代码时,您有责任为这些接口编写实现.例如,在使用C ++的情况下,您将创建一个类并将一个或多个接口类设为基类.您可以通过覆盖每个纯虚函数来实现接口.其他所有内容都取决于那些覆盖的接口功能的实现.如果您有需要初始化的数据,请多加注意.

—SA
Your question is simply not applicable to IDL. It is applicable to implementation of the functions defined by IDL.

IDL is "Interface Definition Language". When you compile it, you got interfaces only (well, just a bit more). When you generate source code in some languages you will get interfaces or declarations equivalent to interfaces. For C++, for example, the classes are generated, but they produce exact same binary layout required by COM interfaces. More exactly, interfaces are expressed as classes with no data with all members being pure virtual function.

When you write the code based on your IDL, it''s your responsibility to write implementation for these interfaces. For example, in case of C++ you create a class and make one or more interface classes your base classes. You implement the interface(s) by overriding each and every pure virtual function. Everything else depends in the implementation of those overridden interface functions. If you have data which need initialization, take care about it.

—SA


我认为我没有正确提出问题.通过类进行接口的实现是众所周知的.协同类可以初始化自身,并且其方法实现可以验证接口输入等.但是,我说的是IDL中用于接口方法的结构数据类型.例如

I think I did not pose the problem correctly. The implementation of interfaces by co-class is well-known. The co-class can initialize itself and its method implementation can validate interface inputs etc. However, I am talking of structure data types in IDL which are used in interface methods. e.g.

Interface I{
typedef struct S{
     data_type1 m1;
     data_type2 m2;
};

HRESULT Method([in] S s, [out]IObject *pObject);
};



在C ++头文件/源文件中,结构S对我不可用.
它不能具有构造函数.因此,当用户创建S的实例并使用接口方法I :: Method时,I :: Method不能确定用户已初始化了S的所有成员是什么,还没有确定是什么?
S实例的统一成员可以具有I :: Method无法理解的垃圾值?程序员的问题是如何提供S的默认初始化?



The structure S is not available with me in C++ header/source files.
It cannot have constructor. Hence, when user creates an instance of S, and uses the interface method I::Method, the I::Method cannot be sure of what all members of S have been initialized by the user and what have not been?
The unitilized members of instance of S can have junk values which I::Method cannot understand? The programmer''s problem is how to provide default initialiation of S?


这篇关于初始化IDL文件中的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆