c# property exposed as COM bindable property

M

Miguel.Herrera

I like to create an assembly with a property exposed in COM as
bindable. I have tried to use [Bindable(true)] attribute but when I
check the typelib produced by regasm for my assembly the property does
not have bindable on it.

Here is some code of what I mean:

[Bindable(true)]
public bool ActiveXDone
{
get
{
return _activeXDone;
}
set
{
_activeXDone = value;
}
}

when I use regasm to generate a typelib for my assembly I like to get
the following (note the bindable attribute):

[id(0x60020000), propget, bindable]
HRESULT ActiveXDone([out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020000), propput, bindable]
HRESULT ActiveXDone([in] VARIANT_BOOL pRetVal);

but instead I get the following :

[id(0x60020000), propget]
HRESULT ActiveXDone([out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020000), propput]
HRESULT ActiveXDone([in] VARIANT_BOOL pRetVal);


What am I doing wrong ?
 
D

Dmytro Lapshyn [MVP]

Hi Miguel!

The [Bindable] attribute is for managed design-time environment, as far as I
know it has no effect on COM-visible type libraries.
I have looked through all System.Runtime.InteropServices attributes and it
seems there is no suitable attribute at all :-(.

Re-posting your question in microsoft.public.dotnet.framework.interop might
give better results.
 
N

Nicholas Paldino [.NET/C# MVP]

Miguel,

You might have to reverse engineer some of the generated code to do
this. Offhand, I would create the TLB file, and then use OLEVIEW to view
the IDL.

Then, I would copy and paste the IDL into a new file, and add the
bindable attribute to the idl in the appropriate places. Once that is done,
I would run that IDL file through MIDL, and create a type library. Once you
do that, you should be able to register that type library to create your
CCW's.

Hope this helps.
 
D

Dmytro Lapshyn [MVP]

Nicholas,

I must say "live and learn" - I did not know before that one could create a
CCW from an already existing type library. Is there an example? What I
personally would try is creating a type library containing interfaces only,
then I'd run tlbimp.exe on it and create my [ComVisible] classes that
implement interfaces imported from the type library.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Nicholas Paldino said:
Miguel,

You might have to reverse engineer some of the generated code to do
this. Offhand, I would create the TLB file, and then use OLEVIEW to view
the IDL.

Then, I would copy and paste the IDL into a new file, and add the
bindable attribute to the idl in the appropriate places. Once that is
done, I would run that IDL file through MIDL, and create a type library.
Once you do that, you should be able to register that type library to
create your CCW's.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I like to create an assembly with a property exposed in COM as
bindable. I have tried to use [Bindable(true)] attribute but when I
check the typelib produced by regasm for my assembly the property does
not have bindable on it.

Here is some code of what I mean:

[Bindable(true)]
public bool ActiveXDone
{
get
{
return _activeXDone;
}
set
{
_activeXDone = value;
}
}

when I use regasm to generate a typelib for my assembly I like to get
the following (note the bindable attribute):

[id(0x60020000), propget, bindable]
HRESULT ActiveXDone([out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020000), propput, bindable]
HRESULT ActiveXDone([in] VARIANT_BOOL pRetVal);

but instead I get the following :

[id(0x60020000), propget]
HRESULT ActiveXDone([out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020000), propput]
HRESULT ActiveXDone([in] VARIANT_BOOL pRetVal);


What am I doing wrong ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top