473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Properties only ByVal

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::.c tor(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
Nov 20 '05 #1
5 1429
Cor
Hi Onno,

No it is not possible to make dotnet Library for VB6.
While you also cannot make that with which other managed code language.

Cor


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::.c tor(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?

Nov 20 '05 #2
* "Onno Ceelen" <on*****@excite.com> scripsit:
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::.c tor(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'.


Are you sure you want a 'ByRef' behavior? I don't understand why that
makes sense for 'Property Set'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
It doesn't make sense to me too :-)

The problem is that I don't want to touch my existing code. My existing code
uses (references) the VB 6.0 library mentioned in the example of my previous
e-mail. To be able to actually replace my VB 6.0 library with a .NET interop
assembly that has the same interface definition and implementation (but in
C# or VB.NET and using InteropServices attributes etc.) I have to adhere to
the the previous interface created in VB 6.0.

But, if in VB 6.0 you had a property defined as:

Public Property Let ByVB6DefaultProperty(newItemID As String)
mVB6DefaultProperty = newItemID
End Property

the newItemID is passed in ByRef (just because the one who coded this didn't
specify ByVal).

I can't do that in VB.NET.

My question is, am I right about this, that you could pass property values
ByRef in VB 6.0 but can't do that anymore in VB.NET? Does C# allow this?

All I want is to produce the following IDL for my interface with either
VB.NET or C# (interop):

interface _ByRefProject : IDispatch {
[id(0x68030002), propget]
HRESULT ByValProperty([out, retval] BSTR* );
[id(0x68030002), propput]
HRESULT ByValProperty([in] BSTR );
[id(0x68030001), propget]
HRESULT ByRefProperty([out, retval] BSTR* );
[id(0x68030001), propput]
HRESULT ByRefProperty([in, out] BSTR* );
[id(0x68030000), propget]
HRESULT ByVB6DefaultProperty([out, retval] BSTR* );
[id(0x68030000), propput]
HRESULT ByVB6DefaultProperty([in, out] BSTR* );
};

Thanks,

Onno

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u#**************@TK2MSFTNGP09.phx.gbl...
* "Onno Ceelen" <on*****@excite.com> scripsit:
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::.c tor(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'.


Are you sure you want a 'ByRef' behavior? I don't understand why that
makes sense for 'Property Set'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
Herfried & Onno,
Public Property Let ByVB6DefaultProperty(newItemID As String)
mVB6DefaultProperty = newItemID
End Property Are you sure you want a 'ByRef' behavior? I don't understand why that
makes sense for 'Property Set'.

I'm strongly suspect he does not want "ByRef"! If he does he needs to read
about side-effects in methods! And why they should be avoided.

Remember ByRef is the default if you do not specify ByRef or ByVal in VB6.
Looking at his code, he did not specify, so it defaults to ByRef!

I would recommend to Onno, if he has the VB6 library to run the Visual Basic
6.0 Code Advisor, on his VB6 project, make the corrections then recompile it
as a VB6 library:

http://msdn.microsoft.com/vbasic/dow...r/default.aspx

Of course this means he will need to recompile any VB6 projects that
reference it, alternatively Onno could create a VB6 shim project (wrapper)
that corrects the parameters that is used by VB.NET, while keeping the
original VB6 library intact. The wrapper may be the easier route, especially
if the VB6 project does not change. Of course the wrapper means you are
going through 2 extra layers (the wrapper and the interop).

Hope this helps
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl... * "Onno Ceelen" <on*****@excite.com> scripsit:
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::.c tor(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'.


Are you sure you want a 'ByRef' behavior? I don't understand why that
makes sense for 'Property Set'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5
Onno,
I have to adhere to
the the previous interface created in VB 6.0. See my other post, I would recommend the wrapper if you are NOT allowed to
fix the VB6 class library.
My question is, am I right about this, that you could pass property values
ByRef in VB 6.0 but can't do that anymore in VB.NET? Does C# allow this? You are correct VB6 allowed it, while .NET does not. You could try C# to see
it its allowed, however I don't think so as C# requires you to use "ref"
keyword when passing ByRef parameters...

I don't remember specifically, Adam Nathan's book ".NET and COM - The
Complete Interoperability Guide" from MS Press. May have an example of how
to get what you got to work. I know he discusses how to create & "improve"
the interop assemblies.

Hope this helps
Jay
Hope this helps
Jay

"Onno Ceelen" <on*****@excite.com> wrote in message
news:40*********************@news.xs4all.nl... It doesn't make sense to me too :-)

The problem is that I don't want to touch my existing code. My existing code uses (references) the VB 6.0 library mentioned in the example of my previous e-mail. To be able to actually replace my VB 6.0 library with a .NET interop assembly that has the same interface definition and implementation (but in
C# or VB.NET and using InteropServices attributes etc.) I have to adhere to the the previous interface created in VB 6.0.

But, if in VB 6.0 you had a property defined as:

Public Property Let ByVB6DefaultProperty(newItemID As String)
mVB6DefaultProperty = newItemID
End Property

the newItemID is passed in ByRef (just because the one who coded this didn't specify ByVal).

I can't do that in VB.NET.

My question is, am I right about this, that you could pass property values
ByRef in VB 6.0 but can't do that anymore in VB.NET? Does C# allow this?

All I want is to produce the following IDL for my interface with either
VB.NET or C# (interop):

interface _ByRefProject : IDispatch {
[id(0x68030002), propget]
HRESULT ByValProperty([out, retval] BSTR* );
[id(0x68030002), propput]
HRESULT ByValProperty([in] BSTR );
[id(0x68030001), propget]
HRESULT ByRefProperty([out, retval] BSTR* );
[id(0x68030001), propput]
HRESULT ByRefProperty([in, out] BSTR* );
[id(0x68030000), propget]
HRESULT ByVB6DefaultProperty([out, retval] BSTR* );
[id(0x68030000), propput]
HRESULT ByVB6DefaultProperty([in, out] BSTR* );
};

Thanks,

Onno

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u#**************@TK2MSFTNGP09.phx.gbl...
* "Onno Ceelen" <on*****@excite.com> scripsit:
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::.c tor(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'.


Are you sure you want a 'ByRef' behavior? I don't understand why that
makes sense for 'Property Set'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
2
by: Miky | last post by:
Hi, I'm looking resources or tutorial where I can learn how to add properties to other objects at design time for VB.NEt or C#. I want to reproduce the same effect as when your drop the...
5
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We...
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.