473,804 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32) = (
01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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.In terop._ByRefPro ject

The VS.NET IDE completes the code for me but immediately shows an error in
the generated code:

'dotNetProject. SomeClassName' must implement 'Overridable Property
ByVB6DefaultPro perty() As String' for interface
'ByRefProject.I nterop._ByRefPr oject'. 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 1445
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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32) = (
01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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.In terop._ByRefPro ject

The VS.NET IDE completes the code for me but immediately shows an error in
the generated code:

'dotNetProject. SomeClassName' must implement 'Overridable Property
ByVB6DefaultPro perty() As String' for interface
'ByRefProject.I nterop._ByRefPr oject'. 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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32) = (
01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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 ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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 ByVB6DefaultPro perty([out, retval] BSTR* );
[id(0x68030000), propput]
HRESULT ByVB6DefaultPro perty([in, out] BSTR* );
};

Thanks,

Onno

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u#******** ******@TK2MSFTN GP09.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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32) = ( 01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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 ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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%******** ********@TK2MSF TNGP09.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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32) = ( 01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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 Interoperabilit y 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******** *************@n ews.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 ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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 ByVB6DefaultPro perty([out, retval] BSTR* );
[id(0x68030000), propput]
HRESULT ByVB6DefaultPro perty([in, out] BSTR* );
};

Thanks,

Onno

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u#******** ******@TK2MSFTN GP09.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 ByVB6DefaultPro perty() As String
ByRefProperty = mVB6DefaultProp erty
End Property

Public Property Let ByVB6DefaultPro perty(newItemID As String)
mVB6DefaultProp erty = 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_ByVB6Defaul tProperty([in][out] string&
marshal( bstr) A_1) runtime managed internalcall
{
.custom instance void
[mscorlib]System.Runtime. InteropServices .DispIdAttribut e::.ctor(int32)
=
( 01 00 00 00 03 68 00 00 ) // .....h..
} // end of method _ByRefProject:: set_ByVB6Defaul tProperty

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
2978
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 already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
2
1732
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 tooltip object on a form. Once it's done, every object has a new property added to the property box so we can write the tooltip text. Syncfusion object does something like that when we drop a docking
5
1580
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 have used shared properties on some of these objects to enable caching of frequently used objects, so save fetching them from SQL every time. These shared properties vastly increase performance of our windows app.
10
1871
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 dotnet textbox which is MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the property no problem. But looping through the 3rd party control, Properties.MaxLength does not get listed. I was hoping to find how it names it using...
10
1733
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 dotnet textbox which is MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the property no problem. But looping through the 3rd party control, Properties.MaxLength does not get listed. I was hoping to find how it names it using...
0
9577
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.