473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How should DISPID_VALUE properties be put in the tlb for (easy) use by C#

I have the following in the idl for a COM collection:

[propget, id(DISPID_VALUE ), helpstring("pro perty Item")] HRESULT
Item([in] VARIANT* Index, [out, retval] LPDISPATCH* punk);

This allows VBA to access objects in the collection using the syntax
collection("key ") or collection(1).

When I import this type library into C#, the DISPID_VALUE property appears
as 'this[]', and when I try to use the syntax similar to VBA, the compiler
complains that I must use collection.get_ Item() instead of collection().

1. How should I form the idl so that I can use the collection.Item[]
syntax, as I would be able to if I didn't use DISPID_VALUE?

2. If I use the collection.get_ Item() syntax, I must convert the Index
parameter to an 'object ref', and the method returns an object. How should
I change the idl so that the method accepts a 'string' and returns the
correct object type?

Thanks,
Aaron Queenan.
Nov 15 '05 #1
1 3851
I've just changed:

[propget, id(DISPID_VALUE ), helpstring("pro perty Item")]
HRESULT Item([in] VARIANT* Index, [out, retval] LPDISPATCH* punk);

to:

[propget, id(DISPID_VALUE ), helpstring("pro perty Item")]
HRESULT Item([in] VARIANT Index, [out, retval] IChain** ppChain);

Thanks for your suggestion. Changing VARIANT* to VARIANT fixes the
problem - i.e. the [] syntax works correctly. C# doesn't seem to cope with
the [] syntax when passing the index by reference, which could be a problem
with other collections. :-(

Next problem, is that I can now access the objects using collection["key"],
but if I use collection[1] I get a stack overflow. It works fine in VBA.

Thanks,
Aaron Queenan.

"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Aaron,

You should be able to use the square brackets to access the information. However, you will still have to pass it as an object reference.

You could change the IDL so that it takes a variant by value (remove the pointer), but then you would have to change the underlying implementation as well. If you change it so that it takes a string (change Variant to BSTR)
then you will not have the ability to access the items by index.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Aaron Queenan" <aq************ *********@conti ngent.com.au> wrote in message news:Oy******** ******@TK2MSFTN GP12.phx.gbl...
I have the following in the idl for a COM collection:

[propget, id(DISPID_VALUE ), helpstring("pro perty Item")] HRESULT
Item([in] VARIANT* Index, [out, retval] LPDISPATCH* punk);

This allows VBA to access objects in the collection using the syntax
collection("key ") or collection(1).

When I import this type library into C#, the DISPID_VALUE property appears as 'this[]', and when I try to use the syntax similar to VBA, the compiler complains that I must use collection.get_ Item() instead of collection().

1. How should I form the idl so that I can use the collection.Item[]
syntax, as I would be able to if I didn't use DISPID_VALUE?

2. If I use the collection.get_ Item() syntax, I must convert the Index parameter to an 'object ref', and the method returns an object. How

should
I change the idl so that the method accepts a 'string' and returns the
correct object type?

Thanks,
Aaron Queenan.


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1357
by: Jon Slaughter | last post by:
Lets assume I want to write a whole host of classes having "property" elements in them and create a bunch of objects from the different classes. Lets suppose that they are circles, lines, etc... and I display them on the screen for the user. Now I want to have a window that allows the user to modify all the "properties" of the object. It is very similar in how VS.net has a window pane that lets you modify the different default values of...
24
5444
by: downwitch | last post by:
Hi, I know this has been covered here and in the .public groups, but it seems like it's been a while, especially around here, so I just thought I'd ask again to see if anyone has figured out a new angle. If I have a class MyClass--not a collection container but a single-level class--that has a bunch of properties of different types, I'd like to be able to reference them via the standard VBA syntax of
0
1537
by: Peter Verburgh | last post by:
Hello, I'm using PropertyGrid control to show the properties of an control. There are standard properties for each usercontrol like "Cursor, Dock ,...ect" I don't want to show this properties in the Propertygrid control , but i want only show m custom made properties. How can i easy hide those properties ?
15
1373
by: Gary Morris | last post by:
Hello all, OK, first of all I have known about properties since VB6, which I have and have used extensively. It seems that property get and set are basically the same concept in C# and VB.NET, so no problem there. In programming with VB6, I never wrote any program that used properties, and to date I still haven't ever used them in C#. What I really want to know is, when should I use them at all? I mean, we have variables (now referred...
1
1677
by: lester | last post by:
I'm using a C++ dll and need to allow unsafe code because the dll function takes char *. I am using Visual Studio.NET 2002. Everything I've seen says to go to the project properties page, then the build properties page and allow it there. For some reason, my project does not have a build properties page, only a configuration properties page. Can I add a build properties page somehow? Is this because I am not using the command line...
8
1716
by: Chuck Bowling | last post by:
Is there any justification - from an OOP perspective - for wrapping an attribute in a Property beyond the ability to restrict access? private int myInt; public int MyInt { get { return myInt; } set { myInt = value; } }
45
2415
by: Brett | last post by:
If I do this without declaring a corresponding field, is it considered bad design? What are the advantages or disadvantages to either method? Notice there is not set. public string URL { get { return "www.somewhere.com/test.aspx"; }
2
1357
by: Özden Irmak | last post by:
Hello, Is there an easy way to save some/all properties of a windows forms control into a type of file? I came acros with "Serializable" attribute but it seems that I have to inherit evey windows forms control and mark them asa serializable? Does anybody know an easy way for this?
8
1670
by: Joel Reinford | last post by:
I would like to build a class that has properties which can be accessed by string names or index numbers in the form of MyClass.Item("LastName"). The string names or item index values would be populated by a data-driven loop. I need a few pointers to get me started in the right direction. I'm pretty sure that I need a default Item property but I'm not sure how to create that or index the other properties. A short code example is below ...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.