[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

msnews.microsoft.com

8/16/2007 6:23:00 PM

Hello!

I've read on MSDN [1] that it is necessary to mark methods and properties
with DispId in order to expose them to COM. But that doesn't seem
necessary. I've created interfaces and subclasses in C# and I have no
problem using them from C++. So what is DispId really used for?

[1] Example COM Class (C#):
http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx

--
Daniel
6 Answers

Nicholas Paldino [.NET/C# MVP]

8/16/2007 6:44:00 PM

0

Daniel,

DispId is used in the event that you want to assign the dispatch id
(used with dispatch interfaces, basically late binding). If you don't
assign it, then it will be auto assigned for you. It's a good idea to use
them, as it gives you better control over how your class is exposed to COM.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Daniel Lidström" <someone@microsoft.com> wrote in message
news:3ofjy13vf6jc.xid7i2ndrsfa$.dlg@40tude.net...
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class (C#):
> http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel


Ignacio Machin \( .NET/ C# MVP \)

8/16/2007 8:17:00 PM

0

Hi,

IT's not necesary


"Daniel Lidström" <someone@microsoft.com> wrote in message
news:3ofjy13vf6jc.xid7i2ndrsfa$.dlg@40tude.net...
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class (C#):
> http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel


Alvin Bruney [MVP]

8/16/2007 11:58:00 PM

0

maybe a google on dispid would help? http://en.wikipedia.org/wiki...
3rd paragraph.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET - MS Press
Professional VSTO 2005 - Wrox/Wiley
OWC Black Book www.lulu.com/owc

"Daniel Lidström" <someone@microsoft.com> wrote in message
news:3ofjy13vf6jc.xid7i2ndrsfa$.dlg@40tude.net...
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class (C#):
> http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel


Micky Duncan

8/17/2007 4:16:00 AM

0

You don't, C# will do that for you automatically creating prodids {1...n}.
However there may be times when a property or method must match a well-known
progid in the COM world so in this case you would need to specifiy it. You
may not encounter this scenario. Some examples are ActiveX controls well
known properties or Ole Collections.

The only time I have found where I needed to was on a COM event source
interface written in c#.

--
Cheers,
Micky D
"Daniel Lidström" <someone@microsoft.com> wrote in message
news:3ofjy13vf6jc.xid7i2ndrsfa$.dlg@40tude.net...
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class (C#):
> http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel

DeveloperX

8/17/2007 9:17:00 AM

0

On 16 Aug, 19:22, Daniel Lidstr?m <some...@microsoft.com> wrote:
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class (C#):http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel

the dispid is used with IDispatch which allows COM to late bind. COM
also has the IUnknown interface which is used for early binding.
(disclaimer, I think :))

Micky Duncan

9/6/2007 12:25:00 AM

0

IUnknown has nothing to do with early binding. Both early and late binding
involve IDispatch and are used by automation clients. Early binding is used
by say VB which has access to a type library at compile time. VB with early
binding knows about strong types and can create objects such as

dim widget as new MickysMyLib.Widget

VB inspects the type library and determines the progids/dispids and invokes
methods by progid which is faster than late binding. Automation clients
will cache the progids so that they do not need to perform a lookup again.
Some clients are quite powerful and will actually invoke methods by using
the vtable on dual interfaces in the same way as c++ apps will - this is
extremely fast.

Late binding is used by say VB Script which cannot use type libraries to
create rich types. it creates objects with calls like

set widget = CreateObject ("Micky.MyLib.Widget")

calling any methods are very slow compared to early binding since lookups
are required.

IUnknown is NOT accessible from your VB or VB Script code.

--
Cheers,
Micky D
"DeveloperX" <nntpDev@operamail.com> wrote in message
news:1187342193.591180.242500@50g2000hsm.googlegroups.com...
On 16 Aug, 19:22, Daniel Lidström <some...@microsoft.com> wrote:
> Hello!
>
> I've read on MSDN [1] that it is necessary to mark methods and properties
> with DispId in order to expose them to COM. But that doesn't seem
> necessary. I've created interfaces and subclasses in C# and I have no
> problem using them from C++. So what is DispId really used for?
>
> [1] Example COM Class
> (C#):http://msdn2.microsoft.com/en-us/librar...(VS.80).aspx
>
> --
> Daniel

the dispid is used with IDispatch which allows COM to late bind. COM
also has the IUnknown interface which is used for early binding.
(disclaimer, I think :))