Thanks.
I've done some research and I think I have found the root cause of this
issue.
There are two approaches to define a property in IDL/ODL, one is to use the
approach in your sample code:
[ uuid(5F9B1CFB-CBD0-4290-A74A-62080CDF50C1),
helpstring("Dispatch interface for HiddenPropTest Control"), hidden ]
dispinterface _DHiddenPropTest
{
properties:
// NOTE - ClassWizard will maintain property information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_PROP(CHiddenPropTestCtrl)
[id(1), hidden] boolean Hidden;
[id(2), nonbrowsable] boolean NonBrowsable;
[id(3)] boolean Normal;
//}}AFX_ODL_PROP
methods:
// NOTE - ClassWizard will maintain method information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(CHiddenPropTestCtrl)
//}}AFX_ODL_METHOD
};
Another one is to use the approach what VB6 is doing using propget/propput:
[id(7), propget] BSTR P1();
[id(8), propput] void P1([in] BSTR rhs);
[id(9), propget, hidden] BSTR P2();
[id(10), propput, hidden] void P2([in] BSTR rhs);
};
Apparently the type library importer of .NET Framework can only deal with
the second approach. Following are the applied attributes to the member
from the generated interop assembly:
[DispId(1),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden)]
public virtual bool Hidden
{
...
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
Browsable(false), DispId(0x68030000)]
public virtual string P2
{
...
Note the second one has an attribute Browsable set to false, which is the
key to make it hidden in property grid.
To workaround this, I think we could use two different aproaches.
1) Change the IDL in MFC project to use propget/propput.
2) If you are distributing the interop assembly (see concept Primary
Interop Assembly, aka. PIA), you can first use ildasm.exe to get the IL
source code of your interop assembly, after modification, use ilasm.exe to
compile the IL source into assembly again.
#Customizing Primary Interop Assemblies
http://msdn2.microsoft.com/en-us/library/7112ksf7.aspx
#How to: Edit Interop Assemblies
http://msdn2.microsoft.com/en-us/library/8zbc969t.aspx
Hope this helps.