Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Win32 VC10.0
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?
Posted 15-Mar-11 4:36am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
Henry Minute at 15-Mar-11 12:35pm
   
Good answer, SA.
SAKryukov at 15-Mar-11 12:37pm
   
Thank you, Henry.
Hope it resolves the confusion.
--SA
Dalek Dave at 16-Mar-11 4:45am
   
Good Call.
SAKryukov at 16-Mar-11 4:59am
   
Thank you.
Hope it... oh, I already said that :-)
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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);
};
 
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?
  Permalink  
v2
Comments
Dalek Dave at 16-Mar-11 4:46am
   
I edited for the code block, but a good answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100