How to pass string arrays using C# COM properties equivalent to VB6 COM properties?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt I want to know if it is possible to create a C# COM object which exposes a public property for a single dimensional string array which results in the
identical type library entry created by a VB6 ActiveX DLL.
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt For example the VB6 class would look like:
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt Private v() As String
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt Public Property Get TestStringArray() As String()<br/>
TestStringArray = v<br/>
End Property
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt Public Property Let TestStringArray(newval() As String)<br/>
v = newval<br/>
End Property
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:"Verdana","sans-serif"; color:black; font-size:8pt After compiling this VB6 class to an ActiveX DLL, the following type library signature is created:
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:7.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt [
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(A8CD37FE-AB27-4621-A012-4D9B99AD8786),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(2.0)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt ]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt library COMStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
// TLib :<span style=" // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
importlib("stdole2.tlb");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
// Forward declare all types defined in this typelib
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface _StringArray;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
odl,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(72059770-0713-4B04-8FE5-736DD5F653C0),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(1.0),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
hidden,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
dual,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
nonextensible,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
oleautomation
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface _StringArray : IDispatch {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x68030000), propget]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT <strong style=" TestStringArray([out, retval] SAFEARRAY(BSTR)* );
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x68030000), propput]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT <strong style=" TestStringArray([in, out] SAFEARRAY(BSTR)* );
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
};
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(472BE203-977D-47EE-BF2A-E9C2D76D4D65),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(1.0)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
coclass StringArray {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[default] interface _StringArray;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
};
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt };
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri The simplest C# COM class (VS2010) given below is:
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt using<span style="font-family:Consolas; font-size:9.5pt System;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt using<span style="font-family:Consolas; font-size:9.5pt System.Text;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt using<span style="font-family:Consolas; font-size:9.5pt System.Runtime.InteropServices;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt namespace<span style="font-family:Consolas; font-size:9.5pt COMStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:#2b91af Guid(<span style="color:#2b91af StringArray.InterfaceId),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af ComVisible(<span style="color:blue true),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af InterfaceType(<span style="color:#2b91af ComInterfaceType.InterfaceIsDual)]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue public <span style="color:blue interface
<span style="color:#2b91af IStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:#2b91af DispId(1)]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue string[] TestStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue get;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue set;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:#2b91af Guid(ClassId),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af ClassInterface(<span style="color:#2b91af ClassInterfaceType.None),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af ComDefaultInterface(<span style="color:blue typeof(<span style="color:#2b91af IStringArray))]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue public <span style="color:blue class
<span style="color:#2b91af StringArray : <span style="color:#2b91af IStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue internal <span style="color:blue const
<span style="color:blue string ClassId = <span style="color:#a31515 "A109B466-AF4F-487E-A9D3-5B003701EE66";
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue internal <span style="color:blue const
<span style="color:blue string InterfaceId = <span style="color:#a31515
"6A2CACBB-3FE2-4C7F-B5BA-52FF1FF37C6E";
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue internal <span style="color:blue const
<span style="color:blue string EventsId = <span style="color:#a31515 "6D0CA031-9304-4F2B-923B-DED8D7FFB517";
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue public <span style="color:blue string[] TestStringArray {
<span style="color:blue get; <span style="color:blue set; }
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt }
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri After compiling this code, the generated type library is given below with the property signatures given in bold:

<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt [
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(0FD36F36-935F-4EB7-9182-31D5BB5F8076),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(1.0)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt ]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt library COMStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
// TLib :<span style=" // TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
importlib("mscorlib.tlb");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
importlib("stdole2.tlb");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
// Forward declare all types defined in this typelib
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface IStringArray;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
odl,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(6A2CACBB-3FE2-4C7F-B5BA-52FF1FF37C6E),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(1.0),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
dual,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
<span style=" oleautomation,
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "COMStringArray.IStringArray")<span style="

<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface IStringArray : IDispatch {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x00000001), propget]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT <strong style=" TestStringArray([out, retval] SAFEARRAY(BSTR)* pRetVal);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x00000001), propput]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT <strong style=" TestStringArray([in] SAFEARRAY(BSTR) pRetVal);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
};
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
uuid(A109B466-AF4F-487E-A9D3-5B003701EE66),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
version(1.0),
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "COMStringArray.StringArray")
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
coclass StringArray {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface _Object;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[default] interface IStringArray;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
};
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt };
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <strong style=" The âgetâ accessor signature for the
<em style=" TestStringArray[/i]<strong style=" property is identical :
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt TestStringArray([out, retval] SAFEARRAY(BSTR)* pRetVal);
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri However, the âsetâ accessors
<span style=" are different:
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <strong style=" VB6: <span style="
<span style="line-height:115%; font-family:Courier; font-size:9pt TestStringArray([in, out] SAFEARRAY(BSTR)* );
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <strong style=" C#:
<span style=" <span style="line-height:115%; font-family:Courier; font-size:9pt TestStringArray([in] SAFEARRAY(BSTR) );
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <strong style=" <span style="font-family:Calibri; font-size:small By modifying the C# interface slightly by adding the â <span style="font-family:Consolas; font-size:9.5pt [<span style="color:blue param:
<span style="color:#2b91af In, <span style="color:#2b91af Out]<span style="font-size:small <span style="font-family:Calibri <strong style=" â to the set accessor <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue public <span style="color:blue interface
<span style="color:#2b91af IStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:#2b91af DispId(1)]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue string[] TestStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue get;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<strong style=" [<span style="color:blue param: <span style="color:#2b91af
In, <span style="color:#2b91af Out] <span style="color:blue set;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri I can get the C# a little closer (but still not identical) to the VB6 âsetâ accessor signature.

<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <strong style=" VB6: <span style="
<span style="line-height:115%; font-family:Courier; font-size:9pt TestStringArray([in, out] SAFEARRAY(BSTR)* );
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <strong style=" C#:
<span style=" <span style="line-height:115%; font-family:Courier; font-size:9pt TestStringArray([in, out] SAFEARRAY(BSTR) );
<p style="margin:0in 0in 0pt <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <strong style=" <span style="text-decoration:underline <span style="line-height:115%; font-size:14pt <span style="font-family:Calibri The question is there any way to get the C# property to treat the set assessor as a ârefâ
parameter?
<p style="margin:0in 0in 0pt <strong style=" <span style="text-decoration:underline <span style="line-height:115%; font-size:14pt <span style="text-decoration:none <span style="font-family:Calibri
<p style="margin:0in 0in 0pt <strong style=" <span style="text-decoration:underline <span style="line-height:115%; font-size:14pt <span style="text-decoration:none <span style="font-family:Calibri
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri I have found that I can get the matching signature if I manually create a âsetâ assessor
<span style="text-decoration:underline method accepting a ref parameter, as follows:
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:Calibri; font-size:small
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue public <span style="color:blue interface
<span style="color:#2b91af IStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:#2b91af DispId(1)]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue string[] TestStringArray
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue get;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
[<span style="color:blue param: <span style="color:#2b91af In,
<span style="color:#2b91af Out] <span style="color:blue set;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="

<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<strong style=" <span style="color:blue void set_TestStringArray(<span style="color:blue ref
<span style="color:blue string[] value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri Results in the following C# COM type library signatures:
<p style="margin:0in 0in 0pt <strong style=" <span style="font-family:Calibri; font-size:small
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
interface IStringArray : IDispatch {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x00000001), propget]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT TestStringArray([out, retval] SAFEARRAY(BSTR)* pRetVal);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x00000001), propput]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
HRESULT TestStringArray([in, out] SAFEARRAY(BSTR) pRetVal);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
[id(0x60020002)]
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
<strong style=" HRESULT set_TestStringArray([in, out] SAFEARRAY(BSTR)* value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:Courier; font-size:9pt <span style="
};
<p style="margin:0in 0in 0pt <strong style=" <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <strong style=" <span style="line-height:115%; font-family:Courier; font-size:9pt
<p style="margin:0in 0in 0pt <strong style=" <span style="font-size:small <span style="font-family:Calibri Does anyone have an idea how to get the C# property set accessor to add the level of indirection created by the VB6 COM object, or is this one of
those areas C# just cannot match?


View the full article
 
Back
Top