473,706 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple way to return a COM enumeration interface from .NET?

Is there a simple way to return a COM enumeration interface from .NET? I am
porting a C++ COM Object that has an enumeration interface containing the
DISPID_NEWENUM and DISPID_VALUE properties and the count property and need
to create the equivilant in C#. I'm hoping I can just return an array list
or something but something tells me it isn't that easy. Any thoughts on the
proper way to do this in C#? Thanks.

Jayme
Jan 11 '06 #1
2 5785
Try this.
http://msdn.microsoft.com/library/en...ClassTopic.asp
A more general introduction is available here.
http://msdn.microsoft.com/library/en...sinterface.asp

--
Naraendira Kumar R.R.
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
"Jayme Pechan" <ja**********@w hitefeld.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
Is there a simple way to return a COM enumeration interface from .NET? I
am porting a C++ COM Object that has an enumeration interface containing
the DISPID_NEWENUM and DISPID_VALUE properties and the count property and
need to create the equivilant in C#. I'm hoping I can just return an
array list or something but something tells me it isn't that easy. Any
thoughts on the proper way to do this in C#? Thanks.

Jayme

Jan 12 '06 #2
Not quite sure about the finer details of tying it into the collection
Count/Item/_NewEnum methods, but it is easy to implement the standard
IEnumVARIANT interface (the _NewEnum should return an object which supports
IEnumVARIANT):

Give your class a GetEnumerator method a DispId of -4 (your class doesn't
necessarily need to implement IEnumerable, though it can do), and the
generated typelib will contain a method returning IEnumVARIANT

class ComEnumerable
{
[DispId(-4)]
public IEnumerator GetEnumerator()
{
//...
}
}

Generated TLB contains something like (dependent on ClassInterfaceA ttribute
settings and what interfaces your class implements)

interface _ComEnumerable : IDispatch
{
[id(0xfffffffc)]
HRESULT GetEnumerator([out,retval] IEnumVARIANT** pRetVal);
}

If you have a more strongly typed enumerator, e.g.

class ComEnumerable
{
[DispId(-4)]
public IStronglyTypedE numerator GetEnumerator()
{
//...
}
}

you will get something like

interface _ComEnumerable : IDispatch
{
[id(0xfffffffc)]
HRESULT GetEnumerator([out,retval] IStronglyTypedE numerator** pRetVal);
}

instead.

You could implement both together as follows:

class ComEnumerable : IEnumerable
{
IEnumerator IEnumerable.Get Enumerator()
{
//...
}

[DispId(-4)]
public IStronglyTypedE numerator GetEnumerator()
{
//...
}
}

so that your class can provide the standard COM IEnumVARIANT enumerator via
the IEnumerable interface plus a strongly typed enumerator. If you implement
IEnumerable you can use this with VB 'for each':

Dim enumerable As mscorlib.IEnume rable

Set enumerable = <your object>

For Each <something> In enumerable
I don't know whether regasm generates anything for the VB collection
interface (which defines Count/Item/_NewEnum) in the same way.

"Jayme Pechan" <ja**********@w hitefeld.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
Is there a simple way to return a COM enumeration interface from .NET? I
am porting a C++ COM Object that has an enumeration interface containing
the DISPID_NEWENUM and DISPID_VALUE properties and the count property and
need to create the equivilant in C#. I'm hoping I can just return an
array list or something but something tells me it isn't that easy. Any
thoughts on the proper way to do this in C#? Thanks.

Jayme

Jan 12 '06 #3

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

Similar topics

3
3693
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example program #include <list>
4
2657
by: scorpion | last post by:
I have a simple type like this: <xs:simpleType name="SizeType"> <xs:restriction base="xs:token"> <xs:enumeration value="small"/> <xs:enumeration value="medium"/> <xs:enumeration value="large"/> <xs:enumeration value="xlarge"/> </xs:restriction> </xs:simpleType>
13
5731
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was hoping the clc crowd had some ideas for making it even simpler! In-lined below the full program (132 lines). It's a circular singular linked list of "cells" inspired by the one in Plauger's text
6
3527
by: Jamie Winder via .NET 247 | last post by:
Is it possible to iterate through all of the possible values of an enumeration? (with foreach, maybe?) What I need to do is fill a ComboBox with all possible values for an enumeration. e.g foreach ( in ) { comboBox1.Items.Add (value.ToString ("G"); }
3
13901
by: Sanjay Pais | last post by:
I know that string/char enum is not possible in c# (.NET2.0) I need to create the equivalent of this: public enum HOW_GOOD { AWESOME = "A", GREAT= "G", NOT_TOO_BAD = "N", TERRIBLE="T" }
0
3996
by: Christian Gosselin | last post by:
The problem: We have an interface (EnumInterface), an enumeration container (EnumContainer) and an enumeration type (TheEnum). We can set the EnumContainer through the EnumInterface. However when we retrieve the EnumContainer from the EnumInterface, the TheEnum within the EnumContainer is null (Assert.IsNotNull(enumService.getEnumContainer().anEnum); throws an exception). Any reason why C# can't retrieve the enum value ?
13
27435
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
10
2242
by: Chris Thomasson | last post by:
Here is the example code: - http://appcore.home.comcast.net/vzoom/example/interface.zip which is an analog of the following technique: - http://groups.google.com/group/comp.lang.c/msg/6cf857051ca4029b
0
1858
by: puvit82 | last post by:
My problem is as follows, any advice / suggestion would be greatly appreciated: Lets suppose that I have defined a simpleType "addressType" with 3 enumeration values (Home, Office, Vacation) that restrict data entry. I want to use this simpleType in 2 different unrelated complexType definitions, lets call them "personalAddress" and "companyAddress" How will I be able to use "addressType" inside "personalAddress" such that the 3...
0
8781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9285
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9156
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...
0
8995
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
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3149
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
2
2502
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2095
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.