O
Onno Ceelen
Hi,
I am testing interop code by use of some prototypes. What I have is the
following:
1. VB 6.0 library
2. VB.NET class library
3. Interop assembly of the VB 6.0 library (tlbimp output)
I want my VB.NET class library to have the exact same definition as my VB
6.0 library.
The code of VB 6.0 looks like the following (where, by default, newItemID is
passed in by reference):
Public Property Get ByVB6DefaultProperty() As String
ByRefProperty = mVB6DefaultProperty
End Property
Public Property Let ByVB6DefaultProperty(newItemID As String)
mVB6DefaultProperty = newItemID
End Property
When I generate an interop assembly by using tlbimp on the VB 6.0 dll, I get
the following IDL (ildasm view) for the set/let part of this property:
..method public hidebysig newslot specialname abstract virtual
instance void set_ByVB6DefaultProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = (
01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject::set_ByVB6DefaultProperty
Note that the parameter is still passed in by reference.
I tried to create a VB.NET assembly that has about the same IDL so it would
be able to replace my VB 6.0 library. Unfortunately for this situation, in
VB.NET you can't pass values by reference to the property: 'Set' parameter
cannot be declared 'ByRef'.
Is this a limitation which I should keep in mind and which forces me to take
another approach? I just moved from C# to VB.NET for this particular
assembly because I have to use optional parameters in methods (opposed to
overloaded methods).
If I reference my interop assembly namespace from my VB.NET project like:
Public Class SomeClassName
Implements ByRefProject.Interop._ByRefProject
The VS.NET IDE completes the code for me but immediately shows an error in
the generated code:
'dotNetProject.SomeClassName' must implement 'Overridable Property
ByVB6DefaultProperty() As String' for interface
'ByRefProject.Interop._ByRefProject'. Implementing property must have
matching 'ReadOnly'/'WriteOnly' specifiers.
Any idea why this is? Is it a limitation of the VB.Net languages or
something else?
Regards,
Onno Ceelen
I am testing interop code by use of some prototypes. What I have is the
following:
1. VB 6.0 library
2. VB.NET class library
3. Interop assembly of the VB 6.0 library (tlbimp output)
I want my VB.NET class library to have the exact same definition as my VB
6.0 library.
The code of VB 6.0 looks like the following (where, by default, newItemID is
passed in by reference):
Public Property Get ByVB6DefaultProperty() As String
ByRefProperty = mVB6DefaultProperty
End Property
Public Property Let ByVB6DefaultProperty(newItemID As String)
mVB6DefaultProperty = newItemID
End Property
When I generate an interop assembly by using tlbimp on the VB 6.0 dll, I get
the following IDL (ildasm view) for the set/let part of this property:
..method public hidebysig newslot specialname abstract virtual
instance void set_ByVB6DefaultProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = (
01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject::set_ByVB6DefaultProperty
Note that the parameter is still passed in by reference.
I tried to create a VB.NET assembly that has about the same IDL so it would
be able to replace my VB 6.0 library. Unfortunately for this situation, in
VB.NET you can't pass values by reference to the property: 'Set' parameter
cannot be declared 'ByRef'.
Is this a limitation which I should keep in mind and which forces me to take
another approach? I just moved from C# to VB.NET for this particular
assembly because I have to use optional parameters in methods (opposed to
overloaded methods).
If I reference my interop assembly namespace from my VB.NET project like:
Public Class SomeClassName
Implements ByRefProject.Interop._ByRefProject
The VS.NET IDE completes the code for me but immediately shows an error in
the generated code:
'dotNetProject.SomeClassName' must implement 'Overridable Property
ByVB6DefaultProperty() As String' for interface
'ByRefProject.Interop._ByRefProject'. Implementing property must have
matching 'ReadOnly'/'WriteOnly' specifiers.
Any idea why this is? Is it a limitation of the VB.Net languages or
something else?
Regards,
Onno Ceelen