How the order of Get/Set property is determined?
(Monday, January 31, 2005)
Found the following interesting discussion in the Newsgroups:
How the order of Get/Set property is determined? by:Anonymous
| The definition of a read/write property in an interface is similar to the following:
Public Interface EiDuty Property Key() As String End Interface
If I would like to generate a TLB out of the interface, how does the tool tlbexp knows what to export first? The get property or the set property goes first??
This is the tlb from the previous code:
[id(0x40030000), propput] HRESULT Key([in] BSTR pRetVal); [id(0x40030000), propget] HRESULT Key([out, retval] BSTR* pRetVal);
In some other cases, I get the opposite:
[id(0x40030000), propget] HRESULT Label([out, retval] BSTR* pRetVal); [id(0x40030000), propput] HRESULT Label([in] BSTR pRetVal);
Is there anything to force the order of get and set? Something similar to C# where in C# I explicitly specify the order like this:
string Key { get; set; }
or if i want to i could write it like this:
string Key { set; get; }
Any advice?
| | | Reply: by:v-phuang@online.microsoft.com (Peter Huang)
| | | Hi,
I wonder why you need to specified the order of the get and set in a property? Do you have any concern about the issue? Best regards,
Peter Huang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
| | | Reply: by:Anonymous
| | | Thanks Peter,
I am trying to generate a TLB from .NET that matches another TLB. The client (that uses Virtual Table to access the functions in the COM) needs the properties and functions to be in the exact order. So, having the get and set functions flipped in the typelib will make the client unhappy and crash.
I can specify the order of get/set in the class implementation and if i generated the interface directly from the class, it will work fine. But I would rather specify an explicit interface definition.
Also I can write two properties with different names as the following:
<DispId(&H68030002)> WriteOnly Property SetLabel() As String <DispId(&H68030002)> ReadOnly Property GetLabel() As String
Notice that I set the DispId to be the same, but since these are differnet properties, the tool tlbexp will generate different DispId(s) and won't use the one I supplied. In this solution, clients that use the Virtual Table will work fine but the clients that use Dispatch ID won't work.
What really bugs me is that the order is not always the same when declaring the read/write property in the interface body.
Any suggestions, advice, comments is highly appreciated..
Thanks,
| | | Reply: by:v-phuang@online.microsoft.com (Peter Huang)
| | | Hi Hani,
Based on my researching, I think we can not do this in VB.NET. I think the problem is more concern about how the vbc compile the vb.net code into il language. As to the tool, it is just export the tlb from the assembly which has already been il language.
As a workaround I think we may try to write C# interface and then implement it in the VB.NET, the suggestion is somewhat strange, if you can accept it I think we just write the whole class library in C#.
If you really, really wants to do this from vb and have the interfaces in the correct order you can manipulate the MSIL code for the compiled assembly that contains the interface and have the MSIL be in the order they want, and then recompile with ilasm.exe and the use tlbexp.exe to create the TLB.
Here are two links about modify the msil language. Editing An Interop Assembly http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm l/cpconeditinginteropassembly.asp
FIX: Tlbimp.exe Generates Interface Wrappers that Cannot Be Used http://support.microsoft.com/?id=318608
Best regards,
Peter Huang Microsoft Online Partner Support
|
Posted by Xander Zelders

|
0 Comments:
Post a Comment
<< Home